2010-08-23 18 views
8

運行時,以下爲sqlite3的DB-selecct查詢,我得到一個SQLLite錯誤「叫了序列的圖書館例行」 21準備聲明:sqlite3的 - 圖書館例行的呼叫順序

sqlite3    *lDb; 
sqlite3_stmt   *lStmt; 
NSNumberFormatter  *lNbrFmt = [[[NSNumberFormatter alloc] init] autorelease]; 

// Define SQL statement 
NSString *lSql = @"SELECT section, language, title, description" 
@"      selector-x-pos, selector-y-pos, gps-x-pos, gps-y-pos" 
@"     FROM sections" 
@"    ORDER BY section ASC"; 

lSqlResult = sqlite3_prepare_v2(lDb, [lSql UTF8String], -1, &lStmt, NULL); 
NSLog(@"%@", [NSString stringWithUTF8String:sqlite3_errmsg(lDb)]); 

什麼時我做錯了?

+0

恭喜上計算出來!你能否重新格式化問題並回答遺留問題,以便將來的訪問者輕鬆解決相同的錯誤?如果不是,你應該完全刪除這個問題。謝謝! – MPelletier 2010-08-23 15:32:00

+1

不用擔心,只是編輯它... – iFloh 2010-08-27 07:10:48

回答

10

Uopon進一步調查我發現我的錯誤。在運行準備語句之前,我應該先打開db。

的代碼應該是這樣的:

sqlite3    *lDb; 
sqlite3_stmt   *lStmt; 
NSNumberFormatter  *lNbrFmt = [[[NSNumberFormatter alloc] init] autorelease]; 

// Define SQL statement 
NSString *lSql = @"SELECT section, language, title, description" 
@"      selector-x-pos, selector-y-pos, gps-x-pos, gps-y-pos" 
@"     FROM sections" 
@"    ORDER BY section ASC"; 

if(sqlite3_open([[fileMethods databasePath] UTF8String], &lDb) == SQLITE_OK) { 
    lSqlResult = sqlite3_prepare_v2(lDb, [lSql UTF8String], -1, &lStmt, NULL); 
    NSLog(@"%@", [NSString stringWithUTF8String:sqlite3_errmsg(lDb)]); 
... 
+0

「圖書館例程調用失序」 - 或檢查你沒有相同的DB已經在其他地方打開..謝謝你的指針;) – Luke 2014-01-17 06:44:10