ccgus/fmdb — Issue #50: executeUpdateWithFormat: with %s and nil fails
Author: bunkenburg
Created: 2012-03-08 11:40:05+00:00
State: open

When using executeUpdateWithFormat with %s and a char* that's actually nil, the method fails. I would have thought it should insert NULL.

NSString* sql = @"CREATE TABLE Test (name TEXT);";
BOOL ok = [db executeUpdate:sql];

NSString* s = nil;
const char* cs = [s UTF8String];
sql = @"INSERT INTO Test (name) VALUES (%s)";
ok = [db executeUpdateWithFormat:sql, cs];

Observed:

2012-03-08 12:33:46.887 tpq[3592:fb03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithUTF8String:]: NULL cString'

Expected:

Insert NULL in DB.

Thanks for making this great small library!