I am using the following code to read the rows from the Sqlite3 database.
if(sqlite3_open([[AppHelper getDatabasePath] UTF8String], &database) == SQLITE_OK)
{
const char *sqlStatement = "select * from customers";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{
NSString *firstName = [NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 1)];
NSLog(@"%@",firstName);
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
The code does not go into the if(sqlite3_prepare_v2 ..... condition.
Can anyone tell me what I am doing wrong? I have the .sql file placed in my Documents Directory and it contains one record.
UPDATE 1:
I am running the app in the simulator and I placed my myDatabase.sql file inside the Supporting Files folder.
UPDATE 2:
The error is “No such table customers” but I can see that I have customers table in the database. I used FireFox Sqlite Manager to see the customers table.
The solution was to close/reset the simulator since the simulator was hanging on to the empty database. Once the simulator content was reset everyone started working again!