[英]iphone: delete row from sqlite database
I have tried many ways to achieve this biut unable to delete row from sqlite, please help me to correct following piece of code 我已经尝试了很多方法来实现这个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);
}
Thanx in advance Thanx提前
have you tried using: 你试过用过:
sqlite3_exec(database, sqlStatement...
with your DELETE statement? 你的DELETE语句?
ALSO.... it's DELETE FROM.... not DELETE * FROM.... 还......它是DELETE FROM ....不是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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.