从sqlite3_open按顺序调用库例程 [英] Library routine called out of sequence from sqlite3_open

查看:35
本文介绍了从sqlite3_open按顺序调用库例程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在应用程序首次加载时创建/打开sqlite数据库.但是由于未捕获的异常"NSInternalInconsistencyException",我不断收到错误正在终止应用程序,原因:错误:由于库例程调用顺序错误而无法打开" 下面是我在主viewcontroller文件中的代码:

I am trying to create/open an sqlite database when the application first loads. But I am constantly getting the error Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error: Failed to open because library routine called out of sequence' Below is my code in the main viewcontroller file:

- (NSString *) filePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
    return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"bp.sql"];
}

- (void)openDB {
    if (sqlite3_open([[self filePath] UTF8String], &db) != SQLITE_OK) {
        sqlite3_close(db);
        NSAssert1(0, @"Error: Failed to open because %s", sqlite3_errmsg(db));
    }
    else {
        NSLog(@"Database opened");
    }
}

    - (void)viewDidLoad {
    [self openDB];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

推荐答案

此错误的原因是您在 sqlite3_close 之后调用了 sqlite3_errmsg ;您会在清理过程中收到无害的错误.

The reasone for this error is that you called sqlite3_errmsg after sqlite3_close; you get a harmless error that happened during cleanup.

您必须在 sqlite3_close 之前调用 sqlite3_errmsg 以获得实际错误.

You must call sqlite3_errmsg before sqlite3_close to get the actual error.

这篇关于从sqlite3_open按顺序调用库例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆