extended unary expr support
This commit is contained in:
parent
f0bb8592cc
commit
bcb39ee291
|
@ -208,9 +208,8 @@ scalar_expr:
|
|||
;
|
||||
|
||||
unary_expr:
|
||||
'-' expr { $$ = NULL; } // TODO
|
||||
| '+' expr { $$ = NULL; }
|
||||
| NOT expr { $$ = NULL; }
|
||||
'-' expr { $$ = Expr::makeOpUnary(UMINUS, $2); }
|
||||
| NOT expr { $$ = Expr::makeOpUnary(NOT, $2); }
|
||||
;
|
||||
|
||||
binary_expr:
|
||||
|
|
|
@ -6,4 +6,5 @@ make clean
|
|||
|
||||
make execution
|
||||
./bin/sql_execution "SELECT a FROM foo WHERE a > 12 OR b > 3 AND c = 3"
|
||||
./bin/sql_execution "SELECT col1, col2, 'test' FROM table, foo WHERE age > 12 AND zipcode = 12345 GROUP BY col1;"
|
||||
./bin/sql_execution "SELECT col1, col2, 'test' FROM table, foo WHERE age > 12 AND zipcode = 12345 GROUP BY col1;"
|
||||
./bin/sql_execution "SELECT * from table WHERE NOT a AND a = 12.5"
|
||||
|
|
|
@ -42,6 +42,7 @@ Expr* Expr::makeOpUnary(OperatorType op, Expr* expr) {
|
|||
ALLOC_EXPR(e, eExprOperator);
|
||||
e->op_type = op;
|
||||
e->expr = expr;
|
||||
e->expr2 = NULL;
|
||||
return e;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,14 +23,17 @@ typedef enum {
|
|||
*/
|
||||
typedef enum {
|
||||
TRIVIAL_OP,
|
||||
// Binary
|
||||
NOT_EQUALS,
|
||||
LESS_EQ,
|
||||
GREATER_EQ,
|
||||
LIKE,
|
||||
ISNULL,
|
||||
NOT,
|
||||
AND,
|
||||
OR
|
||||
OR,
|
||||
// Unary
|
||||
NOT,
|
||||
UMINUS,
|
||||
ISNULL
|
||||
} OperatorType;
|
||||
|
||||
|
||||
|
|
|
@ -27,10 +27,13 @@ void printTableRefInfo(TableRef* table, uint num_indent) {
|
|||
}
|
||||
|
||||
void printOperatorExpression(Expr* expr, uint num_indent) {
|
||||
if (expr == NULL) { inprint("null", num_indent); return; }
|
||||
|
||||
switch (expr->op_type) {
|
||||
case TRIVIAL_OP: inprint(expr->op_char, num_indent); break;
|
||||
case AND: inprint("AND", num_indent); break;
|
||||
case OR: inprint("OR", num_indent); break;
|
||||
case NOT: inprint("NOT", num_indent); break;
|
||||
default: inprint(expr->op_type, num_indent); break;
|
||||
}
|
||||
printExpression(expr->expr, num_indent+1);
|
||||
|
@ -45,9 +48,7 @@ void printExpression(Expr* expr, uint num_indent) {
|
|||
case eExprLiteralString: inprint(expr->name, num_indent); break;
|
||||
case eExprFunctionRef: /* todo */ break;
|
||||
case eExprOperator: printOperatorExpression(expr, num_indent); break;
|
||||
default:
|
||||
fprintf(stderr, "Unrecognized expression type %d\n", expr->type);
|
||||
break;
|
||||
default: fprintf(stderr, "Unrecognized expression type %d\n", expr->type); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,5 +61,8 @@ void printSelectStatementInfo(SelectStatement* stmt, uint num_indent) {
|
|||
printTableRefInfo(stmt->from_table, num_indent+2);
|
||||
|
||||
inprint("Search Conditions:", num_indent+1);
|
||||
printExpression(stmt->where_clause, num_indent+2);
|
||||
if (stmt->where_clause != NULL) {
|
||||
printExpression(stmt->where_clause, num_indent+2);
|
||||
} else inprint("null", num_indent+2);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue