From 9a4864bc6a55dec4e6ee9a2576246a3122b126e1 Mon Sep 17 00:00:00 2001 From: jussisaurio Date: Sun, 17 Nov 2024 18:36:30 +0200 Subject: [PATCH] support parenthesized(single expr) in translate_expr() --- core/translate/expr.rs | 23 ++++++++++++++++++++++- core/vdbe/mod.rs | 4 ++++ testing/select.test | 4 ++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/core/translate/expr.rs b/core/translate/expr.rs index b0b29bc17..c443b1e9f 100644 --- a/core/translate/expr.rs +++ b/core/translate/expr.rs @@ -536,6 +536,8 @@ pub fn translate_condition_expr( } } ast::Expr::Parenthesized(exprs) => { + // TODO: this is probably not correct; multiple expressions in a parenthesized expression + // are reserved for special cases like `(a, b) IN ((1, 2), (3, 4))`. for expr in exprs { let _ = translate_condition_expr( program, @@ -1470,7 +1472,26 @@ pub fn translate_expr( }, ast::Expr::Name(_) => todo!(), ast::Expr::NotNull(_) => todo!(), - ast::Expr::Parenthesized(_) => todo!(), + ast::Expr::Parenthesized(exprs) => { + if exprs.is_empty() { + crate::bail_parse_error!("parenthesized expression with no arguments"); + } + if exprs.len() == 1 { + translate_expr( + program, + referenced_tables, + &exprs[0], + target_register, + cursor_hint, + cached_results, + )?; + } else { + // Parenthesized expressions with multiple arguments are reserved for special cases + // like `(a, b) IN ((1, 2), (3, 4))`. + todo!("TODO: parenthesized expression with multiple arguments not yet supported"); + } + Ok(target_register) + } ast::Expr::Qualified(tbl, ident) => { let (idx, col_type, cursor_id, is_primary_key) = resolve_ident_qualified( program, diff --git a/core/vdbe/mod.rs b/core/vdbe/mod.rs index 322165147..abbb49e91 100644 --- a/core/vdbe/mod.rs +++ b/core/vdbe/mod.rs @@ -583,6 +583,10 @@ impl Program { (OwnedValue::Float(lhs), OwnedValue::Float(rhs)) => { state.registers[dest] = OwnedValue::Float(lhs + rhs); } + (OwnedValue::Float(f), OwnedValue::Integer(i)) + | (OwnedValue::Integer(i), OwnedValue::Float(f)) => { + state.registers[dest] = OwnedValue::Float(*f + *i as f64); + } (OwnedValue::Null, _) | (_, OwnedValue::Null) => { state.registers[dest] = OwnedValue::Null; } diff --git a/testing/select.test b/testing/select.test index d69f3c07e..8cf247d8b 100755 --- a/testing/select.test +++ b/testing/select.test @@ -50,3 +50,7 @@ do_execsql_test table-star-2 { do_execsql_test seekrowid { select * from users u where u.id = 5; } {"5|Edward|Miller|christiankramer@example.com|725-281-1033|08522 English Plain|Lake Keith|ID|23283|15"} + +do_execsql_test select_parenthesized { + select (price + 100) from products limit 1; +} {179.0} \ No newline at end of file