From 0d5cbc4f1d25589f9db24a3a4320b96e27f8a59b Mon Sep 17 00:00:00 2001 From: Krishna Vishal Date: Sun, 8 Jun 2025 22:00:48 +0530 Subject: [PATCH] Add affinity check as a function as `ast::Operator` impl --- core/translate/expr.rs | 13 ++----------- vendored/sqlite3-parser/src/parser/ast/mod.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/core/translate/expr.rs b/core/translate/expr.rs index 5d081d2a9..c1beb32d2 100644 --- a/core/translate/expr.rs +++ b/core/translate/expr.rs @@ -2224,19 +2224,10 @@ fn emit_binary_insn( referenced_tables: Option<&TableReferences>, ) -> Result<()> { let mut affinity = Affinity::Blob; - if matches!( - op, - ast::Operator::Equals - | ast::Operator::NotEquals - | ast::Operator::Less - | ast::Operator::LessEquals - | ast::Operator::Greater - | ast::Operator::GreaterEquals - | ast::Operator::Is - | ast::Operator::IsNot - ) { + if op.is_comparison() { affinity = comparison_affinity(lhs_expr, rhs_expr, referenced_tables); } + match op { ast::Operator::NotEquals => { let if_true_label = program.allocate_label(); diff --git a/vendored/sqlite3-parser/src/parser/ast/mod.rs b/vendored/sqlite3-parser/src/parser/ast/mod.rs index 7512b75d5..6d92c07ba 100644 --- a/vendored/sqlite3-parser/src/parser/ast/mod.rs +++ b/vendored/sqlite3-parser/src/parser/ast/mod.rs @@ -731,6 +731,21 @@ impl Operator { | Operator::NotEquals ) } + + /// Returns true if this operator is a comparison operator that may need affinity conversion + pub fn is_comparison(&self) -> bool { + matches!( + self, + Self::Equals + | Self::NotEquals + | Self::Less + | Self::LessEquals + | Self::Greater + | Self::GreaterEquals + | Self::Is + | Self::IsNot + ) + } } /// Unary operators