From: Tim McCune Date: Fri, 26 Aug 2005 04:23:41 +0000 (+0000) Subject: Fixed bug 1273712 where writing null values into fixed-length columns wasn't working. X-Git-Tag: rel_1_1_2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f109d76b194339b76e328008ad0aea23a4f4128b;p=jackcess.git Fixed bug 1273712 where writing null values into fixed-length columns wasn't working. git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@25 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/project.properties b/project.properties index ef6d4ae..78264d3 100644 --- a/project.properties +++ b/project.properties @@ -18,5 +18,5 @@ maven.sourceforge.project.groupId=134943 maven.sourceforge.username=javajedi maven.test.source=1.5 maven.username=javajedi -log4j.configuration=com/hmsonline/common/access/log4j.properties +log4j.configuration=com/healthmarketscience/jackcess/log4j.properties statcvs.include=**/*.java;**/*.xml diff --git a/project.xml b/project.xml index 6164612..4e11477 100644 --- a/project.xml +++ b/project.xml @@ -3,7 +3,7 @@ 1 jackcess Jackcess - 1.1.1 + 1.1.2 Health Market Science, Inc. http://www.healthmarketscience.com diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java index 54602cc..234544c 100644 --- a/src/java/com/healthmarketscience/jackcess/Column.java +++ b/src/java/com/healthmarketscience/jackcess/Column.java @@ -410,22 +410,26 @@ public class Column implements Comparable { if (_type == DataType.BOOLEAN) { //Do nothing } else if (_type == DataType.BYTE) { - buffer.put(((Number) obj).byteValue()); + buffer.put(obj != null ? ((Number) obj).byteValue() : (byte) 0); } else if (_type == DataType.INT) { - buffer.putShort(((Number) obj).shortValue()); + buffer.putShort(obj != null ? ((Number) obj).shortValue() : (short) 0); } else if (_type == DataType.LONG) { - buffer.putInt(((Number) obj).intValue()); + buffer.putInt(obj != null ? ((Number) obj).intValue() : 0); } else if (_type == DataType.DOUBLE) { - buffer.putDouble(((Number) obj).doubleValue()); + buffer.putDouble(obj != null ? ((Number) obj).doubleValue() : (double) 0); } else if (_type == DataType.FLOAT) { - buffer.putFloat(((Number) obj).floatValue()); + buffer.putFloat(obj != null ? ((Number) obj).floatValue() : (float) 0); } else if (_type == DataType.SHORT_DATE_TIME) { - Calendar cal = Calendar.getInstance(); - cal.setTime((Date) obj); - long ms = cal.getTimeInMillis(); - ms += (long) TimeZone.getDefault().getOffset(ms); - buffer.putDouble((double) ms / MILLISECONDS_PER_DAY + - DAYS_BETWEEN_EPOCH_AND_1900); + if (obj instanceof Date) { + Calendar cal = Calendar.getInstance(); + cal.setTime((Date) obj); + long ms = cal.getTimeInMillis(); + ms += (long) TimeZone.getDefault().getOffset(ms); + buffer.putDouble((double) ms / MILLISECONDS_PER_DAY + + DAYS_BETWEEN_EPOCH_AND_1900); + } else { + buffer.putDouble(0d); + } } else if (_type == DataType.BINARY) { buffer.put((byte[]) obj); } else if (_type == DataType.TEXT) { diff --git a/src/java/com/healthmarketscience/jackcess/Table.java b/src/java/com/healthmarketscience/jackcess/Table.java index 9ac791b..96b51ca 100644 --- a/src/java/com/healthmarketscience/jackcess/Table.java +++ b/src/java/com/healthmarketscience/jackcess/Table.java @@ -194,23 +194,25 @@ public class Table { //Now read in the fixed length columns and populate the columnData array //with the combination of fixed length and variable length data. - byte[] columnData; + byte[] columnData = null; for (Iterator iter = _columns.iterator(); iter.hasNext(); columnNumber++) { Column column = (Column) iter.next(); boolean isNull = nullMask.isNull(columnNumber); Object value = null; if (column.getType() == DataType.BOOLEAN) { value = new Boolean(!isNull); //Boolean values are stored in the null mask - } else if (!isNull) { + } else { if (!column.isVariableLength()) { //Read in fixed length column data columnData = new byte[column.size()]; _buffer.get(columnData); - } else { + } else if (!isNull) { //Refer to already-read-in variable length data columnData = varColumnData[varColumnDataIndex--]; } - if (columnNames == null || columnNames.contains(column.getName())) { + if (!isNull && columnData != null && + (columnNames == null || columnNames.contains(column.getName()))) + { //Add the value if we are interested in it. value = column.read(columnData); } @@ -452,9 +454,7 @@ public class Table { col = (Column) iter.next(); if (!col.isVariableLength()) { //Fixed length column data comes first - if (row.get(index) != null) { - buffer.put(col.write(row.get(index))); - } + buffer.put(col.write(row.get(index))); } if (col.getType() == DataType.BOOLEAN) { if (row.get(index) != null) { diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java index c4dac93..94ee826 100644 --- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -26,7 +26,7 @@ public class DatabaseTest extends TestCase { private Database create() throws Exception { File tmp = File.createTempFile("databaseTest", ".mdb"); - //tmp.deleteOnExit(); + tmp.deleteOnExit(); return Database.create(tmp); } @@ -107,7 +107,7 @@ public class DatabaseTest extends TestCase { row[0] = "Tim"; row[1] = "R"; row[2] = "McCune"; - row[3] = new Integer(1234); + row[3] = null; row[4] = new Byte((byte) 0xad); row[5] = new Double(555.66d); row[6] = new Float(777.88d);