Fix Unary Negate Operation on Blobs

This commit is contained in:
pedrocarlo
2025-04-13 19:17:34 -03:00
parent e07a6fc5c0
commit e1ddf5ffcc
3 changed files with 22 additions and 3 deletions

View File

@@ -1964,7 +1964,7 @@ pub fn translate_expr(
Ok(target_register)
}
(UnaryOperator::Negative, _) => {
let value = -1;
let value = 0;
let reg = program.alloc_register();
translate_expr(program, referenced_tables, expr, reg, resolver)?;
@@ -1974,7 +1974,7 @@ pub fn translate_expr(
dest: zero_reg,
});
program.mark_last_insn_constant();
program.emit_insn(Insn::Multiply {
program.emit_insn(Insn::Subtract {
lhs: zero_reg,
rhs: reg,
dest: target_register,

View File

@@ -5379,7 +5379,14 @@ pub fn exec_subtract(lhs: &OwnedValue, rhs: &OwnedValue) -> OwnedValue {
(other, OwnedValue::Text(text)) => {
exec_subtract(other, &cast_text_to_numeric(text.as_str()))
}
_ => todo!(),
(other, OwnedValue::Blob(blob)) => {
let text = String::from_utf8_lossy(&blob);
exec_subtract(other, &cast_text_to_numeric(&text))
}
(OwnedValue::Blob(blob), other) => {
let text = String::from_utf8_lossy(&blob);
exec_subtract(&cast_text_to_numeric(&text), other)
}
};
match result {
OwnedValue::Float(f) if f.is_nan() => OwnedValue::Null,

View File

@@ -95,6 +95,18 @@ do_execsql_test subtract-agg-float-agg-int {
SELECT sum(3.5) - sum(1)
} {2.5}
do_execsql_test subtract-blob {
SELECT -x'11'
} {0}
do_execsql_test subtract-blob-empty {
SELECT -x''
} {0}
do_execsql_test subtract-blob-charcter {
SELECT -'hi';
} {0}
foreach {testnum lhs rhs ans} {
1 'a' 'a' 0
2 'a' 10 -10