iphone - Strange SQLite behavior -
I am inserting data into a table and SQLite3_step returns SQLITE_DONE. But sometimes there is no new data in the table! I have been adding data immediately after the check, even if
here is my code:.
sqlite3_stmt * addTranslationStmt2 = zero; If (sqlite3_prepare_v2 (database "translation" (lang1_wordid, lang2_wordid) inserted in values (?,)? ", -1, & amp; addTranslationStmt2, zero) = SQLITE_OK {NSLog (@" Prepare statement error "); AddTranslationStmt2 = NULL; Return -1; } Sqlite3_bind_int (addTranslationStmt2, 1, word_id); Sqlite3_bind_int (Additional translation STM2, 2, translation_ID); If {NSLog (@ "addTranslationStmt2 error: '% s'", sqlite3_errmsg (database)) (sqlite3_step (addTranslationStmt2) = SQLITE_DONE!); Sqlite3_reset (addTranslationStmt2); Return -1; } Sqlite3_reset (addTranslationStmt2); If ([self-wordHasTranslation: word_id translation_id: translation_id]!) NSLog (@ "! And after all SQLite3_step returns SQLITE_DONE");
So I'm wondering why the last mentioned log function is being said that it does not have data in the table after adding data, sometimes it adds and sometimes -Not like this.
Where can the problem be? thank you in advanced.
UPDATE: I came to know that this happens when a new database is created. It works correctly after restarting an application. But if a new database is created, weird behavior comes back.
SQL works by default in auto -meter mode, but we do not have any address Some previous interactions or settings may have been reset; If you add COMMIT
after INSERT
, does that help?
EDIT: Probably not, let the information be ahead of the comments, but in the bus if you should be committed in other circumstances, the easiest way is:
four * Errmsg; Int result = sqlite3_exec (database, "comma", zero, zero, and errmsg); With normal result code and C.
you will need to use the error message after having sqlite3_free (errmsg)
, if any).
Comments
Post a Comment