Browse Source

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
tags/rel_1_1_2
Tim McCune 18 years ago
parent
commit
f109d76b19

+ 1
- 1
project.properties View File

@@ -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

+ 1
- 1
project.xml View File

@@ -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>

+ 15
- 11
src/java/com/healthmarketscience/jackcess/Column.java View File

@@ -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) {

+ 7
- 7
src/java/com/healthmarketscience/jackcess/Table.java View File

@@ -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) {

+ 2
- 2
test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java View File

@@ -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);

Loading…
Cancel
Save