xcode SQLite3 - 乱序调用的库例程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3546689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLite3 - Library routine called out of sequence
提问by
When running the following prepare statement for a SQLite3 db-selecct query I get a SQLLite Error 21 "Library routine called out of sequence":
当为 SQLite3 db-selecct 查询运行以下准备语句时,我收到 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)]);
What am I doing wrong?
我究竟做错了什么?
回答by
Uopon further investigation I found my mistake. I should have first opened the db before running the prep statement.
Uopon 进一步调查我发现了我的错误。我应该在运行 prep 语句之前先打开数据库。
The code should look like this:
代码应如下所示:
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)]);
...