2010-08-17 119 views
2

- (無效){dropCategories數據庫被鎖定-sqlite3

 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; 
} 

調用此函數一次工作正常,但每當我再次調用它,它終止給下面的例外。

任何建議爲什麼會發生這種情況?

*** 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' 

回答

3

您致電sqlite3_finalize似乎已被評論。對sqlite3_prepare_v2的完整調用通常後跟sqlite_step,然後sqlite3_finalize。你能試試嗎,沒有sqlite3_reset

編輯:後代:提問者發現真正的原因,數據庫被另一個對象鎖定。以上功能沒問題。

+0

我已經嘗試過,但似乎仍然沒有工作。終止應用程序。有什麼辦法可以強制解鎖數據庫或清除以前的所有鎖嗎? 希望能解決我的問題。 – 2010-08-17 12:03:59

+0

嗯...你試過'sqlite3_exec'嗎?所有功能於一身的查詢執行! – MPelletier 2010-08-17 13:50:16

+0

我終於發現問題出在我的代碼上。 我已經打開了2個不同的對象的數據庫..最後挑選出來 – 2010-08-20 09:31:39