开发者

iphone: delete row from sqlite database

开发者 https://www.devze.com 2023-03-05 06:05 出处:网络
I have tried many ways to achieve this biut unable to delete row from sqlite, please help me to correct following piece of code

I have tried many ways to achieve this biut unable to delete row from sqlite, please help me to correct following piece of code

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

NSLog(@"database path --> %@", db开发者_JAVA百科Path);

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);
}

Thanx in advance


have you tried using:

sqlite3_exec(database, sqlStatement...

with your DELETE statement?

ALSO.... it's DELETE FROM.... not DELETE * FROM....

Snagged the following code from another place out on the internet for a more complete example...

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消