summaryrefslogtreecommitdiffstats
path: root/src/java/com/healthmarketscience/jackcess/Column.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/healthmarketscience/jackcess/Column.java')
-rw-r--r--src/java/com/healthmarketscience/jackcess/Column.java36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java
index a41b450..85ebde0 100644
--- a/src/java/com/healthmarketscience/jackcess/Column.java
+++ b/src/java/com/healthmarketscience/jackcess/Column.java
@@ -345,6 +345,12 @@ public class Column implements Comparable<Column> {
return;
}
+ if((_autoNumberGenerator != null) &&
+ (_autoNumberGenerator.getType() == _type)) {
+ // keep existing
+ return;
+ }
+
switch(_type) {
case LONG:
_autoNumberGenerator = new LongAutoNumberGenerator();
@@ -1098,7 +1104,7 @@ public class Column implements Comparable<Column> {
public ByteBuffer writeFixedLengthField(Object obj, ByteOrder order)
throws IOException
{
- int size = getType().getFixedSize();
+ int size = getType().getFixedSize(_columnLength);
// create buffer for data
ByteBuffer buffer = getPageChannel().createBuffer(size, order);
@@ -1132,6 +1138,19 @@ public class Column implements Comparable<Column> {
case MONEY:
writeCurrencyValue(buffer, obj);
break;
+ case TEXT:
+ // apparently text numeric values are also occasionally written as fixed
+ // length...
+ CharSequence text = toCharSequence(obj);
+ int numChars = getLengthInUnits();
+ if (text.length() != numChars) {
+ throw new IOException(
+ "Text is invalid for fixed length column, length " + numChars
+ + ", got " + text.length());
+ }
+ // force uncompressed encoding for fixed length text
+ buffer.put(encodeUncompressedText(text, getFormat()));
+ break;
case GUID:
writeGUIDValue(buffer, obj, order);
break;
@@ -1538,6 +1557,11 @@ public class Column implements Comparable<Column> {
* Returns the flags used when writing this column.
*/
public abstract int getColumnFlags();
+
+ /**
+ * Returns the type of values generated by this generator.
+ */
+ public abstract DataType getType();
}
private final class LongAutoNumberGenerator extends AutoNumberGenerator
@@ -1560,6 +1584,11 @@ public class Column implements Comparable<Column> {
public int getColumnFlags() {
return AUTO_NUMBER_FLAG_MASK;
}
+
+ @Override
+ public DataType getType() {
+ return DataType.LONG;
+ }
}
private final class GuidAutoNumberGenerator extends AutoNumberGenerator
@@ -1584,6 +1613,11 @@ public class Column implements Comparable<Column> {
public int getColumnFlags() {
return AUTO_NUMBER_GUID_FLAG_MASK;
}
+
+ @Override
+ public DataType getType() {
+ return DataType.GUID;
+ }
}
}