views:

66

answers:

1

I am working on an iPhone App where I am pulling data from an XML file and inserting it into a sqlite database located in the App. I am able to successfully do this process, but it appears that if I try to sqlite3_bind_text with a NSString that has a value of "nil", the App quickly dies.

This is an example of code that fails: (modified for this example)

// idvar = 1
// valuevar = nil

const char *sqlStatement = "insert into mytable (id, value) VALUES(?, ?)";
sqlite3_stmt *compiledStatement = nil;  
sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL);

sqlite3_bind_int(compiledStatement, 1, [idvar intValue]);;
sqlite3_bind_text(compiledStatement, 2, [valuevar UTF8String], -1, SQLITE_TRANSIENT);
A: 

Have you tried something like:

sqlite3_bind_text(compiledStatement, 2, valuevar==nil?"":[valuevar UTF8String], -1, SQLITE_TRANSIENT);
Glenn Howes
That's the ticket
Chris