Implement NOT EXISTS

This commit is contained in:
Pedro 2017-03-07 15:53:22 +01:00
parent 177901816f
commit a0e55035fd
3 changed files with 10 additions and 26 deletions

View File

@ -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:

View File

@ -137,37 +137,21 @@ namespace hsql {
return e;
}
Expr* Expr::makeInOperator(Expr* expr, std::vector<Expr*>* exprList, bool notIn) {
Expr* Expr::makeInOperator(Expr* expr, std::vector<Expr*>* 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;
}

View File

@ -133,9 +133,9 @@ namespace hsql {
static Expr* makeExists(SelectStatement* select);
static Expr* makeInOperator(Expr* expr, std::vector<Expr*>* exprList, bool notIn);
static Expr* makeInOperator(Expr* expr, std::vector<Expr*>* 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