Skip to content

Commit

Permalink
Changed up the behavior of binding empty NSData objects ([NSData data…
Browse files Browse the repository at this point in the history
…]). It will now insert an empty value, rather than a null value- which is consistent with [NSMutableData data] and empty strings (see #73 for a discussion on this).  Thanks to Jens Alfke for pointing this out!
  • Loading branch information
ccgus committed Jun 1, 2012
1 parent 5d87488 commit 8666d8f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES_AND_TODO_LIST.txt
Expand Up @@ -3,6 +3,9 @@ Zip, nada, zilch. Got any ideas?

If you would like to contribute some code- awesome! I just ask that you make it conform to the coding conventions already set in here, and to add a couple of tests for your new code to fmdb.m. And of course, the code should be of general use to more than just a couple of folks. Send your patches to gus@flyingmeat.com.

2012.05.29:
Changed up the behavior of binding empty NSData objects ([NSData data]). It will now insert an empty value, rather than a null value- which is consistent with [NSMutableData data] and empty strings (see https://github.com/ccgus/fmdb/issues/73 for a discussion on this). Thanks to Jens Alfke for pointing this out!

2012.05.25:
Deprecated columnExists:columnName: in favor of columnExists:inTableWithName:
Remembered to update the changes notes. I've been forgetting to do this recently.
Expand Down
8 changes: 7 additions & 1 deletion src/FMDatabase.m
Expand Up @@ -338,7 +338,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]);
Expand Down
12 changes: 12 additions & 0 deletions src/fmdb.m
Expand Up @@ -57,6 +57,18 @@ int main (int argc, const char * argv[]) {
FMDBQuickCheck([err code] == SQLITE_ERROR);
NSLog(@"err: '%@'", err);



// empty strings should still return a value.
FMDBQuickCheck(([db boolForQuery:@"SELECT ? not null", @""]));

// same with empty bits o' mutable data
FMDBQuickCheck(([db boolForQuery:@"SELECT ? not null", [NSMutableData data]]));

// same with empty bits o' data
FMDBQuickCheck(([db boolForQuery:@"SELECT ? not null", [NSData data]]));


// but of course, I don't bother checking the error codes below.
// Bad programmer, no cookie.

Expand Down

0 comments on commit 8666d8f

Please sign in to comment.