• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 使用firefox插件创建时如何打开.sqlite文件

[复制链接]
菜鸟教程小白 发表于 2022-12-12 10:04:27 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我创建了我的表并使用 firefox sqlite manager 扩展插入了我的数据,保存并添加了我的 sqlitefile,它是“notifications.sqlite”,之后我编写了这段代码,但它会输出我nothing

打开 .sqlite 文件和打开 .db 文件有什么区别吗?如何正确打开我的数据库?

*更新:*根据 friend 的评论调试后,这行有问题:

databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"notifications.sqlite"]];

之后

  if ([filemgr fileExistsAtPath: databasePath ] == YES)

if 不是 YES,所以它将丢失所有内容,因此 databasePath 有点错误

我的表格如下:

CREATE TABLE "quotes_type" ("type_id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , "content" VARCHAR)

这是我打开 .sqlite 文件的努力:

- (void)viewDidLoad{

  NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *docsDir = [dirPaths objectAtIndex:0];
    databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"notifications.sqlite"]];
    sqlite3_stmt *statement;
    NSFileManager *filemgr = [NSFileManager defaultManager];
    if ([filemgr fileExistsAtPath: databasePath ] == YES)
    {
    if (sqlite3_open([databasePath UTF8String], &contactDB) == SQLITE_OK)
    {

        NSString *qrycount = [NSString stringWithFormat: @"select * from quotes_type"];

        const char *count_stmt = [qrycount UTF8String];

        sqlite3_prepare_v2(contactDB, count_stmt, -1, &statement, NULL);
        if (sqlite3_step(statement) == SQLITE_ERROR) {
            NSAssert1(0,@"Error when selecting rows  %s",sqlite3_errmsg(contactDB));
        } else {
              NSLog(@"negin");
            int myid=sqlite3_column_int(statement, 0);
            NSString *text = [NSString stringWithUTF8Stringchar *)sqlite3_column_text(statement,1)];
            NSLog(@"myid is %d",myid);
            NSLog(@"text is %@",text);
            sqlite3_finalize(statement);
            sqlite3_close(contactDB);
        }
    }
    else NSLog(@"openning has problem");
    }
}



Best Answer-推荐答案


您正在检查 Documents 中的数据库。但是你曾经在那里复制过吗?如果没有,你永远不会在那里找到它。您确实想检查该文件,如果找不到,请将其从 bundle 复制到 Documents 文件夹。因此,如果您在 Documents 中找不到该数据库,则应通过以下方式复制它:

NSError *error;
NSString *bundleDatabasePath = [[NSBundle mainBundle] pathForResource"notifications" ofType"sqlite"];
NSAssert(bundleDatabasePath, @"database not found in bundle");
if (![filemgr copyItemAtPath:bundleDatabasePath toPath:databasePath error:&error])
    NSLog(@"%s: copyItemAtPath failure: error = %@", __FUNCTION__, error); 

关于ios - 使用firefox插件创建时如何打开.sqlite文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15863488/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap