0

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!

Westley
  • 1,143
  • 14
  • 27

2 Answers2

1

Just found out that the db isn't actually made on disk until [db open]; is called.

Westley
  • 1,143
  • 14
  • 27
0

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"];
David Pollak
  • 60
  • 1
  • 10
  • Had tried that already. Still no luck. I get the db object in memory fine but I can't write it to disk. – Westley Mar 24 '13 at 15:07