From a0e55035fd7cf87ff7850b3f7fc06f30df3e3c33 Mon Sep 17 00:00:00 2001 From: Pedro Date: Tue, 7 Mar 2017 15:53:22 +0100 Subject: [PATCH] Implement NOT EXISTS --- src/parser/bison_parser.y | 10 +++++----- src/sql/Expr.cpp | 22 +++------------------- src/sql/Expr.h | 4 ++-- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/parser/bison_parser.y b/src/parser/bison_parser.y index 08ebaf9..2e32ca4 100644 --- a/src/parser/bison_parser.y +++ b/src/parser/bison_parser.y @@ -661,12 +661,11 @@ logic_expr: | expr OR expr { $$ = Expr::makeOpBinary($1, Expr::OR, $3); } ; -// TODO: in_expr: - operand IN '(' expr_list ')' { $$ = Expr::makeInOperator($1, $4, false); } - | operand NOT IN '(' expr_list ')' { $$ = Expr::makeInOperator($1, $5, true); } - | operand IN '(' select_no_paren ')' { $$ = Expr::makeInOperator($1, $4, false); } - | operand NOT IN '(' select_no_paren ')' { $$ = Expr::makeInOperator($1, $5, true); } + operand IN '(' expr_list ')' { $$ = Expr::makeInOperator($1, $4); } + | operand NOT IN '(' expr_list ')' { $$ = Expr::makeOpUnary(Expr::NOT, Expr::makeInOperator($1, $5)); } + | operand IN '(' select_no_paren ')' { $$ = Expr::makeInOperator($1, $4); } + | operand NOT IN '(' select_no_paren ')' { $$ = Expr::makeOpUnary(Expr::NOT, Expr::makeInOperator($1, $5)); } ; // TODO: allow no else specified @@ -676,6 +675,7 @@ case_expr: exists_expr: EXISTS '(' select_no_paren ')' { $$ = Expr::makeExists($3); } + | NOT EXISTS '(' select_no_paren ')' { $$ = Expr::makeOpUnary(Expr::NOT, Expr::makeExists($4)); } ; comp_expr: diff --git a/src/sql/Expr.cpp b/src/sql/Expr.cpp index 2deb8c6..a4d4c80 100644 --- a/src/sql/Expr.cpp +++ b/src/sql/Expr.cpp @@ -137,37 +137,21 @@ namespace hsql { return e; } - Expr* Expr::makeInOperator(Expr* expr, std::vector* exprList, bool notIn) { + Expr* Expr::makeInOperator(Expr* expr, std::vector* exprList) { Expr* e = new Expr(kExprOperator); e->opType = IN; e->expr = expr; e->exprList = exprList; - // If it is NOT IN, wrap the IN in a NOT operator. - if (notIn) { - Expr* neg = new Expr(kExprOperator); - neg->opType = NOT; - neg->expr = e; - return neg; - } - return e; } - Expr* Expr::makeInOperator(Expr* expr, SelectStatement* select, bool notIn) { + Expr* Expr::makeInOperator(Expr* expr, SelectStatement* select) { Expr* e = new Expr(kExprOperator); e->opType = IN; e->expr = expr; e->select = select; - - // If it is NOT IN, wrap the IN in a NOT operator. - if (notIn) { - Expr* neg = new Expr(kExprOperator); - neg->opType = NOT; - neg->expr = e; - return neg; - } - + return e; } diff --git a/src/sql/Expr.h b/src/sql/Expr.h index 4bbd435..3284802 100644 --- a/src/sql/Expr.h +++ b/src/sql/Expr.h @@ -133,9 +133,9 @@ namespace hsql { static Expr* makeExists(SelectStatement* select); - static Expr* makeInOperator(Expr* expr, std::vector* exprList, bool notIn); + static Expr* makeInOperator(Expr* expr, std::vector* exprList); - static Expr* makeInOperator(Expr* expr, SelectStatement* select, bool notIn); + static Expr* makeInOperator(Expr* expr, SelectStatement* select); }; // Zero initializes an Expr object and assigns it to a space in the heap