ios - how to get NULL from sqlite in xcode -


i want 1 application has sqlite db. in sqlite db exist 5 records record has 2 column. (name,id,key) 1 of id null , want this. (id integer variable)

this code when run application crashed.

do         {             sqlite3 *database2;             if(sqlite3_open([[self datafilepath] utf8string], &database2) == sqlite_ok)             {                             nsstring *sqlstatement_userinfo2 =[nsstring stringwithformat:@"select * table1 name = %@ , id = %@",p,p2];                 sqlite3_stmt *compiledstatement2;                 if(sqlite3_prepare_v2(database2, [sqlstatement_userinfo2 utf8string], -1, &compiledstatement2, null) == sqlite_ok)                 {                 // loop through results , add them feeds array                     while(sqlite3_step(compiledstatement2) == sqlite_row)                     {                         nsmutabledictionary *_datadictionary=[[nsmutabledictionary alloc] init];                         // init data dictionary                         childid = [nsstring stringwithutf8string:(char *)sqlite3_column_text(compiledstatement2, 1)];                         childname = [nsstring stringwithutf8string:(char *)sqlite3_column_text(compiledstatement2, 0)];                         b = [nsstring stringwithutf8string:(char *)sqlite3_column_text(compiledstatement2, 2) ];                         p = childid;                         p2 = b;                         [_datadictionary setobject:[nsstring stringwithformat:@"%@",childname] forkey:@"name"];                         [array addobject:_datadictionary];                     }                 }              else             {                 nslog(@"no data found");             }                  // release compiled statement memory                 sqlite3_finalize(compiledstatement2);              }                 sqlite3_close(database2);          } while (b != null); 

this code not work , error :

*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '*** +[nsstring stringwithutf8string:]: null cstring' *** first throw call stack: (0x2092012 0x119fe7e 0x2091deb 0xb97480 0x35b7 0x2e08 0x1c8817 0x1c8882 0x1c8b2a 0x1dfef5 0x1dffdb 0x1e0286 0x1e0381 0x1e0eab 0x1e0fc9 0x1e1055 0x2e63ab 0x13792d 0x11b36b0 0x268efc0 0x268333c 0x268eeaf 0x1d68cd 0x11f1a6 0x11dcbf 0x11dbd9 0x11ce34 0x11cc6e 0x11da29 0x120922 0x1cafec 0x117bc4 0x117dbf 0x117f55 0x120f67 0xe4fcc 0xe5fab 0xf7315 0xf824b 0xe9cf8 0x1feddf9 0x1fedad0 0x2007bf5 0x2007962 0x2038bb6 0x2037f44 0x2037e1b 0xe57da 0xe765c 0x2b6d 0x2a95) libc++abi.dylib: terminate called throwing exception (lldb)  

you need add check whether sqlite3_column_text(compiledstatement2, 1) returns null byte before try create nsstring it.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -