我已经尝试了很多方法来实现这个biut无法从sqlite中删除行,请帮助我更正以下代码

dbPath = [self applicationDocumentsDirectory];
NSLog(@"%@", dbPath);
dbPath=[dbPath stringByAppendingPathComponent:@"database"];
dbPath=[dbPath stringByAppendingPathComponent:@"OFFENDERSDB.sqlite"];

NSLog(@"database path --> %@", dbPath);

if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
    const char *sqlStatement = ("DELETE * from OFFENDERS_LIST where ID=%d ",2);

    sqlite3_stmt *compiledStatement;

    if (sqlite3_prepare(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {

        NSLog(@"offender deleted");
    }
    sqlite3_finalize(compiledStatement);
}

提前付款

最佳答案

你试过使用:

sqlite3_exec(database, sqlStatement...

你的删除声明?
也。。。。它是从…中删除的。不是从…中删除*。
从Internet上的另一个地方获取以下代码以获得更完整的示例…
sqlite3 *db;
int rc;

rc = sqlite3_open( "C:\\MyDatabase", &db );

if ( rc )
{
        sqlite3_close(db);
}
else //Database connection opened successfuly
{
        char *zErrMsg = 0;

        rc = sqlite3_exec( db, "DELETE FROM yourTable", NULL, NULL, &zErrMsg );

        if( rc != SQLITE_OK )
        {
                sqlite3_free( zErrMsg );
        }

        sqlite3_close(db);
}

10-01 16:50