Note that there are some explanatory texts on larger screens.

plurals
  1. POIPhone ios 5, recreate database on each simulator run?
    primarykey
    data
    text
    <p>How can i replace the database (with the one i am working on) in my app on each simulator run? (Still adding data and want to check that it looks good)</p> <p>I tried this but it doesn't seem to be working, still using the old database:</p> <pre><code>- (void)viewDidLoad { dbname = @"animaldatabase.sql"; NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [documentPaths objectAtIndex:0]; dbpath = [documentsDir stringByAppendingPathComponent:dbname]; [self checkAndCreateDatabase]; [self readAnimalsFromDatabase]; [super viewDidLoad]; // Do any additional setup after loading the view. mylabel.text = [NSString stringWithFormat:@"%d", [animals count]]; } - (void) checkAndCreateDatabase{ BOOL success; NSFileManager *fileManager = [NSFileManager defaultManager]; success = [fileManager fileExistsAtPath:dbpath]; if (success) { //return; [fileManager removeItemAtPath:dbpath error:nil]; } NSString *dbPathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:dbname]; [fileManager copyItemAtPath:dbPathFromApp toPath:dbpath error:nil]; } </code></pre> <p>Also where is the location for the iphone database? When my app copies the database into the iphone, where does it end up?</p> <p><strong>UPDATE</strong></p> <p>Added the loading code as well.</p> <p>Senthilkumar:</p> <p>I fail to see how this should solve the problem? Doesn't this just skip the copying or my database if it already exists?</p> <p>What i want is to delete the database in my iphone app. Import the new database and then run it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload