From 975ae3f8bbfad31652947a1aed51046082821a3a Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Fri, 14 Mar 2008 19:34:14 +0000 Subject: [PATCH] fix creation of tables with auto-number columns git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@273 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/changes/changes.xml | 3 +++ .../healthmarketscience/jackcess/Table.java | 26 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e982615..4e76361 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -28,6 +28,9 @@ Add support for reading table relationships. + + Fix creation of tables with auto-number columns. + diff --git a/src/java/com/healthmarketscience/jackcess/Table.java b/src/java/com/healthmarketscience/jackcess/Table.java index 311f0ad..0c30d79 100644 --- a/src/java/com/healthmarketscience/jackcess/Table.java +++ b/src/java/com/healthmarketscience/jackcess/Table.java @@ -735,7 +735,12 @@ public class Table buffer.putShort((short) 0); //Unknown buffer.putInt(0); //Number of rows buffer.putInt(0); //Last Autonumber - for (int i = 0; i < 16; i++) { //Unknown + if(countAutoNumberColumns(columns) > 0) { + buffer.put((byte) 1); + } else { + buffer.put((byte) 0); + } + for (int i = 0; i < 15; i++) { //Unknown buffer.put((byte) 0); } buffer.put(Table.TYPE_USER); //Table type @@ -1310,6 +1315,11 @@ public class Table return ++_lastAutoNumber; } + int getLastAutoNumber() { + // gets the last used auto number (does not modify) + return _lastAutoNumber; + } + @Override public String toString() { StringBuilder rtn = new StringBuilder(); @@ -1491,6 +1501,20 @@ public class Table return rowSize + format.SIZE_ROW_LOCATION; } + /** + * @return the number of "AutoNumber" columns in the given collection of + * columns. + */ + public static int countAutoNumberColumns(Collection columns) { + int numAutoNumCols = 0; + for(Column c : columns) { + if(c.isAutoNumber()) { + ++numAutoNumCols; + } + } + return numAutoNumCols; + } + /** various statuses for the row data */ private enum RowStatus { INIT, INVALID_PAGE, INVALID_ROW, VALID, DELETED, NORMAL, OVERFLOW; -- 2.39.5