无法从 SQLite iPhone 中删除记录
当我在 iPhone 模拟器中运行此代码时,我无法从数据库中删除记录。如果我在 SQLite DB 浏览器中运行此查询,它效果很好。这是我的代码
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 和 SQLiteDB 的逻辑。 checkAndCopyDB 方法。我的数据库被复制到文档目录中。其他数据库操作工作正常。请帮我。谢谢
When I run this code in iPhone simulator ,I can not delete record from DB . If I run this query in SQLite DB Browser it works well. Here is my code
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);
When I run using debugger , I get following error =>
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 is my class which contains logic for init & checkAndCopyDB methods. My DB gets copied in documents directory. Other DB operations works fine. Please help me. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你调用 sqlite3_step 两次?
试试这个:
you're calling sqlite3_step twice?
Try this :
也许尝试:
Perhaps try: