NSInvalidArgumentException in selected data from sqlite file

I save the data in the following format

             05/03/2012 10:11PM : <0818aaaa aaaaaaaa aaaa454d 554c4154 4f520000 00000000 0000>

but when retrieving data i get the following method

    sqlite3 *database;

if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {

    // Setup the SQL Statement and compile it for faster access
    const char *sqlStatement = "select logText from logTable";

    sqlite3_stmt *compiledStatement;


    if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {



        while(sqlite3_step(compiledStatement) == SQLITE_ROW) {              

            NSString *addressField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(compiledStatement, 0)];

            // Read the data from the result row

            fullLog=[NSString stringWithFormat:@"%@%@",fullLog,addressField];

        } // end of the while

    }
    sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);

I get a follwing error,

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithUTF8String:]: NULL cString'

* Call stack on first throw:

please help why thia problem occurs

+3
source share
2 answers

You cannot initialize objects with a NSStringpointer NULL, so just check this condition:

const char* addressField_tmp = (const char*)sqlite3_column_text(compiledStatement, 0);

NSString *addressField = addressField_tmp == NULL ? nil : [[NSString alloc]           initWithUTF8String:addressField_tmp];
+4
source

Instead of codes, please correct it with the following codes.

  NSString *addressField = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
0
source

All Articles