mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-09 10:14:21 +01:00
Fix Unary Negate Operation on Blobs
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user