当为 SQLite3 db-select 查询运行以下准备语句时,我收到 SQLLite 错误 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)]);
我做错了什么?
最佳答案
经过进一步调查,我发现了我的错误。我应该在运行准备语句之前先打开数据库。
代码应该是这样的:
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)]);
...
关于iphone - SQLite3 - 乱序调用的库例程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3546689/