Reputation: 6991
I am implementing some code for reading and writing the an sqlite3 database. Reading the database works fine, displaying the row is not a problem at all. The problem is in inserting a new row. For some reason it just does not work, sqlite does not return an error after executing the SQL.
if( sqlite3_prepare_v2(db, "INSERT INTO `items` (`itemID`, `itemName`) VALUES (2, 'helloWorld?')", -1, &statement, NULL) != SQLITE_OK)
{
NSAssert1(0, @"Error, unable to modify database",sqlite3_errmsg(db));
}
db and statement:
sqlite3 *db = [RootViewController newDatabaseConnection];
sqlite3_stmt *statement = nil;
Also I do know there is a framework called Core data, so please no answers saying use core data
The database file "AppName.sqlite3" is not located in the app's mainfolder, but in the documents folder so it should be editable
My SQL syntax is ok, tried adding the item using the command line. Everything works fine there.
Upvotes: 0
Views: 199
Reputation: 58468
As far as I'm aware, preparing a statement doesn't actually execute it. You need to call sqlite3_step()
and pass the prepared statement in order for the SQL to be executed.
A a guide, you should prepare the statement and step through the results, then finalise the statement when you're done with it. Then when you're done with the db connection, you can close it.
Upvotes: 1