From a9ad5a56b94dc5ede8a6c999fab7e1d7fe58ef1d Mon Sep 17 00:00:00 2001 From: "l.gualtieri" Date: Sun, 23 Mar 2025 12:24:23 +0100 Subject: [PATCH] fix bug #1155 --- core/types.rs | 32 +++++++++++++++++++++++++++++++- testing/math.test | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) mode change 100644 => 100755 testing/math.test diff --git a/core/types.rs b/core/types.rs index 593c99efd..9295b80d1 100644 --- a/core/types.rs +++ b/core/types.rs @@ -61,7 +61,7 @@ impl Text { } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] pub enum OwnedValue { Null, Integer(i64), @@ -249,6 +249,36 @@ impl AggContext { } } +impl PartialEq for OwnedValue { + fn eq(&self, other: &OwnedValue) -> bool { + match (self, other) { + (Self::Integer(int_left), Self::Integer(int_right)) => int_left == int_right, + (Self::Integer(int_left), Self::Float(float_right)) => { + (*int_left as f64) == (*float_right) + } + (Self::Float(float_left), Self::Integer(int_right)) => { + float_left == (&(*int_right as f64)) + } + (Self::Float(float_left), Self::Float(float_right)) => float_left == float_right, + (Self::Integer(_) | Self::Float(_), Self::Text(_) | Self::Blob(_)) => false, + (Self::Text(_) | Self::Blob(_), Self::Integer(_) | Self::Float(_)) => false, + (Self::Text(text_left), Self::Text(text_right)) => { + text_left.value.eq(&text_right.value) + } + (Self::Blob(blob_left), Self::Blob(blob_right)) => blob_left.eq(blob_right), + (Self::Null, Self::Null) => true, + (Self::Agg(a), Self::Agg(b)) => a.eq(b), + (Self::Agg(a), other) => a.final_value().eq(other), + (other, Self::Agg(b)) => other.eq(b.final_value()), + _ => false, + } + } + + fn ne(&self, other: &OwnedValue) -> bool { + !self.eq(other) + } +} + #[allow(clippy::non_canonical_partial_ord_impl)] impl PartialOrd for OwnedValue { fn partial_cmp(&self, other: &Self) -> Option { diff --git a/testing/math.test b/testing/math.test old mode 100644 new mode 100755 index 5774be932..847f94f9a --- a/testing/math.test +++ b/testing/math.test @@ -1352,3 +1352,35 @@ do_execsql_test mod-agg-int { do_execsql_test mod-agg-float { SELECT count(*) % 2.43 from users } { 0.0 } + +do_execsql_test comp-float-float { + SELECT 0.0 = 0.0 +} { 1 } + +do_execsql_test comp-int-float { + SELECT 0 = 0.0 +} { 1 } + +do_execsql_test comp-float-int { + SELECT 0.0 = 0 +} { 1 } + +do_execsql_test comp-int-string { + SELECT 0 = '0' +} { 0 } + +do_execsql_test comp-string-int { + SELECT '0' = 0 +} { 0 } + +do_execsql_test comp-string-blog { + SELECT '0' = cast('0' as BLOB) +} { 0 } + +do_execsql_test comp-blog-string { + SELECT cast('0' as BLOB) = '0' +} { 0 } + +do_execsql_test comp-blog-blog { + SELECT cast('0' as BLOB) = cast('0' as BLOB) +} { 1 } \ No newline at end of file