Skip to content

Commit

Permalink
Merge 'implement isnull / not null for filter expressions' from Glaub…
Browse files Browse the repository at this point in the history
…er Costa

Allow us to write queries like:
        SELECT name, type, sql FROM sqlite_schema where sql isnull
and
        SELECT name, type, sql FROM sqlite_schema where sql not null

Reviewed-by: Jussi Saurio <[email protected]>

Closes #829
  • Loading branch information
penberg committed Jan 30, 2025
2 parents a2ac313 + effde1c commit 5614a77
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/translate/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,22 @@ pub fn translate_condition_expr(
);
}
}
ast::Expr::NotNull(expr) => {
let cur_reg = program.alloc_register();
translate_expr(program, Some(referenced_tables), expr, cur_reg, resolver)?;
program.emit_insn(Insn::IsNull {
src: cur_reg,
target_pc: condition_metadata.jump_target_when_false,
});
}
ast::Expr::IsNull(expr) => {
let cur_reg = program.alloc_register();
translate_expr(program, Some(referenced_tables), expr, cur_reg, resolver)?;
program.emit_insn(Insn::NotNull {
reg: cur_reg,
target_pc: condition_metadata.jump_target_when_false,
});
}
_ => todo!("op {:?} not implemented", expr),
}
Ok(())
Expand Down
8 changes: 8 additions & 0 deletions testing/where.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ do_execsql_test where-clause-eq-string {
select count(1) from users where last_name = 'Rodriguez';
} {61}

do_execsql_test where-clause-isnull {
select count(1) from users where last_name isnull;
} {0}

do_execsql_test where-clause-notnull {
select count(1) from users where last_name not null;
} {10000}

do_execsql_test where-clause-ne {
select count(1) from users where id != 2000;
} {9999}
Expand Down

0 comments on commit 5614a77

Please sign in to comment.