How to delete a row in a sqlite database table?

人走茶凉 提交于 2019-12-05 05:08:11

FMDB can be a little finicky if you dont pass in the object as an NSNumber. This is the supported, and safe way of formatting queries.

[db executeUpdate:@"DELETE FROM theTable WHERE id = ?", [NSNumber numberWithInt:myObject.id]];
Florin

You should replace:

... [database executeQuery:sqlStat] ...

with:

... [database executeUpdate:sqlStat];

Also, try adding:

[database beginTransaction];

before your CRUD block, and:

[database commit];

after executing an update/delete/insert operation.

;)

i also ran into the same symptom. and my problem was i didnt call (and caused "out of memory" error)

[db open];

be sure to do this to debug your fmdb issues db.traceExecution=YES; db.logsErrors=YES;

you need to ensure all the processes

NSString *query = @"delete from places where published = 1";
const char *sqlStatement = [query UTF8String];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
    // Loop through the results and add them to the feeds array
    while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
        // Read the data from the result row
        NSLog(@"result is here");
    }

    // Release the compiled statement from memory
    sqlite3_finalize(compiledStatement);

}
int numberOfEffectedRow = sqlite3_changes(database);
return numberOfEffectedRow; // get number of effected rows
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!