当我在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);
当我使用调试器运行时,我得到以下错误=>
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'
SQLiteDB是我的类,包含init和amp;的逻辑。 checkAndCopyDB方法。我的数据库被复制到文档目录中。其他DB操作工作正常。请帮我。感谢
答案 0 :(得分:6)
试试这个:
{
int result = sqlite3_step(compiledstatement);
if(SQLITE_DONE != result)
NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(database) );
}
答案 1 :(得分:1)
也许试试:
if(SQLITE_DONE != sqlite3_step(compiledstatement))
NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(database));