Skip to content

Commit

Permalink
CBL-6626: SQL++ query not return expected results (#2209)
Browse files Browse the repository at this point in the history
  • Loading branch information
callumbirks committed Jan 31, 2025
1 parent 95cb359 commit 868b2b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions LiteCore/Query/SQLiteFleeceFunctions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,10 @@ namespace litecore {
{
switch ( sqlite3_value_subtype(arg) ) {
case 0:
// Untagged blob is already Fleece data
break;
if ( sqlite3_value_bytes(arg) > 0 ) {
// Untagged blob with size is already Fleece data
break;
} // Untagged blob with 0 size is null, so fall through into the Null case.
case kFleeceNullSubtype:
{
// A tagged Fleece/JSON null:
Expand Down
4 changes: 3 additions & 1 deletion LiteCore/Query/SQLiteN1QLFunctions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ namespace litecore {

// Test for N1QL NULL value (which is an empty blob tagged with kFleeceNullSubtype)
static inline bool isNull(sqlite3_value* arg) {
return sqlite3_value_type(arg) == SQLITE_BLOB && sqlite3_value_subtype(arg) == kFleeceNullSubtype;
if ( sqlite3_value_type(arg) != SQLITE_BLOB ) return false;
auto subtype = sqlite3_value_subtype(arg);
return subtype == kFleeceNullSubtype || (subtype == 0 && sqlite3_value_bytes(arg) == 0);
}

static sqlite3_value* passMissingOrNull(int argc, sqlite3_value** argv) {
Expand Down

0 comments on commit 868b2b6

Please sign in to comment.