4

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 
user8472
  • 3,268
  • 3
  • 35
  • 62
kunalg
  • 1,570
  • 1
  • 12
  • 18
  • based on your provided output it doesn't look as if it's entering the else case at all - in both iOS5 and iOS6 we see both log messages. – TomSwift Oct 16 '12 at 18:23
  • See this answer, you might have the same problem: http://stackoverflow.com/a/6749033/73429 – Dave Lee Oct 16 '12 at 23:32

3 Answers3

2

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));
}
Lefteris
  • 14,550
  • 2
  • 56
  • 95
1

Try to delete your app from your device (Or simulator) then clean & build

Solidus
  • 251
  • 2
  • 10
0

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...

donjordano
  • 346
  • 3
  • 12