Просмотр исходного кода

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
tags/rel_1_1_7
James Ahlborn 17 лет назад
Родитель
Сommit
2cc11038b9

+ 13
- 4
src/java/com/healthmarketscience/jackcess/Column.java Просмотреть файл

@@ -251,7 +251,8 @@ public class Column implements Comparable<Column> {
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<Column> {
// 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<Column> {
byte[] encodedData = encodeUncompressedText(text).array();
obj = encodedData;
break;
case BINARY:
// should already be "encoded"
break;
@@ -807,9 +819,6 @@ public class Column implements Comparable<Column> {
case MONEY:
writeCurrencyValue(buffer, obj);
break;
case NUMERIC:
writeNumericValue(buffer, obj);
break;
case GUID:
writeGUIDValue(buffer, obj);
break;

+ 22
- 11
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);
}
}
}

+ 3
- 3
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);

Загрузка…
Отмена
Сохранить