开发者

Can not delete record from SQLite iPhone

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, sql开发者_StackOverflowstmt, -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


you're calling sqlite3_step twice?

Try this :

{
    int result = sqlite3_step(compiledstatement);

    if(SQLITE_DONE != result)

        NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(database) );
 }


Perhaps try:

if(SQLITE_DONE != sqlite3_step(compiledstatement))
    NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(database));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜