Browse Source

executeUpdate: wasn't returning the correct value when a bad query went though.

August Mueller 14 years ago
parent
commit
d9c0b0eba8
1 changed files with 11 additions and 4 deletions
  1. 11 4
      src/FMDatabase.m

+ 11 - 4
src/FMDatabase.m

@@ -836,7 +836,7 @@ - (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArra
                 retry = NO;
             }
         }
-        else if (SQLITE_DONE == rc || SQLITE_ROW == rc) {
+        else if (SQLITE_DONE == rc) {
             // all is well, let's return.
         }
         else if (SQLITE_ERROR == rc) {
@@ -870,20 +870,27 @@ - (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArra
         [cachedStmt release];
     }
     
+    int closeErrorCode;
+    
     if (cachedStmt) {
         [cachedStmt setUseCount:[cachedStmt useCount] + 1];
-        rc = sqlite3_reset(pStmt);
+        closeErrorCode = sqlite3_reset(pStmt);
     }
     else {
         /* Finalize the virtual machine. This releases all memory and other
          ** resources allocated by the sqlite3_prepare() call above.
          */
-        rc = sqlite3_finalize(pStmt);
+        closeErrorCode = sqlite3_finalize(pStmt);
+    }
+    
+    if (closeErrorCode != SQLITE_OK) {
+        NSLog(@"Unknown error finalizing or resetting statement (%d: %s)", closeErrorCode, sqlite3_errmsg(_db));
+        NSLog(@"DB Query: %@", sql);
     }
     
     _isExecutingStatement = NO;
     [self checkPoolPushBack];
-    return (rc == SQLITE_OK);
+    return (rc == SQLITE_DONE || rc == SQLITE_OK);
 }