Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite works on device, but not in simulator. sqlite3_prepare_v2 fails
    text
    copied!<p>I'm having problems with SQLite on the iPhone simulator. I've reduced it to a simple test app. sqlite3_prepare_v2 fails. But the real device works fine. </p> <p>I created a database using sqlite3, and added it to my resources. In my code, in viewDidLoad, I call createEditableCopyOfDatabaseIfNeeded (which is a common, widely-used method, seen everywhere). And then I call the following:-</p> <pre><code>- (void) queryDatabase { sqlite3 *database; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myDatabase.sql"]; if (sqlite3_open([path UTF8String], &amp;database) == SQLITE_OK) { NSMutableString *result = [[NSMutableString alloc] init]; const char *sqlStatement = "select * from people"; sqlite3_stmt *compiledStatement; if (sqlite3_prepare_v2(database, sqlStatement, -1, &amp;compiledStatement, NULL) == SQLITE_OK) { while(sqlite3_step(compiledStatement) == SQLITE_ROW) { NSString *firstname = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]; NSString *surname = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)]; [result appendFormat:@"%@ %@\n", firstname, surname]; } [resultView setText:result]; } else { [resultView setText:@"Problem querying database"]; } sqlite3_finalize(compiledStatement); [result release]; } sqlite3_close(database); } </code></pre> <p>On the simulator, sqlite3_prepare_v2 doesn't return SQLITE_OK</p>
 

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