diff --git a/lib/src/sql/value/value.rs b/lib/src/sql/value/value.rs index d4742922..7d885cc7 100644 --- a/lib/src/sql/value/value.rs +++ b/lib/src/sql/value/value.rs @@ -2248,7 +2248,10 @@ impl Value { match self { Value::None => other.is_none(), Value::Null => other.is_null(), - Value::Bool(v) => *v, + Value::Bool(v) => match other { + Value::Bool(w) => v == w, + _ => false, + }, Value::Uuid(v) => match other { Value::Uuid(w) => v == w, Value::Regex(w) => w.regex().is_match(v.to_raw().as_str()), diff --git a/lib/tests/select.rs b/lib/tests/select.rs index ba493d9b..07e74118 100644 --- a/lib/tests/select.rs +++ b/lib/tests/select.rs @@ -107,3 +107,96 @@ async fn select_writeable_subqueries() -> Result<(), Error> { // Ok(()) } + +#[tokio::test] +async fn select_where_field_is_bool() -> Result<(), Error> { + let sql = " + CREATE test:1 SET active = false; + CREATE test:2 SET active = false; + CREATE test:3 SET active = true; + SELECT * FROM test WHERE active = false; + SELECT * FROM test WHERE active != true; + SELECT * FROM test WHERE active = true; + "; + + let dbs = Datastore::new("memory").await?; + let ses = Session::for_kv().with_ns("test").with_db("test"); + let res = &mut dbs.execute(&sql, &ses, None, false).await?; + assert_eq!(res.len(), 6); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: test:1, + active: false + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: test:2, + active: false + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: test:3, + active: true + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: test:1, + active: false + }, + { + id: test:2, + active: false + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: test:1, + active: false + }, + { + id: test:2, + active: false + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: test:3, + active: true + } + ]", + ); + assert_eq!(tmp, val); + + Ok(()) +}