From 73764e198e8dafef9e7f55ca2d26c704755143e2 Mon Sep 17 00:00:00 2001 From: Diego Reis Date: Sat, 12 Apr 2025 16:34:39 -0300 Subject: [PATCH] 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 --- core/util.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/util.rs b/core/util.rs index 3d12a2c6e..aa13e2edc 100644 --- a/core/util.rs +++ b/core/util.rs @@ -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(