简体   繁体   中英

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:

  1. A file system path. The file does not have to exist on disk. If it does not exist, it is created for you.

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. 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]; is called.

Try to use the NSDocumentDirectory. Change your path code with this:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                     NSUserDomainMask,
                                                     YES);
NSString dbPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"file.db"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM