]> source.dussan.org Git - jackcess.git/commitdiff
Added handling of deleted rows.
authorTim McCune <javajedi@users.sf.net>
Fri, 12 Aug 2005 05:28:37 +0000 (05:28 +0000)
committerTim McCune <javajedi@users.sf.net>
Fri, 12 Aug 2005 05:28:37 +0000 (05:28 +0000)
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

project.xml
src/java/com/healthmarketscience/jackcess/Table.java
test/data/delTest.mdb [new file with mode: 0644]
test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java

index fa8da634620d52c82f7b8ea7de5b181cac8d4684..2e26fe5c471910e074e83ac9facf3c175144f5f8 100644 (file)
@@ -3,7 +3,7 @@
   <pomVersion>1</pomVersion>
   <id>jackcess</id>
   <name>Jackcess</name>
-  <currentVersion>1.0</currentVersion>
+  <currentVersion>1.1</currentVersion>
   <organization>
     <name>Health Market Science, Inc.</name>
     <url>http://www.healthmarketscience.com</url>
@@ -18,7 +18,7 @@
   <siteDirectory>/home/groups/j/ja/jackcess/htdocs</siteDirectory>
   <repository>
     <connection>scm:cvs:pserver:anonymous@cvs.sf.net:/cvsroot/jackcess:jackcess</connection>
-    <url>http://cvs.sf.net/viewcvs.py/jackcess/</url>
+    <url>http://cvs.sf.net/viewcvs.py/</url>
   </repository>
   <mailingLists>
     <mailingList>
index 4714eb118f76a18475e6bf459054f5571fcca3fb..f9f7f1f1742926a5330c8251019bf9fee5b4be55 100644 (file)
@@ -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 (file)
index 0000000..915caa2
Binary files /dev/null and b/test/data/delTest.mdb differ
index 6b1fc0e6c702b3a81e1737c3a547f5984796a39e..c4dac937b5b7486b2f61de1e9a474c69d719d17e 100644 (file)
@@ -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();