From f17433f2de69b70a89064eb88b543d5e51c61460 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Mon, 29 Sep 2014 22:10:43 +0000 Subject: [PATCH] fix regression where empty memo values are returned as null (issue 110) git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@884 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/changes/changes.xml | 3 +++ .../jackcess/impl/LongValueColumnImpl.java | 5 ++++- .../jackcess/DatabaseTest.java | 19 +++++++++++++++++- .../jackcess/impl/CalcFieldTest.java | 20 ++++++++++++++++++- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index affaa5c..80de3bc 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,9 @@ IndexCursor can early exit when searching based on indexed values. + + Fix regression where empty memo values are returned as null. + diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/LongValueColumnImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/LongValueColumnImpl.java index b648a6a..89accff 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/LongValueColumnImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/LongValueColumnImpl.java @@ -234,9 +234,12 @@ class LongValueColumnImpl extends ColumnImpl throws IOException { byte[] binData = readLongValue(lvalDefinition); - if((binData == null) || (binData.length == 0)) { + if(binData == null) { return null; } + if(binData.length == 0) { + return ""; + } return decodeTextValue(binData); } diff --git a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java index a9178fe..a25c6e8 100644 --- a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -565,6 +565,8 @@ public class DatabaseTest extends TestCase table.addRow(testStr, testStr, null); table.addRow(testStr, longMemo, oleValue); + table.addRow("", "", new byte[0]); + table.addRow(null, null, null); table.reset(); @@ -580,6 +582,18 @@ public class DatabaseTest extends TestCase assertEquals(longMemo, row.get("B")); assertTrue(Arrays.equals(oleValue, row.getBytes("C"))); + row = table.getNextRow(); + + assertEquals("", row.get("A")); + assertEquals("", row.get("B")); + assertTrue(Arrays.equals(new byte[0], row.getBytes("C"))); + + row = table.getNextRow(); + + assertNull(row.get("A")); + assertNull(row.get("B")); + assertNull(row.getBytes("C")); + db.close(); } } @@ -1565,7 +1579,10 @@ public class DatabaseTest extends TestCase for(Map row : cursor) { foundTable.add(row); } - assertEquals(expectedTable, foundTable); + assertEquals(expectedTable.size(), foundTable.size()); + for(int i = 0; i < expectedTable.size(); ++i) { + assertEquals(expectedTable.get(i), foundTable.get(i)); + } } public static RowImpl createExpectedRow(Object... rowElements) { diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/CalcFieldTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/CalcFieldTest.java index 26b2390..bbcd08c 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/CalcFieldTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/CalcFieldTest.java @@ -102,6 +102,8 @@ public class CalcFieldTest extends TestCase t.addRow(Column.AUTO_NUMBER, "foo", "1_foo", longStr, true, 2, bd1); t.addRow(Column.AUTO_NUMBER, "bar", "2_bar", longStr, false, -37, bd2); + t.addRow(Column.AUTO_NUMBER, "", "", "", false, 0, BigDecimal.ZERO); + t.addRow(Column.AUTO_NUMBER, null, null, null, null, null, null); List> expectedRows = createExpectedTable( @@ -120,7 +122,23 @@ public class CalcFieldTest extends TestCase "calc_memo", longStr, "calc_bool", false, "calc_long", -37, - "calc_numeric", bd2)); + "calc_numeric", bd2), + createExpectedRow( + "id", 3, + "data", "", + "calc_text", "", + "calc_memo", "", + "calc_bool", false, + "calc_long", 0, + "calc_numeric", BigDecimal.ZERO), + createExpectedRow( + "id", 4, + "data", null, + "calc_text", null, + "calc_memo", null, + "calc_bool", null, + "calc_long", null, + "calc_numeric", null)); assertTable(expectedRows, t); -- 2.39.5