From 2cc11038b960176bb216e061e93cf7cfa37e05b5 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Mon, 18 Sep 2006 14:28:28 +0000 Subject: [PATCH] do not ask me why, but numeric columns are considered variable length, even though they are always the same size git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@110 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../healthmarketscience/jackcess/Column.java | 17 +++++++--- .../jackcess/DataType.java | 33 ++++++++++++------- .../jackcess/Database.java | 6 ++-- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java index 6650048..baa48c3 100644 --- a/src/java/com/healthmarketscience/jackcess/Column.java +++ b/src/java/com/healthmarketscience/jackcess/Column.java @@ -251,7 +251,8 @@ public class Column implements Comparable { throw new IllegalArgumentException("invalid fixed length size"); } } else if(!getType().isLongValue()) { - if((getLength() < 0) || (getLength() > getType().getMaxSize())) { + if((getLength() < getType().getMinSize()) || + (getLength() > getType().getMaxSize())) { throw new IllegalArgumentException("var length out of range"); } } @@ -726,6 +727,16 @@ public class Column implements Comparable { // this is an "inline" var length field switch(getType()) { + case NUMERIC: + // don't ask me why numerics are "var length" columns... + ByteBuffer buffer = ByteBuffer.allocate(getLength()); + System.out.println("BUZ NUMERIC " + getLength()); + buffer.order(order); + writeNumericValue(buffer, obj); + buffer.flip(); + System.out.println("BUZ NUMERIC rem " + buffer.remaining()); + return buffer; + case TEXT: CharSequence text = toCharSequence(obj); int maxChars = getLength() / 2; @@ -735,6 +746,7 @@ public class Column implements Comparable { byte[] encodedData = encodeUncompressedText(text).array(); obj = encodedData; break; + case BINARY: // should already be "encoded" break; @@ -807,9 +819,6 @@ public class Column implements Comparable { case MONEY: writeCurrencyValue(buffer, obj); break; - case NUMERIC: - writeNumericValue(buffer, obj); - break; case GUID: writeGUIDValue(buffer, obj); break; diff --git a/src/java/com/healthmarketscience/jackcess/DataType.java b/src/java/com/healthmarketscience/jackcess/DataType.java index 4050958..889377b 100644 --- a/src/java/com/healthmarketscience/jackcess/DataType.java +++ b/src/java/com/healthmarketscience/jackcess/DataType.java @@ -47,14 +47,15 @@ public enum DataType { FLOAT((byte) 0x06, Types.FLOAT, 4), DOUBLE((byte) 0x07, Types.DOUBLE, 8), SHORT_DATE_TIME((byte) 0x08, Types.TIMESTAMP, 8), - BINARY((byte) 0x09, Types.BINARY, null, true, false, 255, 255), - TEXT((byte) 0x0A, Types.VARCHAR, null, true, false, 50 * 2, + BINARY((byte) 0x09, Types.BINARY, null, true, false, 0, 255, 255), + TEXT((byte) 0x0A, Types.VARCHAR, null, true, false, 0, 50 * 2, (int)JetFormat.TEXT_FIELD_MAX_LENGTH), - OLE((byte) 0x0B, Types.LONGVARBINARY, null, true, true, null, 0xFFFFFF), - MEMO((byte) 0x0C, Types.LONGVARCHAR, null, true, true, null, 0xFFFFFF), + OLE((byte) 0x0B, Types.LONGVARBINARY, null, true, true, 0, null, 0xFFFFFF), + MEMO((byte) 0x0C, Types.LONGVARCHAR, null, true, true, 0, null, 0xFFFFFF), UNKNOWN_0D((byte) 0x0D), GUID((byte) 0x0F, null, 16), - NUMERIC((byte) 0x10, Types.NUMERIC, 17, false, false, null, null, + // for some reason numeric is "var len" even though it has a fixed size... + NUMERIC((byte) 0x10, Types.NUMERIC, null, true, false, 17, 17, 17, true, 0, 0, 28, 1, 18, 28); /** Map of SQL types to Access data types */ @@ -92,9 +93,11 @@ public enum DataType { private byte _value; /** Size in bytes of fixed length columns */ private Integer _fixedSize; - /** default size for var length columns */ + /** min in bytes size for var length columns */ + private Integer _minSize; + /** default size in bytes for var length columns */ private Integer _defaultSize; - /** Max size in bytes */ + /** Max size in bytes for var length columns */ private Integer _maxSize; /** SQL type equivalent, or null if none defined */ private Integer _sqlType; @@ -116,21 +119,24 @@ public enum DataType { } private DataType(byte value, Integer sqlType, Integer fixedSize) { - this(value, sqlType, fixedSize, false, false, null, null); + this(value, sqlType, fixedSize, false, false, null, null, null); } private DataType(byte value, Integer sqlType, Integer fixedSize, boolean variableLength, boolean longValue, + Integer minSize, Integer defaultSize, Integer maxSize) { - this(value, sqlType, fixedSize, variableLength, longValue, defaultSize, - maxSize, false, null, null, null, null, null, null); + this(value, sqlType, fixedSize, variableLength, longValue, + minSize, defaultSize, maxSize, + false, null, null, null, null, null, null); } private DataType(byte value, Integer sqlType, Integer fixedSize, boolean variableLength, boolean longValue, + Integer minSize, Integer defaultSize, Integer maxSize, boolean hasScalePrecision, @@ -145,6 +151,7 @@ public enum DataType { _fixedSize = fixedSize; _variableLength = variableLength; _longValue = longValue; + _minSize = minSize; _defaultSize = defaultSize; _maxSize = maxSize; _hasScalePrecision = hasScalePrecision; @@ -180,6 +187,10 @@ public enum DataType { } } + public int getMinSize() { + return _minSize; + } + public int getDefaultSize() { return _defaultSize; } @@ -237,5 +248,5 @@ public enum DataType { throw new SQLException("Unsupported SQL type: " + sqlType); } } - + } diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index ffed46a..24e5e4e 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -462,7 +462,7 @@ public class Database buffer.put((byte) 0x06); //Unknown buffer.putShort((short) 0); //Unknown buffer.putShort(columnNumber); //Column Number - if (col.getType().isVariableLength()) { + if (col.isVariableLength()) { buffer.putShort(variableOffset++); } else { buffer.putShort((short) 0); @@ -476,7 +476,7 @@ public class Database buffer.put((byte) 0x00); //unused } buffer.putShort((short) 0); //Unknown - if (col.getType().isVariableLength()) { //Variable length + if (col.isVariableLength()) { //Variable length buffer.put((byte) 0x2); } else { buffer.put((byte) 0x3); @@ -488,7 +488,7 @@ public class Database } buffer.putInt(0); //Unknown, but always 0. //Offset for fixed length columns - if (col.getType().isVariableLength()) { + if (col.isVariableLength()) { buffer.putShort((short) 0); } else { buffer.putShort(fixedOffset); -- 2.39.5