当为SQLite3 db-select查询运行以下准备语句时,我得到一个SQLite错误21“库例程,不按顺序调用”:
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 :(得分:10)
Uopon进一步调查我发现了我的错误。我应该在运行prep语句之前先打开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)]);
...