Ank*_*han 3 sqlite iphone objective-c
我已经尝试了很多方法来实现这个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);
}
Run Code Online (Sandbox Code Playgroud)
Thanx提前
你试过用过:
sqlite3_exec(database, sqlStatement...
Run Code Online (Sandbox Code Playgroud)
你的DELETE语句?
还......它是DELETE FROM ....不是DELETE*FROM ....
从互联网上的另一个地方窃取以下代码以获得更完整的示例......
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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8205 次 |
| 最近记录: |