Unable to retrieve data from SQLite database iOS6.0
-
11-12-2019 - |
Question
When i run build ios5.0 or less then Sqlite response correct and retrieve data its work fine but when run on ios6.0 i am trying to fetch data from my.sqlite database but it is not executing my if case. It always enters in else condition. What wrong thing i am doing? I am not able to execute my if case i.e. if(sqlite3_prepare_v2(database, sqlQuerry, -1, &querryStatement, NULL)==SQLITE_OK).
for reference check this code .
NSLog(@"sqlite3_prepare_v2 = %d SQLITE_OK %d ",sqlite3_prepare_v2(sqlite, [strQuery UTF8String], -1, &compiledStatement, nil),SQLITE_OK);
if(sqlite3_prepare_v2(sqlite, [strQuery UTF8String], -1, &compiledStatement, nil)==SQLITE_OK)
{
NSLog(@"sqlite3_step = %d SQLITE_ROW %d ",sqlite3_step(compiledStatement),SQLITE_ROW);
while (sqlite3_step(compiledStatement)==SQLITE_ROW)
{ if(sqlite3_column_text(compiledStatement, 2) != nil)
modelObj.Name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
}
}
else
{
}
On iOS6.0 log Print
sqlite3_prepare_v2 = 1 SQLITE_OK 0
sqlite3_step = 21 SQLITE_ROW 100
On iOS5.0 log Print
sqlite3_prepare_v2 = 0 SQLITE_OK 0
sqlite3_step = 100 SQLITE_ROW 100
Solution
Place in the else this, so we can see the error that is resulting..
if(sqlite3_prepare_v2(sqlite, [strQuery UTF8String], -1, &compiledStatement, nil)==SQLITE_OK)
{
NSLog(@"sqlite3_step = %d SQLITE_ROW %d ",sqlite3_step(compiledStatement),SQLITE_ROW);
while (sqlite3_step(compiledStatement)==SQLITE_ROW)
{ if(sqlite3_column_text(compiledStatement, 2) != nil)
modelObj.Name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
}
}
else{
//error
NSLog(@"Failed to open database. Error: %s",sqlite3_errmsg(database));
}
OTHER TIPS
Try to delete your app from your device (Or simulator) then clean & build
I'm not 100% sure but regarding this: NULL is a void *, nil is an id
So if you can change this:
if(sqlite3_prepare_v2(sqlite, [strQuery UTF8String], -1, &compiledStatement, nil)==SQLITE_OK)
Whit this:
if(sqlite3_prepare_v2(sqlite, [strQuery UTF8String], -1, &compiledStatement, NULL)==SQLITE_OK)
I just change nil with NULL. Again not 100% sure but only this I see in your code. I always use NULL :)
Hope this help...