Inserting nil Values into Sqlite Database?

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-04-06T17:49:27Z Indexed on 2010/04/06 17:53 UTC
Read the original article Hit count: 316

Filed under:
|
|
|

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);

© Stack Overflow or respective owner

Related posts about iphone

Related posts about sqlite