0

I'm using fmdb (https://github.com/ccgus/fmdb) to insert data into sqlite. I'm talking directly to sqlite instead of using Core Data just because I feel it gives me more flexibility in my queries and I'm good at SQL so it's easy for me.

The problem I'm noticing when running in XCode5 using the simulator is when I turn off my Mac and then turn it back on, none of my SQLite data that I inserted is persisted. The tables are empty. I don't have a Apple Device besides my Mac, so as of yet I've been unable to test this on an actual device, so maybe this is just a Simulator thing, and if that's the case I'd be ok with that.

Here's a typical insert for me:

   -(BOOL)insertLocation:(BTRLocation *)location {
NSMutableDictionary *dictionaryArgs = [NSMutableDictionary dictionary];
[dictionaryArgs setObject:location.address forKey:@"columnA"];
[dictionaryArgs setObject:location.name forKey:@"columnB"];

return [self.db executeUpdate:@"insert into locs (columnA, columnB) values (:columnA, :columnB)" withParameterDictionary:dictionaryArgs];

}

It wouldn't appear that anything is wrong with my query because it does work. Even if I kill the app by hitting the Stop button in XCode and then relaunch it, all of the data is persisted. It just doesn't make it through computer shut downs. I find this a little bit weird because NSUserDefaults seem to get persisted through computer shut downs.

Help?

Edit: A bit of extra information I found: It would seem it's not just my data in the tables that don't exist anymore on restart, it's the tables themselves. I always do this on app startup:

  FMResultSet *rs = [self.db executeQuery:@"select DISTINCT tbl_name from sqlite_master where tbl_name = ?", table];
[rs next];
BOOL errors = NO;
if([rs hasAnotherRow]) {
    // table exists - I think -> So here we would do nothing
    NSLog(@"locs table existed");
} else {
    NSLog(@"locs table does not exist");

And it always hits the if (locs table existed) except for the first time starting up the app after a computer restart.

user1513171
  • 1,912
  • 6
  • 32
  • 54

1 Answers1

1

Sounds like you are storing your data in /tmp. You didn't just copy and paste the FMDB sample code without looking at it, did you? :)

ccgus
  • 2,906
  • 23
  • 18
  • No I really do have hundreds of lines of code using fmdb that I wrote myself, however, it's definitely possible I missed something when becoming familiar enough with fmdb that I could use it for my purposes. And yes, I am storing my data in /tmp/myapp_locations.db. Is this not the place I should be? The code in my example code above isn't even in the fmdb sample code to the best of my knowledge.... – user1513171 Oct 15 '14 at 03:51
  • You'll want to store your database either in some sort of document, or in the App Support folder. /tmp is just going to be wiped out when you reboot. – ccgus Oct 15 '14 at 04:27