oracle-sql-parser 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/HISTORY.md +6 -0
- data/Rakefile +3 -11
- data/lib/oracle-sql-parser/ast.rb +5 -1
- data/lib/oracle-sql-parser/ast/cursor_expression.rb +13 -0
- data/lib/oracle-sql-parser/ast/datetime_expression.rb +8 -0
- data/lib/oracle-sql-parser/ast/interval_expression.rb +27 -0
- data/lib/oracle-sql-parser/ast/{simple_comparision_condition.rb → simple_comparison_condition.rb} +1 -1
- data/lib/oracle-sql-parser/ast/timezone_clause.rb +8 -0
- data/lib/oracle-sql-parser/grammar.rb +24 -0
- data/lib/oracle-sql-parser/grammar/condition.treetop +12 -289
- data/lib/oracle-sql-parser/grammar/condition/between.treetop +20 -0
- data/lib/oracle-sql-parser/grammar/condition/comparison.treetop +32 -0
- data/lib/oracle-sql-parser/grammar/condition/compound.treetop +11 -0
- data/lib/oracle-sql-parser/grammar/condition/exists.treetop +13 -0
- data/lib/oracle-sql-parser/grammar/condition/floating_point.treetop +20 -0
- data/lib/oracle-sql-parser/grammar/condition/in.treetop +19 -0
- data/lib/oracle-sql-parser/grammar/condition/is_of_type.treetop +56 -0
- data/lib/oracle-sql-parser/grammar/condition/multiset.treetop +85 -0
- data/lib/oracle-sql-parser/grammar/condition/null.treetop +17 -0
- data/lib/oracle-sql-parser/grammar/condition/pattern_matching.treetop +47 -0
- data/lib/oracle-sql-parser/grammar/delete.treetop +2 -10
- data/lib/oracle-sql-parser/grammar/expression.treetop +39 -214
- data/lib/oracle-sql-parser/grammar/expression/case.treetop +77 -0
- data/lib/oracle-sql-parser/grammar/expression/compound.treetop +22 -0
- data/lib/oracle-sql-parser/grammar/expression/cursor.treetop +15 -0
- data/lib/oracle-sql-parser/grammar/expression/datetime.treetop +36 -0
- data/lib/oracle-sql-parser/grammar/expression/function.treetop +47 -0
- data/lib/oracle-sql-parser/grammar/expression/interval.treetop +47 -0
- data/lib/oracle-sql-parser/grammar/expression/simple.treetop +29 -0
- data/lib/oracle-sql-parser/grammar/grammar.treetop +1 -1
- data/lib/oracle-sql-parser/grammar/reserved_word_generator.rb +14 -2
- data/lib/oracle-sql-parser/grammar/select.treetop +11 -513
- data/lib/oracle-sql-parser/grammar/select/for_update.treetop +48 -0
- data/lib/oracle-sql-parser/grammar/select/group.treetop +62 -0
- data/lib/oracle-sql-parser/grammar/select/join.treetop +165 -0
- data/lib/oracle-sql-parser/grammar/select/order.treetop +43 -0
- data/lib/oracle-sql-parser/grammar/select/query_block.treetop +116 -0
- data/lib/oracle-sql-parser/grammar/select/union.treetop +48 -0
- data/lib/oracle-sql-parser/grammar/update.treetop +1 -1
- data/lib/oracle-sql-parser/version.rb +1 -1
- data/oracle-sql-parser.gemspec +1 -0
- metadata +55 -3
@@ -0,0 +1,77 @@
|
|
1
|
+
module OracleSqlParser::Grammar::Expression
|
2
|
+
grammar Case
|
3
|
+
rule case_expression
|
4
|
+
case_keyword space? case_expression:(simple_case_expression / searched_case_expression) space?
|
5
|
+
else_clause:else_clause? space? end_keyword {
|
6
|
+
def ast
|
7
|
+
ast = case_expression.ast
|
8
|
+
ast.else_clause = else_clause.ast
|
9
|
+
ast
|
10
|
+
end
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
rule simple_case_expression
|
15
|
+
expr space w:(when_keyword space comparison_expr space then_keyword space? return_expr space?)+ {
|
16
|
+
def ast
|
17
|
+
OracleSqlParser::Ast::SimpleCaseExpression[
|
18
|
+
:condition => expr.ast,
|
19
|
+
:when_clauses => OracleSqlParser::Ast::Array[*when_clauses]
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
def when_clauses
|
24
|
+
w.elements.map do |elem|
|
25
|
+
OracleSqlParser::Ast::Hash[
|
26
|
+
:when_expr => elem.comparison_expr.ast,
|
27
|
+
:return_expr => elem.return_expr.ast
|
28
|
+
]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
rule comparison_expr
|
35
|
+
expr {
|
36
|
+
def ast
|
37
|
+
super
|
38
|
+
end
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
rule return_expr
|
43
|
+
expr {
|
44
|
+
def ast
|
45
|
+
super
|
46
|
+
end
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
rule else_expr
|
51
|
+
expr {
|
52
|
+
def ast
|
53
|
+
super
|
54
|
+
end
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
rule searched_case_expression
|
59
|
+
when_keyword space? condition space? then_keyword space? return_expr {
|
60
|
+
def ast
|
61
|
+
OracleSqlParser::Ast::SearchedCaseExpression[
|
62
|
+
:when_condition => condition.ast,
|
63
|
+
:return_expr => return_expr.ast
|
64
|
+
]
|
65
|
+
end
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
rule else_clause
|
70
|
+
else_keyword space? else_expr {
|
71
|
+
def ast
|
72
|
+
else_expr.ast
|
73
|
+
end
|
74
|
+
}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module OracleSqlParser::Grammar::Expression
|
2
|
+
grammar Compound
|
3
|
+
rule compound_expression
|
4
|
+
ex:(
|
5
|
+
left_parenthesis:'(' space? left:expr space? right_parenthesis:')' /
|
6
|
+
left:not_loop_sql_expression space? op:('*' / '/' / '+' / '-' / '||') space? right:expr /
|
7
|
+
!number_literal op:(prior_keyword / '-' / '+') space? right:expr
|
8
|
+
)
|
9
|
+
|
10
|
+
{
|
11
|
+
def ast
|
12
|
+
OracleSqlParser::Ast::CompoundExpression[
|
13
|
+
:has_parenthesis => ex.respond_to?(:left_parenthesis) ? true : nil,
|
14
|
+
:left => ex.try(:left).ast,
|
15
|
+
:op => ex.try(:op).ast,
|
16
|
+
:right => ex.try(:right).ast,
|
17
|
+
]
|
18
|
+
end
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module OracleSqlParser::Grammar::Expression
|
2
|
+
grammar Cursor
|
3
|
+
rule cursor_expression
|
4
|
+
cursor_keyword space? '(' space? subquery space? ')' {
|
5
|
+
def ast
|
6
|
+
OracleSqlParser::Ast::CursorExpression[
|
7
|
+
:cursor => cursor_keyword.ast,
|
8
|
+
:subquery => subquery.ast,
|
9
|
+
]
|
10
|
+
end
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module OracleSqlParser::Grammar::Expression
|
2
|
+
grammar Datetime
|
3
|
+
rule datetime_expression
|
4
|
+
not_loop_sql_expression space? d:(
|
5
|
+
at_keyword space? local_keyword /
|
6
|
+
at_keyword space? datetime_timezone_clause
|
7
|
+
) {
|
8
|
+
def ast
|
9
|
+
OracleSqlParser::Ast::DatetimeExpression[
|
10
|
+
:expr => not_loop_sql_expression.ast,
|
11
|
+
:at => d.try(:at_keyword).ast,
|
12
|
+
:local => d.try(:local_keyword).ast,
|
13
|
+
:timezone => d.try(:datetime_timezone_clause).ast,
|
14
|
+
]
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
rule datetime_timezone_clause
|
20
|
+
time_keyword space? zone_keyword space? expr:(
|
21
|
+
text_literal /
|
22
|
+
dbtimezone_keyword /
|
23
|
+
sessiontimezone_keyword /
|
24
|
+
expr
|
25
|
+
) {
|
26
|
+
def ast
|
27
|
+
OracleSqlParser::Ast::TimezoneClause[
|
28
|
+
:time => time_keyword.ast,
|
29
|
+
:zone => zone_keyword.ast,
|
30
|
+
:expr => expr.ast,
|
31
|
+
]
|
32
|
+
end
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module OracleSqlParser::Grammar::Expression
|
2
|
+
grammar Function
|
3
|
+
rule function_expression
|
4
|
+
function_name space? '(' space? function_args:function_args? space? ')' {
|
5
|
+
def ast
|
6
|
+
OracleSqlParser::Ast::FunctionExpression[
|
7
|
+
:name => function_name.ast,
|
8
|
+
:args => function_args.ast
|
9
|
+
]
|
10
|
+
end
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
rule function_name
|
15
|
+
(
|
16
|
+
package_name '.' procedure_name /
|
17
|
+
procedure_name
|
18
|
+
) {
|
19
|
+
def ast
|
20
|
+
OracleSqlParser::Ast::Identifier[:name => text_value]
|
21
|
+
end
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
rule function_args
|
26
|
+
function_arg more:(space? ',' space? function_arg)* {
|
27
|
+
def ast
|
28
|
+
OracleSqlParser::Ast::Array[function_arg.ast, *more_function_args.map(&:ast)]
|
29
|
+
end
|
30
|
+
|
31
|
+
def more_function_args
|
32
|
+
more.elements.map(&:function_arg)
|
33
|
+
end
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
rule function_arg
|
38
|
+
expr {
|
39
|
+
def ast
|
40
|
+
super
|
41
|
+
end
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module OracleSqlParser::Grammar::Expression
|
2
|
+
grammar Interval
|
3
|
+
rule interval_expression
|
4
|
+
'(' space? left:not_loop_sql_expression space? '-' space? right:expr space? ')'
|
5
|
+
e:(
|
6
|
+
space? day_keyword
|
7
|
+
l:(space? '(' space? leading_field_precision space? ')')?
|
8
|
+
space? to_keyword space? second_keyword
|
9
|
+
f:(space? '(' space? fractional_second_precision space? ')')?
|
10
|
+
/
|
11
|
+
space? year_keyword
|
12
|
+
l:(space? '(' space? leading_field_precision space? ')')?
|
13
|
+
space? to_keyword space? month_keyword
|
14
|
+
) {
|
15
|
+
def ast
|
16
|
+
OracleSqlParser::Ast::IntervalExpression[
|
17
|
+
:left => left.ast,
|
18
|
+
:right => right.ast,
|
19
|
+
:day => e.try(:day_keyword).ast,
|
20
|
+
:year => e.try(:year_keyword).ast,
|
21
|
+
:leading_field_precision => e.try(:l).try(:leading_field_precision).ast,
|
22
|
+
:to => e.try(:to_keyword).ast,
|
23
|
+
:second => e.try(:second_keyword).ast,
|
24
|
+
:month => e.try(:month_keyword).ast,
|
25
|
+
:fractional_second_precision => e.try(:f).try(:fractional_second_precision).ast,
|
26
|
+
]
|
27
|
+
end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
rule leading_field_precision
|
32
|
+
[0-9] {
|
33
|
+
def ast
|
34
|
+
OracleSqlParser::Ast::NumberLiteral[:value => text_value]
|
35
|
+
end
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
rule fractional_second_precision
|
40
|
+
[0-9] {
|
41
|
+
def ast
|
42
|
+
OracleSqlParser::Ast::NumberLiteral[:value => text_value]
|
43
|
+
end
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module OracleSqlParser::Grammar::Expression
|
2
|
+
grammar Simple
|
3
|
+
rule simple_expression
|
4
|
+
rownum_keyword /
|
5
|
+
sysdate_keyword /
|
6
|
+
systimestamp_keyword /
|
7
|
+
null_keyword /
|
8
|
+
text_literal /
|
9
|
+
number_literal /
|
10
|
+
sequence /
|
11
|
+
simple_expression_column {
|
12
|
+
def ast
|
13
|
+
super
|
14
|
+
end
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
rule simple_expression_column
|
19
|
+
name:(
|
20
|
+
( schema_name space? '.' space? table_name '.' / table_name space? '.' space? )?
|
21
|
+
( rowid_keyword / column_name )
|
22
|
+
) {
|
23
|
+
def ast
|
24
|
+
OracleSqlParser::Ast::Identifier.new(:name => text_value)
|
25
|
+
end
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -94,14 +94,15 @@ EOS
|
|
94
94
|
'ANY',
|
95
95
|
'AS',
|
96
96
|
'ASC',
|
97
|
+
'AT',
|
97
98
|
'AUDIT',
|
98
99
|
'BETWEEN',
|
99
100
|
'BY',
|
100
101
|
'CASE',
|
102
|
+
'CAST',
|
101
103
|
'CHAR',
|
102
104
|
'CHECK',
|
103
105
|
'CLUSTER',
|
104
|
-
'CURRENT_OF',
|
105
106
|
'COLUMN',
|
106
107
|
'COLUMN_VALUE',
|
107
108
|
'COMMENT',
|
@@ -111,8 +112,12 @@ EOS
|
|
111
112
|
'CROSS',
|
112
113
|
'CUBE',
|
113
114
|
'CURRENT',
|
115
|
+
'CURRENT_OF',
|
114
116
|
'CURRVAL',
|
117
|
+
'CURSOR',
|
115
118
|
'DATE',
|
119
|
+
'DAY',
|
120
|
+
'DBTIMEZONE',
|
116
121
|
'DECIMAL',
|
117
122
|
'DEFAULT',
|
118
123
|
'DELETE',
|
@@ -155,6 +160,7 @@ EOS
|
|
155
160
|
'LIKE2',
|
156
161
|
'LIKE4',
|
157
162
|
'LIKEC',
|
163
|
+
'LOCAL',
|
158
164
|
'LOCK',
|
159
165
|
'LONG',
|
160
166
|
'MAXEXTENTS',
|
@@ -163,6 +169,7 @@ EOS
|
|
163
169
|
'MLSLABEL',
|
164
170
|
'MODE',
|
165
171
|
'MODIFY',
|
172
|
+
'MONTH',
|
166
173
|
'NAN',
|
167
174
|
'NATURAL',
|
168
175
|
'NESTED_TABLE_ID',
|
@@ -198,12 +205,14 @@ EOS
|
|
198
205
|
'ROWID',
|
199
206
|
'ROWNUM',
|
200
207
|
'ROWS',
|
208
|
+
'SECOND',
|
201
209
|
'SELECT',
|
202
210
|
'SESSION',
|
211
|
+
'SESSIONTIMEZONE',
|
203
212
|
'SET',
|
204
213
|
'SHARE',
|
205
|
-
'SIZE',
|
206
214
|
'SIBLINGS',
|
215
|
+
'SIZE',
|
207
216
|
'SMALLINT',
|
208
217
|
'START',
|
209
218
|
'SUBMULTISET',
|
@@ -213,6 +222,7 @@ EOS
|
|
213
222
|
'SYSTIMESTAMP',
|
214
223
|
'TABLE',
|
215
224
|
'THEN',
|
225
|
+
'TIME',
|
216
226
|
'TO',
|
217
227
|
'TRIGGER',
|
218
228
|
'TYPE',
|
@@ -231,6 +241,8 @@ EOS
|
|
231
241
|
'WHEN',
|
232
242
|
'WHENEVER',
|
233
243
|
'WHERE',
|
244
|
+
'YEAR',
|
245
|
+
'ZONE',
|
234
246
|
]
|
235
247
|
end
|
236
248
|
end
|
@@ -1,5 +1,12 @@
|
|
1
1
|
module OracleSqlParser::Grammar
|
2
2
|
grammar Select
|
3
|
+
include OracleSqlParser::Grammar::Select::Order
|
4
|
+
include OracleSqlParser::Grammar::Select::Group
|
5
|
+
include OracleSqlParser::Grammar::Select::Join
|
6
|
+
include OracleSqlParser::Grammar::Select::ForUpdate
|
7
|
+
include OracleSqlParser::Grammar::Select::Union
|
8
|
+
include OracleSqlParser::Grammar::Select::QueryBlock
|
9
|
+
|
3
10
|
rule select_statement
|
4
11
|
space? subquery for_update:(space for_update_clause)? space? {
|
5
12
|
def ast
|
@@ -20,522 +27,13 @@ module OracleSqlParser::Grammar
|
|
20
27
|
order:(space order_by_clause)? {
|
21
28
|
def ast
|
22
29
|
OracleSqlParser::Ast::Subquery[
|
23
|
-
:has_parenthesis =>
|
24
|
-
:query_block => query_block.ast,
|
25
|
-
:subqueries => subqueries.ast,
|
26
|
-
:subquery => subquery.ast,
|
30
|
+
:has_parenthesis => query.try(:left_parenthesis) ? true : nil,
|
31
|
+
:query_block => query.try(:query_block).ast,
|
32
|
+
:subqueries => query.try(:subqueries).ast,
|
33
|
+
:subquery => query.try(:subquery).ast,
|
27
34
|
:order_by_clause => order.try(:order_by_clause).ast,
|
28
35
|
]
|
29
36
|
end
|
30
|
-
|
31
|
-
def has_parenthesis
|
32
|
-
true if query.respond_to? :left_parenthesis
|
33
|
-
end
|
34
|
-
|
35
|
-
def query_block
|
36
|
-
query.query_block if query.respond_to? :query_block
|
37
|
-
end
|
38
|
-
|
39
|
-
def subqueries
|
40
|
-
query.subqueries if query.respond_to? :subqueries
|
41
|
-
end
|
42
|
-
|
43
|
-
def subquery
|
44
|
-
query.subquery if query.respond_to? :subquery
|
45
|
-
end
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
rule subqueries_with_union
|
50
|
-
query_block space? more:(union_or_intersect_or_minus space? subquery)+
|
51
|
-
{
|
52
|
-
def ast
|
53
|
-
OracleSqlParser::Ast::Array[
|
54
|
-
query_block.ast,
|
55
|
-
*more_queries.map(&:ast),
|
56
|
-
]
|
57
|
-
end
|
58
|
-
|
59
|
-
def more_queries
|
60
|
-
more.elements.map{|e| [e.union_or_intersect_or_minus, e.subquery]}.flatten
|
61
|
-
end
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
|
-
rule union_or_intersect_or_minus
|
66
|
-
(
|
67
|
-
union:union_all /
|
68
|
-
intersect:intersect_keyword /
|
69
|
-
minus:minus_keyword
|
70
|
-
) {
|
71
|
-
def ast
|
72
|
-
if respond_to? :union
|
73
|
-
union.ast
|
74
|
-
elsif respond_to? :intersect
|
75
|
-
OracleSqlParser::Ast::Array[intersect.ast]
|
76
|
-
elsif respond_to? :minus
|
77
|
-
OracleSqlParser::Ast::Array[minus.ast]
|
78
|
-
end
|
79
|
-
end
|
80
|
-
}
|
81
|
-
end
|
82
|
-
|
83
|
-
rule union_all
|
84
|
-
union_keyword all:(space all_keyword)? {
|
85
|
-
def ast
|
86
|
-
OracleSqlParser::Ast::Array[
|
87
|
-
union_keyword.ast,
|
88
|
-
all.try(:all_keyword).ast
|
89
|
-
]
|
90
|
-
end
|
91
|
-
}
|
92
|
-
end
|
93
|
-
|
94
|
-
rule query_block
|
95
|
-
(subquery_factoring_clause:subquery_factoring_clause space)?
|
96
|
-
select_keyword space
|
97
|
-
hint:hint?
|
98
|
-
mod:(modifier:(all_keyword / distinct_keyword / unique_keyword) space)?
|
99
|
-
select_list space
|
100
|
-
from_keyword
|
101
|
-
select:(space select_sources)?
|
102
|
-
where:(space where_clause)?
|
103
|
-
group:(space group_by_clause)?
|
104
|
-
model:(space model_clause)? {
|
105
|
-
def ast
|
106
|
-
OracleSqlParser::Ast::QueryBlock[
|
107
|
-
:hint => hint.ast,
|
108
|
-
:modifier => modifier.ast,
|
109
|
-
:select_list => select_list.ast,
|
110
|
-
:select_sources => select.try(:select_sources).ast,
|
111
|
-
:where_clause => where.try(:where_clause).ast,
|
112
|
-
:group_by_clause => group.try(:group_by_clause).ast,
|
113
|
-
:model_clause => model.try(:model_clause).ast]
|
114
|
-
end
|
115
|
-
|
116
|
-
def modifier
|
117
|
-
mod.modifier if mod.respond_to? :modifier
|
118
|
-
end
|
119
|
-
}
|
120
|
-
end
|
121
|
-
|
122
|
-
rule select_sources
|
123
|
-
select_source more:(space? ',' space? select_source)* {
|
124
|
-
def ast
|
125
|
-
OracleSqlParser::Ast::Array[
|
126
|
-
select_source.ast,
|
127
|
-
*more_select_sources.map(&:ast),
|
128
|
-
]
|
129
|
-
end
|
130
|
-
|
131
|
-
def more_select_sources
|
132
|
-
more.elements.map(&:select_source)
|
133
|
-
end
|
134
|
-
}
|
135
|
-
end
|
136
|
-
|
137
|
-
rule select_source
|
138
|
-
join_clause /
|
139
|
-
'(' space? join_clause:join_clause space? ')' /
|
140
|
-
table_reference /
|
141
|
-
subquery
|
142
|
-
{
|
143
|
-
def ast
|
144
|
-
if respond_to? :join_clause
|
145
|
-
join_clause.ast
|
146
|
-
else
|
147
|
-
super
|
148
|
-
end
|
149
|
-
end
|
150
|
-
}
|
151
|
-
end
|
152
|
-
|
153
|
-
rule join_clause
|
154
|
-
table_reference space
|
155
|
-
join:(
|
156
|
-
outer_join_clause /
|
157
|
-
inner_cross_join_clause
|
158
|
-
) {
|
159
|
-
def ast
|
160
|
-
result = join.ast
|
161
|
-
result.table1 = table_reference.ast
|
162
|
-
result
|
163
|
-
end
|
164
|
-
}
|
165
|
-
end
|
166
|
-
|
167
|
-
rule inner_cross_join_clause
|
168
|
-
inner_join_clause /
|
169
|
-
cross_join_clause {
|
170
|
-
def ast
|
171
|
-
super
|
172
|
-
end
|
173
|
-
}
|
174
|
-
end
|
175
|
-
|
176
|
-
rule inner_join_clause
|
177
|
-
inner_join space? table_reference space? on_or_using_clause {
|
178
|
-
def ast
|
179
|
-
OracleSqlParser::Ast::InnerJoinClause[
|
180
|
-
:inner => inner_join.inner_keyword.ast,
|
181
|
-
:join => inner_join.try(:join_keyword).ast,
|
182
|
-
:table2 => table_reference.ast,
|
183
|
-
:on_or_using_clause => on_or_using_clause.ast
|
184
|
-
]
|
185
|
-
end
|
186
|
-
}
|
187
|
-
end
|
188
|
-
|
189
|
-
rule inner_join
|
190
|
-
inner_keyword space? join_keyword
|
191
|
-
end
|
192
|
-
|
193
|
-
rule on_or_using_clause
|
194
|
-
on_clause /
|
195
|
-
using_clause {
|
196
|
-
def ast
|
197
|
-
super
|
198
|
-
end
|
199
|
-
}
|
200
|
-
end
|
201
|
-
|
202
|
-
rule on_clause
|
203
|
-
on_keyword space? condition {
|
204
|
-
def ast
|
205
|
-
OracleSqlParser::Ast::OnClause[
|
206
|
-
:on => on_keyword.ast,
|
207
|
-
:condition => condition.ast
|
208
|
-
]
|
209
|
-
end
|
210
|
-
}
|
211
|
-
end
|
212
|
-
|
213
|
-
rule using_clause
|
214
|
-
using_keyword space? '(' space? column_list space? ')' {
|
215
|
-
def ast
|
216
|
-
OracleSqlParser::Ast::UsingClause[
|
217
|
-
:using => using_keyword.ast,
|
218
|
-
:column_list => column_list.ast
|
219
|
-
]
|
220
|
-
end
|
221
|
-
}
|
222
|
-
end
|
223
|
-
|
224
|
-
rule cross_join_clause
|
225
|
-
cross_natural_join space table_reference {
|
226
|
-
def ast
|
227
|
-
OracleSqlParser::Ast::CrossNaturalJoinClause[
|
228
|
-
:cross => cross_natural_join.cross_keyword.ast,
|
229
|
-
:natural => cross_natural_join.natural_keyword.ast,
|
230
|
-
:inner => cross_natural_join.inner_keyword.ast,
|
231
|
-
:join => cross_natural_join.try(:join_keyword).ast,
|
232
|
-
:table2 => table_reference.ast
|
233
|
-
]
|
234
|
-
end
|
235
|
-
}
|
236
|
-
end
|
237
|
-
|
238
|
-
rule cross_natural_join
|
239
|
-
(
|
240
|
-
cross_keyword:cross_keyword /
|
241
|
-
natural_keyword:natural_keyword inner:(space inner_keyword)?
|
242
|
-
) space join_keyword {
|
243
|
-
|
244
|
-
def cross_keyword
|
245
|
-
elements.first.try(:cross_keyword)
|
246
|
-
end
|
247
|
-
|
248
|
-
def natural_keyword
|
249
|
-
elements.first.try(:natural_keyword)
|
250
|
-
end
|
251
|
-
|
252
|
-
def inner_keyword
|
253
|
-
elements.first.try(:inner).try(:inner_keyword)
|
254
|
-
end
|
255
|
-
}
|
256
|
-
end
|
257
|
-
|
258
|
-
rule column_list
|
259
|
-
column_name more:(space? ',' space? column_name)* {
|
260
|
-
def ast
|
261
|
-
OracleSqlParser::Ast::Array[
|
262
|
-
column_name.ast,
|
263
|
-
*more_column_names.map(&:ast)
|
264
|
-
]
|
265
|
-
end
|
266
|
-
|
267
|
-
def more_column_names
|
268
|
-
more.elements.map(&:column_name)
|
269
|
-
end
|
270
|
-
}
|
271
|
-
end
|
272
|
-
|
273
|
-
rule outer_join_clause
|
274
|
-
query_partition_clause?
|
275
|
-
join_type:(
|
276
|
-
natural_keyword:natural_keyword? space? outer_join_type:outer_join_type? space? join_keyword
|
277
|
-
) space
|
278
|
-
table_reference space
|
279
|
-
(query_partition_clause space)?
|
280
|
-
on_or_using_clause {
|
281
|
-
def ast
|
282
|
-
OracleSqlParser::Ast::OuterJoinClause[
|
283
|
-
:natural => join_type.try(:natural_keyword).ast,
|
284
|
-
:join_type => join_type.outer_join_type.try(:type).ast,
|
285
|
-
:outer => join_type.outer_join_type.try(:outer).ast,
|
286
|
-
:join => join_type.join_keyword.ast,
|
287
|
-
:table2 => table_reference.ast,
|
288
|
-
:on_or_using_clause => on_or_using_clause.ast
|
289
|
-
]
|
290
|
-
end
|
291
|
-
}
|
292
|
-
end
|
293
|
-
|
294
|
-
rule query_partition_clause
|
295
|
-
'query_partition_clause' {
|
296
|
-
def ast
|
297
|
-
'query_partition_clause' # do not supported
|
298
|
-
end
|
299
|
-
}
|
300
|
-
end
|
301
|
-
|
302
|
-
rule outer_join_type
|
303
|
-
type:(
|
304
|
-
full_keyword /
|
305
|
-
left_keyword /
|
306
|
-
right_keyword
|
307
|
-
) o:(space outer_keyword)? {
|
308
|
-
def outer
|
309
|
-
o.try(:outer_keyword)
|
310
|
-
end
|
311
|
-
}
|
312
|
-
end
|
313
|
-
|
314
|
-
rule for_update_clause
|
315
|
-
for_keyword space update_keyword
|
316
|
-
of:(space of_keyword space for_update_clause_columns)?
|
317
|
-
wait:(
|
318
|
-
space w:wait_keyword space time:integer /
|
319
|
-
space w:nowait_keyword
|
320
|
-
)? {
|
321
|
-
def ast
|
322
|
-
OracleSqlParser::Ast::ForUpdateClause[
|
323
|
-
:columns => of.try(:for_update_clause_columns).ast,
|
324
|
-
:wait => wait.try(:w).ast,
|
325
|
-
:time => wait.try(:time).ast
|
326
|
-
].remove_nil_values!
|
327
|
-
end
|
328
|
-
}
|
329
|
-
end
|
330
|
-
|
331
|
-
rule for_update_clause_columns
|
332
|
-
for_update_clause_column more:(space? ',' space? for_update_clause_column)* {
|
333
|
-
def ast
|
334
|
-
OracleSqlParser::Ast::Array[
|
335
|
-
for_update_clause_column.ast, *more_for_update_clause_columns.map(&:ast)
|
336
|
-
]
|
337
|
-
end
|
338
|
-
|
339
|
-
def more_for_update_clause_columns
|
340
|
-
more.elements.map(&:for_update_clause_column)
|
341
|
-
end
|
342
|
-
}
|
343
|
-
end
|
344
|
-
|
345
|
-
rule for_update_clause_column
|
346
|
-
(
|
347
|
-
schema_name space? '.' space? table_name space? '.' space? column_name /
|
348
|
-
table_name space? '.' space? column_name /
|
349
|
-
space? column_name
|
350
|
-
) {
|
351
|
-
def ast
|
352
|
-
OracleSqlParser::Ast::Identifier[:name => text_value]
|
353
|
-
end
|
354
|
-
}
|
355
|
-
end
|
356
|
-
|
357
|
-
rule subquery_factoring_clause
|
358
|
-
'subquery_factoring_clause' { # not implemented
|
359
|
-
def ast
|
360
|
-
'subquery_factoring_clause'
|
361
|
-
end
|
362
|
-
}
|
363
|
-
end
|
364
|
-
|
365
|
-
rule order_by_clause
|
366
|
-
order_keyword space siblings:siblings_keyword? space? by_keyword space order_by_clause_items {
|
367
|
-
def ast
|
368
|
-
OracleSqlParser::Ast::OrderByClause[
|
369
|
-
:siblings => siblings.ast,
|
370
|
-
:items => order_by_clause_items.ast
|
371
|
-
]
|
372
|
-
end
|
373
|
-
}
|
374
|
-
end
|
375
|
-
|
376
|
-
rule order_by_clause_items
|
377
|
-
order_by_clause_item
|
378
|
-
more:(space? ',' space? order_by_clause_item space?)* {
|
379
|
-
def ast
|
380
|
-
OracleSqlParser::Ast::Array[
|
381
|
-
order_by_clause_item.ast, *more_order_by_clause_items.map(&:ast)
|
382
|
-
]
|
383
|
-
end
|
384
|
-
|
385
|
-
def more_order_by_clause_items
|
386
|
-
more.elements.map(&:order_by_clause_item)
|
387
|
-
end
|
388
|
-
}
|
389
|
-
end
|
390
|
-
|
391
|
-
rule order_by_clause_item
|
392
|
-
target:(expr / position / c_alias) space?
|
393
|
-
asc:(asc_keyword / desc_keyword)? space?
|
394
|
-
null:(nulls_keyword space first_or_last:(first_keyword / last_keyword))? {
|
395
|
-
def ast
|
396
|
-
OracleSqlParser::Ast::OrderByClauseItem[
|
397
|
-
:target => target.ast,
|
398
|
-
:asc => asc.ast,
|
399
|
-
:nulls => nulls.ast
|
400
|
-
]
|
401
|
-
end
|
402
|
-
|
403
|
-
def nulls
|
404
|
-
if null.respond_to? :first_or_last
|
405
|
-
null.first_or_last
|
406
|
-
else
|
407
|
-
nil
|
408
|
-
end
|
409
|
-
end
|
410
|
-
}
|
411
|
-
end
|
412
|
-
|
413
|
-
rule select_list
|
414
|
-
select_one more_list:( space? ',' space? select_one)* {
|
415
|
-
def ast
|
416
|
-
OracleSqlParser::Ast::Array[select_one.ast, *more_columns.map(&:ast)]
|
417
|
-
end
|
418
|
-
|
419
|
-
def more_columns
|
420
|
-
more_list.elements.map(&:select_one)
|
421
|
-
end
|
422
|
-
}
|
423
|
-
end
|
424
|
-
|
425
|
-
rule select_one
|
426
|
-
select_table /
|
427
|
-
select_column
|
428
|
-
{
|
429
|
-
def ast
|
430
|
-
super
|
431
|
-
end
|
432
|
-
}
|
433
|
-
end
|
434
|
-
|
435
|
-
rule select_table
|
436
|
-
(table_name '.')? '*' {
|
437
|
-
def ast
|
438
|
-
OracleSqlParser::Ast::Identifier[:name => text_value]
|
439
|
-
end
|
440
|
-
}
|
441
|
-
end
|
442
|
-
|
443
|
-
rule select_column
|
444
|
-
expr _alias:( space as:( as_keyword space )? c_alias )? {
|
445
|
-
def ast
|
446
|
-
OracleSqlParser::Ast::SelectColumn[
|
447
|
-
:expr => expr.ast,
|
448
|
-
:as => as_keyword.ast,
|
449
|
-
:c_alias => c_alias.ast,
|
450
|
-
]
|
451
|
-
end
|
452
|
-
|
453
|
-
def c_alias
|
454
|
-
if _alias.respond_to? :c_alias
|
455
|
-
_alias.c_alias
|
456
|
-
end
|
457
|
-
end
|
458
|
-
|
459
|
-
def as_keyword
|
460
|
-
if respond_to? :_alias and _alias.respond_to? :as
|
461
|
-
_alias.as.as_keyword
|
462
|
-
end
|
463
|
-
end
|
464
|
-
}
|
465
|
-
end
|
466
|
-
|
467
|
-
# group
|
468
|
-
rule group_by_clause
|
469
|
-
group_keyword space by_keyword space target:group_column space?
|
470
|
-
t:(',' space? more_target:group_column space?)*
|
471
|
-
h:(having_keyword space condition:condition)? {
|
472
|
-
def ast
|
473
|
-
OracleSqlParser::Ast::GroupByClause[
|
474
|
-
:targets => OracleSqlParser::Ast::Array[
|
475
|
-
target.ast, *more_targets.map(&:ast)
|
476
|
-
],
|
477
|
-
:having => condition.ast
|
478
|
-
]
|
479
|
-
end
|
480
|
-
|
481
|
-
def more_targets
|
482
|
-
t.elements.map{|e| e.more_target}
|
483
|
-
end
|
484
|
-
|
485
|
-
def condition
|
486
|
-
if h.respond_to? :condition
|
487
|
-
h.condition
|
488
|
-
else
|
489
|
-
nil
|
490
|
-
end
|
491
|
-
end
|
492
|
-
}
|
493
|
-
end
|
494
|
-
|
495
|
-
rule group_column
|
496
|
-
(
|
497
|
-
expr /
|
498
|
-
rollup_cube_clause /
|
499
|
-
grouping_sets_clause
|
500
|
-
) {
|
501
|
-
def ast
|
502
|
-
super
|
503
|
-
end
|
504
|
-
}
|
505
|
-
end
|
506
|
-
|
507
|
-
rule rollup_cube_clause
|
508
|
-
func_name:(rollup_keyword / cube_keyword) space? grouping_expression_list {
|
509
|
-
def ast
|
510
|
-
OracleSqlParser::Ast::RollupCubeClause[
|
511
|
-
:func_name => func_name.ast,
|
512
|
-
:args => grouping_expression_list.ast
|
513
|
-
]
|
514
|
-
end
|
515
|
-
}
|
516
|
-
end
|
517
|
-
|
518
|
-
rule grouping_sets_clause
|
519
|
-
'grouping_sets_clause' { # not implemented
|
520
|
-
def ast
|
521
|
-
'grouping_sets_clause'
|
522
|
-
end
|
523
|
-
}
|
524
|
-
end
|
525
|
-
|
526
|
-
rule grouping_expression_list
|
527
|
-
expression_list {
|
528
|
-
def ast
|
529
|
-
super
|
530
|
-
end
|
531
|
-
}
|
532
|
-
end
|
533
|
-
|
534
|
-
rule model_clause
|
535
|
-
'model_clause' {
|
536
|
-
def ast
|
537
|
-
'model_clause'
|
538
|
-
end
|
539
37
|
}
|
540
38
|
end
|
541
39
|
end
|