数据库被锁定-sqlite3 [英] Database is locked -sqlite3

查看:141
本文介绍了数据库被锁定-sqlite3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- (void)dropCategories {

-(void) dropCategories{

        if (deleteCategoryStmt == nil) {
            const char *deleteSql = "delete from tb_category";
            if (sqlite3_prepare_v2(database, deleteSql, -1, &deleteCategoryStmt, NULL) != SQLITE_OK) 
                    NSAssert1(0,@"Error in preparing drop category statement with '%s'", sqlite3_errmsg(database));
            else 
                    NSLog(@"NO error in creating drop categories statement");


        }

        if(SQLITE_DONE != sqlite3_step(deleteCategoryStmt))
            NSAssert1(0, @"Error while drop category data. '%s'", sqlite3_errmsg(database));

    sqlite3_reset(deleteCategoryStmt);  
    //sqlite3_finalize(deleteCategoryStmt);
    deleteCategoryStmt = nil;
}

调用此函数一旦正常工作,但每当我再次调用它时它会终止给定以下例外。

Call to this function once works fine but whenever i calls it again it terminates giving the below exception.

任何建议为什么会发生这种情况?

Any suggestion Why is such happening?

 *** Assertion failure in -[Category dropCategories], /Users/rsplmac/Documents/LiteApp2/Classes/Category.m:171
2010-08-17 14:01:06.648 LiteApp2[4335:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error while drop category data. 'database is locked''
*** Call stack at first throw:
(
    0   CoreFoundation                      0x02429919 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x025775de objc_exception_throw + 47
    2   CoreFoundation                      0x023e2078 +[NSException raise:format:arguments:] + 136
    3   Foundation                          0x000ce8cf -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
    4   LiteApp2                            0x000043ce -[Category dropCategories] + 462
    5   LiteApp2                            0x00004ba3 -[RootViewController updateMe:] + 1297
    6   UIKit                               0x002d3e14 -[UIApplication sendAction:to:from:forEvent:] + 119
    7   UIKit                               0x004db14b -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
    8   UIKit                               0x002d3e14 -[UIApplication sendAction:to:from:forEvent:] + 119
    9   UIKit                               0x0035d6c8 -[UIControl sendAction:to:forEvent:] + 67
    10  UIKit                               0x0035fb4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    11  UIKit                               0x0035e6f7 -[UIControl touchesEnded:withEvent:] + 458
    12  UIKit                               0x002f72ff -[UIWindow _sendTouchesForEvent:] + 567
    13  UIKit                               0x002d91ec -[UIApplication sendEvent:] + 447
    14  UIKit                               0x002ddac4 _UIApplicationHandleEvent + 7495
    15  GraphicsServices                    0x02c15afa PurpleEventCallback + 1578
    16  CoreFoundation                      0x0240adc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    17  CoreFoundation                      0x0236b737 __CFRunLoopDoSource1 + 215
    18  CoreFoundation                      0x023689c3 __CFRunLoopRun + 979
    19  CoreFoundation                      0x02368280 CFRunLoopRunSpecific + 208
    20  CoreFoundation                      0x023681a1 CFRunLoopRunInMode + 97
    21  GraphicsServices                    0x02c142c8 GSEventRunModal + 217
    22  GraphicsServices                    0x02c1438d GSEventRun + 115
    23  UIKit                               0x002e1b58 UIApplicationMain + 1160
    24  LiteApp2                            0x00002808 main + 102
    25  LiteApp2                            0x00002799 start + 53
)
terminate called after throwing an instance of 'NSException'


推荐答案

您的 sqlite3_finalize 的来电出现被评论。完全调用 sqlite3_prepare_v2 后面通常会跟着 sqlite_step 然后 sqlite3_finalize 。你可以试试吗,没有 sqlite3_reset

Your call to sqlite3_finalize appears to be commented. A complete call to sqlite3_prepare_v2 is usually followed by sqlite_step then sqlite3_finalize. Can you try that, without sqlite3_reset?

编辑:对于后人:提问者找到了真正的原因,数据库是被另一个物体锁定。以上功能很好。

For posterity: asker found the real cause, the database was locked by another object. Above function was fine.

这篇关于数据库被锁定-sqlite3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆