Permalink
Browse files

Fix issue binding an empty NSData parameter

The object [NSData data] was binding to a SQL 'null', not an empty blob.
See: ccgus#73
  • Loading branch information...
1 parent 0774a8d commit 7000d079c9559a7c7c3cf83c565167a5856cccac @snej snej committed May 29, 2012
Showing with 7 additions and 1 deletion.
  1. +7 −1 src/FMDatabase.m
View
@@ -314,7 +314,13 @@ - (void)bindObject:(id)obj toColumn:(int)idx inStatement:(sqlite3_stmt*)pStmt {
// FIXME - someday check the return codes on these binds.
else if ([obj isKindOfClass:[NSData class]]) {
- sqlite3_bind_blob(pStmt, idx, [obj bytes], (int)[obj length], SQLITE_STATIC);
+ const void* bytes = [obj bytes];
+ if (!bytes) {
+ // it's an empty NSData object, aka [NSData data].
+ // Don't pass a NULL pointer, or sqlite will bind a SQL null instead of a blob!
+ bytes = "";
+ }
+ sqlite3_bind_blob(pStmt, idx, bytes, (int)[obj length], SQLITE_STATIC);
}
else if ([obj isKindOfClass:[NSDate class]]) {
sqlite3_bind_double(pStmt, idx, [obj timeIntervalSince1970]);

0 comments on commit 7000d07

Please sign in to comment.