diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2007-05-08 03:32:44 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2007-05-08 03:32:44 +0000 |
commit | ed6ff8410bf61859e2569905c2326e5b7270f1cd (patch) | |
tree | b0c89d1517dd00c305c161ca7555448e25fa9331 /src/java/com/healthmarketscience/jackcess/Database.java | |
parent | 0df6bc796d4e6a6f0485df2c9774ddab6cd3f7d1 (diff) | |
download | jackcess-ed6ff8410bf61859e2569905c2326e5b7270f1cd.tar.gz jackcess-ed6ff8410bf61859e2569905c2326e5b7270f1cd.zip |
when writing table definition, set things up so long variable length columns are written after normal variable length columns. this makes it more likely that all the data can be written sucessfully because long var columns can be written in separate data pages (fix bug [1675522]); tweak row writing to account for deleted columns
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@143 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java/com/healthmarketscience/jackcess/Database.java')
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/Database.java | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index 3468b4f..492df5f 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -501,14 +501,17 @@ public class Database * @param buffer Buffer to write to * @param columns List of Columns to write definitions for */ - private void writeColumnDefinitions(ByteBuffer buffer, List columns) + private void writeColumnDefinitions(ByteBuffer buffer, List<Column> columns) throws IOException { - Iterator iter; short columnNumber = (short) 0; short fixedOffset = (short) 0; short variableOffset = (short) 0; - for (iter = columns.iterator(); iter.hasNext(); columnNumber++) { - Column col = (Column) iter.next(); + // we specifically put the "long variable" values after the normal + // variable length values so that we have a better chance of fitting it + // all (because "long variable" values can go in separate pages) + short longVariableOffset = + (short) Column.countNonLongVariableLength(columns); + for (Column col : columns) { int position = buffer.position(); buffer.put(col.getType().getValue()); buffer.put((byte) 0x59); //Unknown @@ -516,7 +519,11 @@ public class Database buffer.putShort((short) 0); //Unknown buffer.putShort(columnNumber); //Column Number if (col.isVariableLength()) { - buffer.putShort(variableOffset++); + if(!col.getType().isLongValue()) { + buffer.putShort(variableOffset++); + } else { + buffer.putShort(longVariableOffset++); + } } else { buffer.putShort((short) 0); } @@ -552,14 +559,13 @@ public class Database } else { buffer.putShort((short)0x0000); // unused } + columnNumber++; if (LOG.isDebugEnabled()) { LOG.debug("Creating new column def block\n" + ByteUtil.toHexString( buffer, position, _format.SIZE_COLUMN_DEF_BLOCK)); } } - iter = columns.iterator(); - while (iter.hasNext()) { - Column col = (Column) iter.next(); + for (Column col : columns) { ByteBuffer colName = _format.CHARSET.encode(col.getName()); buffer.putShort((short) colName.remaining()); buffer.put(colName); |