Skip to content

Commit 168a48f

Browse files
author
Dray Lacy
committed
Added ORDER BY.
1 parent d051c6c commit 168a48f

File tree

8 files changed

+767
-635
lines changed

8 files changed

+767
-635
lines changed

lib/sql/parser.racc

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,43 @@
11
class SQL::Parser
22

33
rule
4-
statement
5-
: query_specification
4+
# dynamic sql
5+
direct_sql_statement
6+
: direct_sql_data_statement
7+
8+
direct_sql_data_statement
9+
: direct_select_statement_multiple_rows
10+
11+
direct_select_statement_multiple_rows
12+
: query_expression order_by_clause { result = SQL::Statement::DirectSelect.new(val[0], val[1]) }
13+
14+
# module contents
15+
order_by_clause
16+
: # no action
17+
| ORDER BY sort_specification_list { result = SQL::Statement::OrderBy.new(val[2]) }
18+
19+
sort_specification_list
20+
: sort_specification_list comma sort_specification { result = Array(val[0]) + Array(val[2]) }
21+
| sort_specification
22+
23+
sort_specification
24+
: sort_key ordering_specification
25+
26+
sort_key
27+
: column_name
28+
29+
ordering_specification
30+
: # no action
31+
# | ASC
32+
# | DESC
633

734
# queries
835
subquery
936
# FIXME: shortcut
10-
: left_paren query_specification right_paren { result = SQL::Statement::Subquery.new(val[1]) }
37+
: left_paren query_expression right_paren { result = SQL::Statement::Subquery.new(val[1]) }
38+
39+
query_expression
40+
: query_specification
1141

1242
query_specification
1343
: SELECT select_list table_expression { result = SQL::Statement::Select.new(val[1], val[2]) }

0 commit comments

Comments
 (0)