[英]FMDB databaseWithPath: not writing to disk
The fmdb docs say that if you pass a file system path to databaseWithPath: it will create a file for you: fmdb文档说,如果您将文件系统路径传递给databaseWithPath:,它将为您创建一个文件:
I am getting my file system path with this code: 我正在使用以下代码获取文件系统路径:
[[NSHomeDirectory() stringByAppendingPathComponent:@"Desktop"] stringByAppendingPathComponent:@"file.db"];
And attempting to setup my db like so: 并尝试像这样设置我的数据库:
FMDatabase *aDB = nil;
if (aLanguageDBPath) {
aDB = [FMDatabase databaseWithPath:aLanguageDBPath];
}
The result is a valid FMDatabase object that isn't being written to disk as advertised. 结果是一个有效的FMDatabase对象,没有按公告内容写入磁盘。 Did I misinterpret the explanation in the docs? 我是否误解了文档中的解释? How am I supposed to create and write dbs to disk on the fly? 我应该如何动态创建数据库并将其写入磁盘?
Thanks! 谢谢!
Just found out that the db isn't actually made on disk until [db open];
只是发现直到[db open];
才真正在磁盘上创建[db open];
is called. 叫做。
Try to use the NSDocumentDirectory. 尝试使用NSDocumentDirectory。 Change your path code with this: 以此更改路径代码:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString dbPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"file.db"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.