2010-08-23 15 views
8

Quando si esegue la seguente preparare dichiarazione per una query db-selecct SQLite3 ottengo un errore SqlLite 21 "Biblioteca routine chiamata fuori sequenza":SQLite3 - routine di libreria chiamata fuori sequenza

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)]); 

Cosa am Sto sbagliando?

+0

Congrats a capire che fuori! Potresti riformattare la domanda e rispondere per eredità, in modo che lo stesso errore possa essere risolto facilmente dai futuri visitatori? In caso contrario, dovresti eliminare completamente la domanda. Grazie! – MPelletier

+1

Non preoccuparti, lo hai appena modificato ... – iFloh

risposta

10

Uopon ulteriori indagini ho trovato il mio errore. Dovrei aver prima aperto il db prima di eseguire l'istruzione prep.

Il codice dovrebbe essere simile a questo:

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

"La routine di libreria chiamata fuori sequenza" - Oppure controlla di non avere lo stesso DB aperto già altrove .. Grazie per il puntatore;) – Luke

Problemi correlati