iOS*_*Dev 0 sqlite iphone delete-row
当我在iPhone模拟器中运行此代码时,我无法从DB中删除记录.如果我在SQLite DB Browser中运行此查询,则效果很好.这是我的代码
SQLiteDB *sqliteConnect=[[SQLiteDB alloc] init];
sqlite3 *database;
if(sqlite3_open([sqliteConnect.databasePath UTF8String], &database)==SQLITE_OK)
{
sqlite3_stmt *compiledstatement;
const char *sqlstmt="delete from searchHistory where id = (select min(id) from searchHistory) ";
if(sqlite3_prepare_v2(database, sqlstmt, -1, &compiledstatement, NULL)==SQLITE_OK)
{
sqlite3_step(compiledstatement);
if(SQLITE_DONE != sqlite3_step(compiledstatement))
NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(database) );
}
NSLog(@"delete DONE");
sqlite3_finalize(compiledstatement);
}
sqlite3_close(database);
Run Code Online (Sandbox Code Playgroud)
当我使用调试器运行时,我得到以下错误=>
2011-04-08 08:42:34.049 MyApp[1838:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error while creating delete statement => not an error'
Run Code Online (Sandbox Code Playgroud)
SQLiteDB是我的类,它包含init和checkAndCopyDB方法的逻辑.我的数据库被复制到文档目录中.其他DB操作工作正常.请帮我.谢谢
你要两次调用sqlite3_step吗?
试试这个 :
{
int result = sqlite3_step(compiledstatement);
if(SQLITE_DONE != result)
NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(database) );
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1632 次 |
| 最近记录: |