allowing column ref with table specified
This commit is contained in:
parent
33e04efcab
commit
b06ea85ff5
|
@ -21,7 +21,7 @@ echo "\n\n"
|
|||
|
||||
# ./bin/analysis "SELECT a FROM foo WHERE a > 12 OR b > 3 AND c = 3"
|
||||
./bin/analysis "SELECT col1, col2, 'test' FROM table, foo WHERE age > 12 AND zipcode = 12345 GROUP BY col1 ORDER BY col2 DESC LIMIT 100;"
|
||||
./bin/analysis "SELECT * from table WHERE (b OR NOT a) AND a = 12.5 JOIN table2 ON a = b"
|
||||
./bin/analysis "SELECT * from table WHERE (b OR NOT a) AND a = 12.5 JOIN table2 ON t1.a = t2.b"
|
||||
# ./bin/analysis "SELECT * from table WHERE (b OR NOT a) AND a = 12.5 JOIN table2 ON a = b"
|
||||
|
||||
echo "\n\n"
|
|
@ -72,6 +72,13 @@ Expr* Expr::makeColumnRef(char* name) {
|
|||
return e;
|
||||
}
|
||||
|
||||
Expr* Expr::makeColumnRef(char* table, char* name) {
|
||||
ALLOC_EXPR(e, kExprTableColumnRef);
|
||||
e->name = name;
|
||||
e->table = table;
|
||||
return e;
|
||||
}
|
||||
|
||||
Expr* Expr::makeFunctionRef(char* func_name, Expr* expr) {
|
||||
ALLOC_EXPR(e, kExprFunctionRef);
|
||||
e->name = func_name;
|
||||
|
|
|
@ -11,6 +11,7 @@ typedef enum {
|
|||
kExprLiteralInt,
|
||||
kExprStar,
|
||||
kExprColumnRef,
|
||||
kExprTableColumnRef,
|
||||
kExprFunctionRef,
|
||||
kExprOperator
|
||||
} ExprType;
|
||||
|
@ -49,6 +50,7 @@ struct Expr {
|
|||
Expr* expr;
|
||||
Expr* expr2;
|
||||
char* name;
|
||||
char* table;
|
||||
float fval;
|
||||
int64_t ival;
|
||||
|
||||
|
@ -64,6 +66,7 @@ struct Expr {
|
|||
static Expr* makeLiteral(char* val);
|
||||
|
||||
static Expr* makeColumnRef(char* name);
|
||||
static Expr* makeColumnRef(char* table, char* name);
|
||||
static Expr* makeFunctionRef(char* func_name, Expr* expr);
|
||||
};
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ const char* indent(uint num_indent) { return std::string(num_indent, '\t').c_str
|
|||
void inprint(int64_t val, uint num_indent) { printf("%s%ld \n", indent(num_indent), val); }
|
||||
void inprint(float val, uint num_indent) { printf("%s%f\n", indent(num_indent), val); }
|
||||
void inprint(const char* val, uint num_indent) { printf("%s%s\n", indent(num_indent), val); }
|
||||
void inprint(const char* val, const char* val2, uint num_indent) { printf("%s%s->%s\n", indent(num_indent), val, val2); }
|
||||
void inprintC(char val, uint num_indent) { printf("%s%c\n", indent(num_indent), val); }
|
||||
void inprintU(uint64_t val, uint num_indent) { printf("%s%lu\n", indent(num_indent), val); }
|
||||
|
||||
|
@ -47,6 +48,7 @@ void printExpression(Expr* expr, uint num_indent) {
|
|||
switch (expr->type) {
|
||||
case kExprStar: inprint("*", num_indent); break;
|
||||
case kExprColumnRef: inprint(expr->name, num_indent); break;
|
||||
case kExprTableColumnRef: inprint(expr->table, expr->name, num_indent); break;
|
||||
case kExprLiteralFloat: inprint(expr->fval, num_indent); break;
|
||||
case kExprLiteralInt: inprint(expr->ival, num_indent); break;
|
||||
case kExprLiteralString: inprint(expr->name, num_indent); break;
|
||||
|
|
|
@ -291,6 +291,7 @@ function_expr:
|
|||
|
||||
column_name:
|
||||
NAME { $$ = Expr::makeColumnRef($1); }
|
||||
| NAME '.' NAME { $$ = Expr::makeColumnRef($1, $3); }
|
||||
;
|
||||
|
||||
literal:
|
||||
|
|
|
@ -28,7 +28,11 @@ int main(int argc, char *argv[]) {
|
|||
} else if (stmt->type == kStmtJoin) {
|
||||
printJoinStatementInfo((JoinStatement*) stmt, 0);
|
||||
} else {
|
||||
fprintf(stderr, "Unsupported Statement Type %u!\n", stmt->type);
|
||||
if (stmt->type == kStmtError) {
|
||||
fprintf(stderr, "%s!\n", stmt->parser_msg);
|
||||
} else {
|
||||
fprintf(stderr, "Unsupported Statement Type %u!\n", stmt->type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue