core: Fix equivalence between variable expressions to be always false

Since until the bind to a value they are treated as NULL. https://sqlite.org/lang_expr.html#varparam
This commit is contained in:
Diego Reis
2025-04-12 16:34:39 -03:00
parent 508df42075
commit 73764e198e

View File

@@ -399,7 +399,9 @@ pub fn exprs_are_equivalent(expr1: &Expr, expr2: &Expr) -> bool {
(Expr::Unary(op1, expr1), Expr::Unary(op2, expr2)) => {
op1 == op2 && exprs_are_equivalent(expr1, expr2)
}
(Expr::Variable(var1), Expr::Variable(var2)) => var1 == var2,
// Variables that are not bound to a specific value, are treated as NULL
// https://sqlite.org/lang_expr.html#varparam
(Expr::Variable(..), Expr::Variable(..)) => false,
(Expr::Parenthesized(exprs1), Expr::Parenthesized(exprs2)) => {
exprs1.len() == exprs2.len()
&& exprs1
@@ -945,6 +947,13 @@ pub mod tests {
assert_eq!(normalize_ident("\"foo\""), "foo");
}
#[test]
fn test_variable_comparison() {
let expr1 = Expr::Variable("?".to_string());
let expr2 = Expr::Variable("?".to_string());
assert!(!exprs_are_equivalent(&expr1, &expr2));
}
#[test]
fn test_basic_addition_exprs_are_equivalent() {
let expr1 = Expr::Binary(