I'm using XCode 6.4 and iOS Si,mulator iPhone 6. Every run of my app database or table is recreated so i lost all previously inserted data. I have 1 database with 1 table inside. Database file is located in Supporing Files directory of the project. Here is the code for database initialization:
BOOL success;
NSString *databasePath = [[NSBundle mainBundle] pathForResource:@"signals" ofType:@"sql"];
NSFileManager *fileManager = [NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:databasePath];
if (success) {
NSLog(@"exists");
return;
} else {
NSLog(@"No file found");
[fileManager copyItemAtPath:databasePath toPath:databasePath error:nil];
}
On run - success variable is YES - so i see in logs "exists". After that i insert one item to my table and do select query that returns this one inserted raw. On next run i should see two rows, but there is only one row again - so i assume the table was recreated. I need help with this problem.
Not got enough reputations to comment, but if you're not getting any No file found messages in your log, then I don't think this is the block of code that is causing the problem. Are you definitely doing an Insert query into the database and not an Update? Also, is your Select query returning all rows and not just one. Are you running through XCode or directly in the Simulator? XCode might overwrite the files if you're running it just through there - try re-running the app in the Simulator (CMD + Shift + H to get to the home screen), and seeing if that makes any difference.