From 55592e3b49b4353b855af422b3507f8f95640a99 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Wed, 16 Apr 2008 17:25:17 +0000 Subject: [PATCH] fix access compatibility issue with writing small rows, limit data pages to 256 rows (#1942330) git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@329 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/changes/changes.xml | 3 +++ .../healthmarketscience/jackcess/JetFormat.java | 15 +++++---------- .../com/healthmarketscience/jackcess/Table.java | 6 ++++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c4ee4c8..4fee05f 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -10,6 +10,9 @@ Need to store auto-number values back into row so that indexes can be updated correctly. + + Access seems to limit data pages to a max of 256 rows. + diff --git a/src/java/com/healthmarketscience/jackcess/JetFormat.java b/src/java/com/healthmarketscience/jackcess/JetFormat.java index 173da95..787cad3 100644 --- a/src/java/com/healthmarketscience/jackcess/JetFormat.java +++ b/src/java/com/healthmarketscience/jackcess/JetFormat.java @@ -92,8 +92,6 @@ public abstract class JetFormat { public final int OFFSET_COLUMN_FIXED_DATA_OFFSET; public final int OFFSET_TABLE_DEF_LOCATION; - public final int OFFSET_NUM_ROWS_ON_PAGE; - public final int OFFSET_ROW_LOCATION_BLOCK; public final int OFFSET_ROW_START; public final int OFFSET_USAGE_MAP_START; @@ -104,6 +102,7 @@ public abstract class JetFormat { public final int OFFSET_FREE_SPACE; public final int OFFSET_NUM_ROWS_ON_DATA_PAGE; + public final int MAX_NUM_ROWS_ON_DATA_PAGE; public final int OFFSET_INDEX_COMPRESSED_BYTE_COUNT; public final int OFFSET_INDEX_ENTRY_MASK; @@ -178,8 +177,6 @@ public abstract class JetFormat { OFFSET_COLUMN_FIXED_DATA_OFFSET = defineOffsetColumnFixedDataOffset(); OFFSET_TABLE_DEF_LOCATION = defineOffsetTableDefLocation(); - OFFSET_NUM_ROWS_ON_PAGE = defineOffsetNumRowsOnPage(); - OFFSET_ROW_LOCATION_BLOCK = defineOffsetRowLocationBlock(); OFFSET_ROW_START = defineOffsetRowStart(); OFFSET_USAGE_MAP_START = defineOffsetUsageMapStart(); @@ -190,6 +187,7 @@ public abstract class JetFormat { OFFSET_FREE_SPACE = defineOffsetFreeSpace(); OFFSET_NUM_ROWS_ON_DATA_PAGE = defineOffsetNumRowsOnDataPage(); + MAX_NUM_ROWS_ON_DATA_PAGE = defineMaxNumRowsOnDataPage(); OFFSET_INDEX_COMPRESSED_BYTE_COUNT = defineOffsetIndexCompressedByteCount(); OFFSET_INDEX_ENTRY_MASK = defineOffsetIndexEntryMask(); @@ -243,8 +241,6 @@ public abstract class JetFormat { protected abstract int defineOffsetColumnFixedDataOffset(); protected abstract int defineOffsetTableDefLocation(); - protected abstract int defineOffsetNumRowsOnPage(); - protected abstract int defineOffsetRowLocationBlock(); protected abstract int defineOffsetRowStart(); protected abstract int defineOffsetUsageMapStart(); @@ -255,6 +251,7 @@ public abstract class JetFormat { protected abstract int defineOffsetFreeSpace(); protected abstract int defineOffsetNumRowsOnDataPage(); + protected abstract int defineMaxNumRowsOnDataPage(); protected abstract int defineOffsetIndexCompressedByteCount(); protected abstract int defineOffsetIndexEntryMask(); @@ -347,10 +344,6 @@ public abstract class JetFormat { @Override protected int defineOffsetTableDefLocation() { return 4; } - @Override - protected int defineOffsetNumRowsOnPage() { return 12; } - @Override - protected int defineOffsetRowLocationBlock() { return 16; } @Override protected int defineOffsetRowStart() { return 14; } @@ -367,6 +360,8 @@ public abstract class JetFormat { protected int defineOffsetFreeSpace() { return 2; } @Override protected int defineOffsetNumRowsOnDataPage() { return 12; } + @Override + protected int defineMaxNumRowsOnDataPage() { return 256; } @Override protected int defineOffsetIndexCompressedByteCount() { return 24; } diff --git a/src/java/com/healthmarketscience/jackcess/Table.java b/src/java/com/healthmarketscience/jackcess/Table.java index 5600d06..ad6d9ad 100644 --- a/src/java/com/healthmarketscience/jackcess/Table.java +++ b/src/java/com/healthmarketscience/jackcess/Table.java @@ -1220,7 +1220,9 @@ public class Table int rowSize = rowData[i].remaining(); int rowSpaceUsage = getRowSpaceUsage(rowSize, getFormat()); short freeSpaceInPage = dataPage.getShort(getFormat().OFFSET_FREE_SPACE); - if (freeSpaceInPage < rowSpaceUsage) { + int rowsOnPage = getRowsOnDataPage(dataPage, getFormat()); + if((freeSpaceInPage < rowSpaceUsage) || + (rowsOnPage >= getFormat().MAX_NUM_ROWS_ON_DATA_PAGE)) { // Last data page is full. Create a new one. writeDataPage(dataPage, pageNumber); @@ -1292,7 +1294,7 @@ public class Table getFormat())); //Free space in this page dataPage.putInt(_tableDefPageNumber); //Page pointer to table definition dataPage.putInt(0); //Unknown - dataPage.putInt(0); //Number of records on this page + dataPage.putShort((short)0); //Number of rows on this page int pageNumber = _addRowBufferH.getPageNumber(); getPageChannel().writePage(dataPage, pageNumber); _ownedPages.addPageNumber(pageNumber); -- 2.39.5