eda, sqlite driver, TableEditor: Tweak so that Prev() and Next() work when ponting...
authorJerome St-Louis <jerome@ecere.com>
Fri, 6 Jul 2012 19:22:17 +0000 (15:22 -0400)
committerJerome St-Louis <jerome@ecere.com>
Fri, 6 Jul 2012 19:22:17 +0000 (15:22 -0400)
eda/drivers/sqlite/EDASQLite.ec
eda/libeda/src/gui/TableEditor.ec

index 0512af7..81f2367 100644 (file)
@@ -835,6 +835,9 @@ class SQLiteRow : DriverRow
    bool done;
    done = true;
    int64 rowID;
+   // Because we use GoToSysID() and the sysIDStatement when searching for a primary key with Find(),
+   // this flag is used to distinguish between a Find() and a GoToSysID() for Select(next) purposes:
+   bool findSysID;
    
    bool Nil()
    {
@@ -889,7 +892,8 @@ class SQLiteRow : DriverRow
          case middle:
             break;
          case next:
-            if(!stepping)
+            // For sysID statement, for a Find() we want to go through next/previous in order, otherwise we just go to nil
+            if(!stepping && (curStatement != sysIDStatement || findSysID))
             {
                result = sqlite3_step(curStatement);
                done = result == SQLITE_DONE || (result && result != SQLITE_ROW);
@@ -1120,7 +1124,10 @@ class SQLiteRow : DriverRow
 
       if(fld == tbl.primaryKey)
       {
-         return GoToSysID(*(int *)data);
+         result = GoToSysID(*(int *)data);
+         if(result)
+            findSysID = true;
+         return result;
       }
 
       sprintf(command, "SELECT ROWID, * FROM `%s` WHERE ", tbl.name);
@@ -1261,6 +1268,7 @@ class SQLiteRow : DriverRow
          }
          sqlite3_reset(id ? insertIDStatement : insertStatement);
          curStatement = sysIDStatement;
+         findSysID = false;
          sqlite3_reset(curStatement);
          sqlite3_bind_int64(sysIDStatement, 1, (sqlite3_int64)rowID);
          result = sqlite3_step(curStatement);
@@ -1408,6 +1416,7 @@ class SQLiteRow : DriverRow
       //sprintf(command, "SELECT ROWID, * FROM `%s` WHERE ROWID = ?;", tbl.name);
       //result = sqlite3_prepare_v2(tbl.db.db, command, -1, &statement, null);
 
+      findSysID = false;
       if(curStatement)
          sqlite3_reset(curStatement);
 
index c32f96a..583bf7b 100644 (file)
@@ -565,7 +565,8 @@ public:
    {
       bool result;
       DebugLn("TableEditor::Select");
-      if(idField && editRow.Find(idField, middle, nil, id))
+      // EDA is now set up so that Next()/Prev() will work with sysID = , but not with Find() (As Find() will return a particular set of results)
+      if(idField && (editRow.sysID = id, !editRow.nil))// && editRow.Find(idField, middle, nil, id))
       {
          //Id test = editRow.sysID;
          selectedId = editRow.sysID;