mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-15 04:54:20 +01:00
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:
11
core/util.rs
11
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(
|
||||
|
||||
Reference in New Issue
Block a user