diff options
author | Tim McCune <javajedi@users.sf.net> | 2005-08-26 04:23:41 +0000 |
---|---|---|
committer | Tim McCune <javajedi@users.sf.net> | 2005-08-26 04:23:41 +0000 |
commit | f109d76b194339b76e328008ad0aea23a4f4128b (patch) | |
tree | c1da9594a9474d074bae4426d3ef68c1144fc872 | |
parent | 2300c101bb4dadee060d0c4a5b9f973d4519b454 (diff) | |
download | jackcess-f109d76b194339b76e328008ad0aea23a4f4128b.tar.gz jackcess-f109d76b194339b76e328008ad0aea23a4f4128b.zip |
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
-rw-r--r-- | project.properties | 2 | ||||
-rw-r--r-- | project.xml | 2 | ||||
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/Column.java | 26 | ||||
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/Table.java | 14 | ||||
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java | 4 |
5 files changed, 26 insertions, 22 deletions
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 @@ <pomVersion>1</pomVersion> <id>jackcess</id> <name>Jackcess</name> - <currentVersion>1.1.1</currentVersion> + <currentVersion>1.1.2</currentVersion> <organization> <name>Health Market Science, Inc.</name> <url>http://www.healthmarketscience.com</url> 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<Column> { 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); |