【问题标题】:Sqlite Prepare Failed: No such table <table_name>Sqlite 准备失败:没有这样的表 <table_name>
【发布时间】:2010-11-20 14:00:16
【问题描述】:

我在我的 iphone 应用程序中使用 Sqlite 数据库。

在我的应用程序中,我最初使用了一个绝对路径,例如 @"/Users/macos/Documents/appdatabase.sql

现在我想在设备上运行应用程序。它需要相对路径。

需要做什么才能获得数据库的路径?

当我尝试使用设备上的绝对路径运行时出现此错误。

Sqlite Prepare 失败:没有这样的表

我已检查该表已存在于我的数据库中。

如何获取数据库的相对路径?

请帮助和建议。

谢谢

【问题讨论】:

    标签: iphone objective-c cocoa-touch ios4


    【解决方案1】:

    你可以使用这个来获取数据库路径 -

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDir = [documentPaths objectAtIndex:0];
        NSString *databasePath = [documentsDir stringByAppendingPathComponent:@"mydb.sqlite"];
    

    还可以从模拟器或设备中删除您的应用,然后再次运行/安装它。

    【讨论】:

    • 使用前需要先致电[databasePath stringByExpandingTildeInPath]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-16
    • 2013-03-07
    相关资源
    最近更新 更多