【问题标题】:Where does sqlite file get stored on Mac?sqlite 文件在 Mac 上存储在哪里?
【发布时间】:2015-01-08 06:31:55
【问题描述】:

我已经在我的 Xcode 6.6.1 应用程序中链接了 libsqlite3.dylib。我没有使用核心数据,我使用的是 FMDB。在哪里可以找到我的应用运行时创建的 .db 或 .sqlite 文件?

我对使用 Mac 很陌生,但我相信我使用 Finder 在我的机器上到处搜索,但找不到任何 *.db 或 *.sqlite 文件。当我运行应用程序时,它会在两次执行之间保留数据,所以我知道它会保存在某个地方……但是在哪里?

【问题讨论】:

  • 检查你的iphone模拟器的文档目录
  • 代码中的简单日志语句会显示路径。

标签: ios sqlite swift


【解决方案1】:

首先获取 SQLite 的路径,如下代码。

-(NSString*)getDBPath
{
    NSArray *path =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentdirectory = [path objectAtIndex:0];
    return [documentdirectory stringByAppendingPathComponent:@"wordDatabase.sqlite"];
}

-(void)copyDatabaseIfNeeded{
    NSFileManager *filemanager = [NSFileManager defaultManager];
    NSError *error;
    NSString *DBPath = [self getDBPath];

    NSLog(@"Path == %@",DBPath);

    BOOL success = [filemanager fileExistsAtPath:DBPath];
    if (!success) {
        NSString *defaultDBPath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"wordDatabase.sqlite"];
        success = [filemanager copyItemAtPath:defaultDBPath toPath:DBPath error:&error];
        if (!success) {
            NSLog(@"Error in creating database");
        }
    }
}

YourParh: /Users/mspsys087/Library/Developer/CoreSimulator/Devices/AAECF3F8-1EFD-46D6-8B45-08A6BCE7A002/data/Documents/wordDatabase.sqlite

现在转到查找器:

并在 GO 中粘贴您的路径:

点击 GO,然后点击它显示你的数据库的位置。

【讨论】:

  • 这太好了,谢谢...但是不应该在我的整个机器上搜索 *.sqlite 仍然找到它吗?如果不是,为什么?
  • 我爱你...对于 xamarin Mac 生成 sqlite db 路径使用: var dbPath = Path.Combine(NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true)[0], "数据库.db3");
猜你喜欢
  • 2011-09-04
  • 1970-01-01
  • 2017-10-24
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
  • 2018-10-04
  • 2010-11-15
相关资源
最近更新 更多