Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ pub enum Operator {
In,
NotIn,
Is,
IsNot
}

impl Display for Operator {
Expand All @@ -237,6 +238,7 @@ impl Display for Operator {
Operator::LessOrEqual => "<=",
Operator::In => "IN",
Operator::NotIn => "NOT IN",
Operator::IsNot => "IS NOT",
Operator::Is => "IS",
};
write!(f, "{}", op)
Expand Down
35 changes: 28 additions & 7 deletions src/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,13 @@ fn is_null(i: &[u8]) -> IResult<&[u8], (Operator, ConditionExpression)> {
tag_no_case("null"),
))(i)?;

// XXX(malte): bit of a hack; would consumers ever need to know
// about "IS NULL" vs. "= NULL"?
Ok((
remaining_input,
(
if not.is_some() {
Operator::NotEqual
Operator::IsNot
} else {
Operator::Equal
Operator::Is
},
ConditionExpression::Base(ConditionBase::Literal(Literal::Null)),
),
Expand Down Expand Up @@ -838,11 +836,34 @@ mod tests {

let res = condition_expr(cond.as_bytes());
let expected =
flat_condition_tree(Operator::Equal, Field("bar".into()), Literal(Literal::Null));
flat_condition_tree(Operator::Is, Field("bar".into()), Literal(Literal::Null));
assert_eq!(res.unwrap().1, expected);

let cond = "bar IS NOT NULL";

let res = condition_expr(cond.as_bytes());
let expected = flat_condition_tree(
Operator::IsNot,
Field("bar".into()),
Literal(Literal::Null),
);
assert_eq!(res.unwrap().1, expected);
}

#[test]
fn null_equality() {
use common::Literal;
use ConditionBase::*;

let cond = "bar = NULL";

let res = condition_expr(cond.as_bytes());
let expected =
flat_condition_tree(Operator::Equal, Field("bar".into()), Literal(Literal::Null));
assert_eq!(res.unwrap().1, expected);

let cond = "bar != NULL";

let res = condition_expr(cond.as_bytes());
let expected = flat_condition_tree(
Operator::NotEqual,
Expand Down Expand Up @@ -903,7 +924,7 @@ mod tests {
ConditionExpression::LogicalOp(ConditionTree {
operator: Operator::And,
left: Box::new(flat_condition_tree(
Operator::Equal,
Operator::Is,
Field("parent_comments.user_id".into()),
Literal(Literal::Null),
)),
Expand All @@ -922,7 +943,7 @@ mod tests {
ConditionExpression::LogicalOp(ConditionTree {
operator: Operator::Or,
left: Box::new(flat_condition_tree(
Operator::Equal,
Operator::Is,
Field("parent_comments.id".into()),
Literal(Literal::Null),
)),
Expand Down
2 changes: 1 addition & 1 deletion src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ mod tests {
left: Box::new(ComparisonOp(ConditionTree {
left: Box::new(Base(Field(Column::from("votes.story_id")))),
right: Box::new(Base(Literal(Literal::Null))),
operator: Operator::Equal,
operator: Operator::Is,
})),
right: Box::new(ComparisonOp(ConditionTree {
left: Box::new(Base(Field(Column::from("votes.vote")))),
Expand Down