iphone - SQLite3 - 乱序调用的库例程

标签 iphone objective-c xcode sqlite

当为 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/

相关文章:

ios - 如何在 Swift 中显示当前 PDF 页码并将该页码保存为书签?

objective-c - 计算矩形内最大旋转矩形的点和尺寸

ios - userInteractionEnabled 禁用单元格中的所有元素

Xcode 卡在索引上

ios - 如何在 swift 4 和 xcode 9 中单击 UITableViewCell 中的按钮更新 UILabel?

iphone - iOS:如何动态设置 UITableView 的高度

iPhone 6.0 模拟器不显示主页按钮或框架

iPhone 开发者 : Reload data of a table view from a child controller and another controller in a TabBar

iphone - 在 Objective C 中运行 AJAX 代码

ios - WebKit View 无法打开某些 URL