From: Tim McCune Date: Fri, 12 Aug 2005 05:28:37 +0000 (+0000) Subject: Added handling of deleted rows. X-Git-Tag: rel_1_1~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cd4c2188725dec869749adb490ef24bebc720813;p=jackcess.git Added handling of deleted rows. Fixed a couple bugs introduced by the 1.5 upgrade. git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@19 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/project.xml b/project.xml index fa8da63..2e26fe5 100644 --- a/project.xml +++ b/project.xml @@ -3,7 +3,7 @@ 1 jackcess Jackcess - 1.0 + 1.1 Health Market Science, Inc. http://www.healthmarketscience.com @@ -18,7 +18,7 @@ /home/groups/j/ja/jackcess/htdocs scm:cvs:pserver:anonymous@cvs.sf.net:/cvsroot/jackcess:jackcess - http://cvs.sf.net/viewcvs.py/jackcess/ + http://cvs.sf.net/viewcvs.py/ diff --git a/src/java/com/healthmarketscience/jackcess/Table.java b/src/java/com/healthmarketscience/jackcess/Table.java index 4714eb1..f9f7f1f 100644 --- a/src/java/com/healthmarketscience/jackcess/Table.java +++ b/src/java/com/healthmarketscience/jackcess/Table.java @@ -202,9 +202,9 @@ public class Table { if (column.getType() == DataType.BOOLEAN) { value = new Boolean(!isNull); //Boolean values are stored in the null mask } else if (!isNull) { - if (!column.getType().isVariableLength()) { + if (!column.isVariableLength()) { //Read in fixed length column data - columnData = new byte[column.getType().getSize()]; + columnData = new byte[column.size()]; _buffer.get(columnData); } else { //Refer to already-read-in variable length data @@ -238,13 +238,18 @@ public class Table { } _rowStart = _buffer.getShort(_format.OFFSET_DATA_ROW_LOCATION_BLOCK + _currentRowInPage * _format.SIZE_ROW_LOCATION); - // XXX - Handle overflow pages and deleted rows. - _buffer.position(_rowStart); - _buffer.limit(_lastRowStart); - _rowsLeftOnPage--; _currentRowInPage++; - _lastRowStart = _rowStart; - return true; + _rowsLeftOnPage--; + if (_rowStart < 0) { + // Deleted row. Skip. + return positionAtNextRow(); + } else { + // XXX - Handle overflow pages. + _buffer.position(_rowStart); + _buffer.limit(_lastRowStart); + _lastRowStart = _rowStart; + return true; + } } /** @@ -439,7 +444,7 @@ public class Table { for (iter = _columns.iterator(); iter.hasNext() && index < row.size(); index++) { col = (Column) iter.next(); - if (!col.getType().isVariableLength()) { + if (!col.isVariableLength()) { //Fixed length column data comes first if (row.get(index) != null) { buffer.put(col.write(row.get(index))); @@ -464,7 +469,7 @@ public class Table { for (iter = _columns.iterator(); iter.hasNext() && index < row.size(); index++) { col = (Column) iter.next(); short offset = (short) buffer.position(); - if (col.getType().isVariableLength()) { + if (col.isVariableLength()) { if (row.get(index) != null) { buffer.put(col.write(row.get(index))); } diff --git a/test/data/delTest.mdb b/test/data/delTest.mdb new file mode 100644 index 0000000..915caa2 Binary files /dev/null and b/test/data/delTest.mdb differ diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java index 6b1fc0e..c4dac93 100644 --- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -29,6 +29,15 @@ public class DatabaseTest extends TestCase { //tmp.deleteOnExit(); return Database.create(tmp); } + + public void testReadDeletedRows() throws Exception { + Table table = Database.open(new File("test/data/delTest.mdb")).getTable("Table"); + int rows = 0; + while (table.getNextRow() != null) { + rows++; + } + assertEquals(2, rows); + } public void testGetColumns() throws Exception { List columns = open().getTable("Table1").getColumns();