From 92e9f17ade330591a71aeb51fdeb01d83a8ac80b Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 17 May 2021 18:00:17 +0100 Subject: [PATCH] Add exactly equal operator (==) --- src/fnc/operate.rs | 4 ++++ src/sql/expression.rs | 1 + src/sql/operator.rs | 3 +++ 3 files changed, 8 insertions(+) diff --git a/src/fnc/operate.rs b/src/fnc/operate.rs index 4256af22..7cdc3c2d 100644 --- a/src/fnc/operate.rs +++ b/src/fnc/operate.rs @@ -42,6 +42,10 @@ pub fn div(a: &Literal, b: &Literal) -> Result { Ok(Literal::from(a / b)) } +pub fn exact(a: &Literal, b: &Literal) -> Result { + Ok(Literal::from(a == b)) +} + pub fn equal(a: &Literal, b: &Literal) -> Result { match a { Literal::None => Ok(Literal::from(b.is_none() == true)), diff --git a/src/sql/expression.rs b/src/sql/expression.rs index 881d34be..352791ed 100644 --- a/src/sql/expression.rs +++ b/src/sql/expression.rs @@ -77,6 +77,7 @@ impl dbs::Process for Expression { Operator::Mul => fnc::operate::mul(&l, &r), Operator::Div => fnc::operate::div(&l, &r), Operator::Equal => fnc::operate::equal(&l, &r), + Operator::Exact => fnc::operate::exact(&l, &r), Operator::NotEqual => fnc::operate::not_equal(&l, &r), Operator::AllEqual => fnc::operate::all_equal(&l, &r), Operator::AnyEqual => fnc::operate::any_equal(&l, &r), diff --git a/src/sql/operator.rs b/src/sql/operator.rs index 53dd40f3..3116ca6f 100644 --- a/src/sql/operator.rs +++ b/src/sql/operator.rs @@ -19,6 +19,7 @@ pub enum Operator { Dec, // -= // Equal, // = + Exact, // == NotEqual, // != AllEqual, // *= AnyEqual, // ?= @@ -64,6 +65,7 @@ impl fmt::Display for Operator { Operator::Inc => write!(f, "+="), Operator::Dec => write!(f, "-="), Operator::Equal => write!(f, "="), + Operator::Exact => write!(f, "=="), Operator::NotEqual => write!(f, "!="), Operator::AllEqual => write!(f, "*="), Operator::AnyEqual => write!(f, "?="), @@ -111,6 +113,7 @@ pub fn operator(i: &str) -> IResult<&str, Operator> { )), alt(( map(tag("="), |_| Operator::Equal), + map(tag("=="), |_| Operator::Exact), map(tag("!="), |_| Operator::NotEqual), map(tag("*="), |_| Operator::AllEqual), map(tag("?="), |_| Operator::AnyEqual),