Failed to get data from SQLite iOS6.0 database

When I run build ios5.0 or less, then the Sqlite answer is correct and retrieves the data, it works fine, but when I run on ios6.0 I try to retrieve the data from my.sqlite database, but it does not fulfill my if case. He always enters into another condition. What am I doing wrong? I can not execute my if if, i.e. if(sqlite3_prepare_v2(database, sqlQuerry, -1, &querryStatement, NULL)==SQLITE_OK).

check this code for reference.

 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 { } 

In iOS6.0 Print Magazine

  sqlite3_prepare_v2 = 1 SQLITE_OK 0 sqlite3_step = 21 SQLITE_ROW 100 

In iOS5.0 Print Magazine

 sqlite3_prepare_v2 = 0 SQLITE_OK 0 sqlite3_step = 100 SQLITE_ROW 100 
+4
source share
3 answers

Put this in else so that we can see the error that occurs.

 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)); } 
+2
source

Try uninstalling the application from your device (or simulator), then clean and build

+1
source

I'm not 100% sure, but regarding this: NULL - void * , nil - id

So, if you can change this:

 if(sqlite3_prepare_v2(sqlite, [strQuery UTF8String], -1, &compiledStatement, nil)==SQLITE_OK) 

Take this away:

 if(sqlite3_prepare_v2(sqlite, [strQuery UTF8String], -1, &compiledStatement, NULL)==SQLITE_OK) 

I just change null using NULL. Again, I’m not 100% sure, but only this I see in your code. I always use NULL :)

Hope this help ...

0
source

Source: https://habr.com/ru/post/1436933/


All Articles