Note that there are some explanatory texts on larger screens.

plurals
  1. POPull Database from Documents Directory
    primarykey
    data
    text
    <p>I have been using the following code to pull an sqlite DB from the Supporting Files in my app. This has worked fine with no problems.</p> <pre><code>NSFileManager *fileMgr = [NSFileManager defaultManager]; NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"TulsaListBars.sqlite"]; BOOL success = [fileMgr fileExistsAtPath:dbPath]; if(!success) { NSLog(@"Cannot locate database file '%@'.", dbPath); }else{ NSLog(@"File Exists: %@", dbPath); } if(!(sqlite3_open([dbPath UTF8String], &amp;db) == SQLITE_OK)) { NSLog(@"An error has occured: %s", sqlite3_errmsg(db)); } const char *sql = "SELECT * FROM Locations WHERE bar = 'yes'"; sqlite3_stmt *sqlStatement; if(sqlite3_prepare(db, sql, -1, &amp;sqlStatement, NULL) != SQLITE_OK) { NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(db)); } </code></pre> <p>I have no removed the DB from the Supporting Files and put in on a server. I'm using the following code to pull the DB from the server into my Documents Directory. I have verified the file is coming over to the Documents Directory and is accurate with all tables. However, I'm now getting an error 'Problem with prepare statement: no such table: Locations'</p> <pre><code>NSURL *url = [NSURL URLWithString:@"my web site/TulsaListBars.sqlite"]; NSData *data = [NSData dataWithContentsOfURL:url]; NSString *appDocDir = [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) lastObject]; NSString *storePath = [appDocDir stringByAppendingPathComponent:@"TulsaListBars.sqlite"]; [data writeToFile:storePath atomically:TRUE]; </code></pre> <p>Is this an issue with the DB being in my Documents Directory now instead of the Supporting Files?</p> <p>Update: I have restarted and reset the simulator and now it appears the DB is not being loaded into the Documents Directory. Any help would be appreciated.</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.
    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