now supporting * in select list

This commit is contained in:
Pedro 2014-10-22 17:18:43 +02:00
parent 5dfcce1b7d
commit 200402bab2
2 changed files with 9 additions and 7 deletions

View File

@ -93,7 +93,7 @@ typedef void* yyscan_t;
%type <expr> expr column_name scalar_exp literal %type <expr> expr column_name scalar_exp literal
%type <expr> comparison_predicate predicate search_condition where_clause %type <expr> comparison_predicate predicate search_condition where_clause
%type <slist> table_ref_commalist %type <slist> table_ref_commalist
%type <explist> expr_list group_clause %type <explist> expr_list group_clause select_list
@ -125,7 +125,7 @@ statement:
// TODO: limit // TODO: limit
// TODO: order by // TODO: order by
select_statement: select_statement:
SELECT expr_list from_clause where_clause group_clause SELECT select_list from_clause where_clause group_clause
{ {
SelectStatement* s = new SelectStatement(); SelectStatement* s = new SelectStatement();
s->select_list = $2; s->select_list = $2;
@ -137,6 +137,10 @@ select_statement:
; ;
select_list:
'*' { $$ = new List<Expr*>(makeColumnRef("*")); }
| expr_list;
from_clause: from_clause:
FROM table_exp { $$ = $2; } FROM table_exp { $$ = $2; }

View File

@ -50,17 +50,15 @@ void SelectTest2() {
printf("Test: SelectTest2... "); printf("Test: SelectTest2... ");
fflush(stdout); fflush(stdout);
const char* sql = "SELECT age, name, address FROM (SELECT age FROM table, table2);"; const char* sql = "SELECT * FROM (SELECT age FROM table, table2);";
Statement* stmt = SQLParser::parseSQL(sql); Statement* stmt = SQLParser::parseSQL(sql);
ASSERT(stmt != NULL); ASSERT(stmt != NULL);
ASSERT(stmt->type == eSelect); ASSERT(stmt->type == eSelect);
SelectStatement* select = (SelectStatement*) stmt; SelectStatement* select = (SelectStatement*) stmt;
ASSERT(select->select_list->size() == 3); ASSERT(select->select_list->size() == 1);
ASSERT_STR(select->select_list->at(0)->name, "age"); ASSERT_STR(select->select_list->at(0)->name, "*");
ASSERT_STR(select->select_list->at(1)->name, "name");
ASSERT_STR(select->select_list->at(2)->name, "address");
ASSERT(select->from_table != NULL); ASSERT(select->from_table != NULL);
ASSERT(select->from_table->type == eTableSelect); ASSERT(select->from_table->type == eTableSelect);