fix: remainder operator rhs text

This commit is contained in:
jachewz
2025-04-07 21:45:49 +10:00
parent 3a1b87eb21
commit a72b75e193
2 changed files with 18 additions and 2 deletions

View File

@@ -1001,9 +1001,12 @@ pub fn exec_remainder(lhs: &OwnedValue, rhs: &OwnedValue) -> OwnedValue {
&cast_text_to_numeric(lhs.as_str()), &cast_text_to_numeric(lhs.as_str()),
&cast_text_to_numeric(rhs.as_str()), &cast_text_to_numeric(rhs.as_str()),
), ),
(OwnedValue::Text(text), other) | (other, OwnedValue::Text(text)) => { (OwnedValue::Text(text), other) => {
exec_remainder(&cast_text_to_numeric(text.as_str()), other) exec_remainder(&cast_text_to_numeric(text.as_str()), other)
} }
(other, OwnedValue::Text(text)) => {
exec_remainder(other, &cast_text_to_numeric(text.as_str()))
}
other => todo!("remainder not implemented for: {:?} {:?}", lhs, other), other => todo!("remainder not implemented for: {:?} {:?}", lhs, other),
} }
} }
@@ -1699,7 +1702,7 @@ mod tests {
), ),
( (
OwnedValue::Float(12.0), OwnedValue::Float(12.0),
OwnedValue::Text(Text::from_str("12.0")), OwnedValue::Text(Text::from_str("3.0")),
), ),
]; ];
let outputs = vec![ let outputs = vec![

View File

@@ -1357,6 +1357,19 @@ do_execsql_test mod-agg-float {
SELECT count(*) % 2.43 from users SELECT count(*) % 2.43 from users
} { 0.0 } } { 0.0 }
foreach {testnum lhs rhs ans} {
1 'a' 'a' {}
2 'a' 10 0
3 10 'a' {}
4 'a' 11.0 0.0
5 11.0 'a' {}
7 '10' '3' 1
8 '10.0' '3' 1.0
9 '10.0' -3 1.0
} {
do_execsql_test mod-text-$testnum "SELECT $lhs % $rhs" $::ans
}
do_execsql_test comp-float-float { do_execsql_test comp-float-float {
SELECT 0.0 = 0.0 SELECT 0.0 = 0.0
} { 1 } } { 1 }