简体   繁体   中英

Unable to retrieve data from SQLite database iOS6.0

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

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));
}

尝试从您的设备(或模拟器)中删除您的应用程序,然后清理和构建

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM