mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-16 05:24:22 +01:00
Merge 'Fix SELECT 0.0 = 0 returning false' from lgualtieri75
Fixes #1155 Closes #1158
This commit is contained in:
@@ -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<OwnedValue> 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<OwnedValue> for OwnedValue {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
|
||||
32
testing/math.test
Normal file → Executable file
32
testing/math.test
Normal file → Executable file
@@ -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 }
|
||||
Reference in New Issue
Block a user