[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mdbtools-dev
Subject:    [mdb-dev] Deleted rows (again)
From:       Brent Johnson <xone47 () yahoo ! com>
Date:       2000-08-10 3:49:25
[Download RAW message or body]

 Here is my latest diff of data.c.

 I submitted a modified mdb_find_end_if_row() previously (which is included in
this patch).  That logic seems to work correctly.

 Now, mdb_read_row() can't do anything when it recognizes a deleted row, so I
modified mdb_fetch_row() to skip over any deleted rows by having mdb_read_row()
return a -1 for a deleted row and a 0 for a 'real' row.

 It works for the one case I had.

 It appeared that the offset of the deleted row was changed to the offset of
the previous row with the first 2 bits set (flags?).  If this is always the
case, maybe mdb_find_end_if_row doesn't need to loop, but rather just strip off
the flags and the original (pre-Michael's patch) version would work????

 Anyone concur?

  Brent


Index: data.c
===================================================================
RCS file: /cvsroot/mdbtools/mdbtools/src/libmdb/data.c,v
retrieving revision 1.24
diff -u -r1.24 data.c
--- data.c	2000/08/09 03:04:58	1.24
+++ data.c	2000/08/10 03:48:34
@@ -33,25 +33,22 @@
 }
 int mdb_find_end_of_row(MdbHandle *mdb, int row)
 {
-int rows, row_start, row_end, i;
+int row_start, row_end, i;
 
-	rows = mdb_get_int16(mdb,8);
-	if (row==0) 
-		row_end = mdb->pg_size - 1; /* end of page */
-	else {
-		row_end = mdb_get_int16(mdb, (10 + (row-1) * 2)) - 1;
-
-		for (i = row - 1; i > 0; i--) {
-			row_start = mdb_get_int16(mdb, (10 + i * 2));
-			if (!(row_start & 0x8000)) {
-				break;
-			}
+	/* Search the previous "row start" values for the first non-deleted one.
+	 * If we don't find one, then the end of the page is the correct value.
+	 */
+	for (i = row - 1; i >= 0; i--) {
+		row_start = mdb_get_int16(mdb, (10 + i * 2));
+		if (!(row_start & 0x8000)) {
+			break;
 		}
-		if (i == 0) {
-			row_end = mdb->pg_size - 1;
-		} else {
-			row_end = row_start - 1;
-		}
+	}
+
+	if (i == -1) {
+		row_end = mdb->pg_size - 1;
+	} else {
+		row_end = row_start - 1;
 	}
 
 	return row_end;
@@ -108,8 +105,7 @@
 		delflag ? "[delflag]" : "");
 #endif	
 	if (delflag || lookupflag) {
-		row_end = row_start-1;
-		return 0;
+		return -1;
 	}
 
 #if MDB_DEBUG
@@ -181,7 +177,7 @@
 		}
 	}
 
-	row_end = row_start-1;
+	return 0;
 }
 int mdb_read_next_dpg(MdbTableDef *table)
 {
@@ -223,8 +219,14 @@
 		if (!mdb_read_next_dpg(table)) return 0;
 	}
 
-	mdb_read_row(table, 
-		table->cur_row);
+	/* Skip over any deleted rows.
+	 *  mdb_read_row() returns -1 on deleted rows.
+	 *  mdb_read_row() returns 0 on actual rows.
+	 */
+	while(mdb_read_row(table,
+		table->cur_row)) {
+		table->cur_row++;
+	}
 
 	table->cur_row++;
 	return 1;

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic