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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/HISTORY.md +6 -0
  4. data/Rakefile +3 -11
  5. data/lib/oracle-sql-parser/ast.rb +5 -1
  6. data/lib/oracle-sql-parser/ast/cursor_expression.rb +13 -0
  7. data/lib/oracle-sql-parser/ast/datetime_expression.rb +8 -0
  8. data/lib/oracle-sql-parser/ast/interval_expression.rb +27 -0
  9. data/lib/oracle-sql-parser/ast/{simple_comparision_condition.rb → simple_comparison_condition.rb} +1 -1
  10. data/lib/oracle-sql-parser/ast/timezone_clause.rb +8 -0
  11. data/lib/oracle-sql-parser/grammar.rb +24 -0
  12. data/lib/oracle-sql-parser/grammar/condition.treetop +12 -289
  13. data/lib/oracle-sql-parser/grammar/condition/between.treetop +20 -0
  14. data/lib/oracle-sql-parser/grammar/condition/comparison.treetop +32 -0
  15. data/lib/oracle-sql-parser/grammar/condition/compound.treetop +11 -0
  16. data/lib/oracle-sql-parser/grammar/condition/exists.treetop +13 -0
  17. data/lib/oracle-sql-parser/grammar/condition/floating_point.treetop +20 -0
  18. data/lib/oracle-sql-parser/grammar/condition/in.treetop +19 -0
  19. data/lib/oracle-sql-parser/grammar/condition/is_of_type.treetop +56 -0
  20. data/lib/oracle-sql-parser/grammar/condition/multiset.treetop +85 -0
  21. data/lib/oracle-sql-parser/grammar/condition/null.treetop +17 -0
  22. data/lib/oracle-sql-parser/grammar/condition/pattern_matching.treetop +47 -0
  23. data/lib/oracle-sql-parser/grammar/delete.treetop +2 -10
  24. data/lib/oracle-sql-parser/grammar/expression.treetop +39 -214
  25. data/lib/oracle-sql-parser/grammar/expression/case.treetop +77 -0
  26. data/lib/oracle-sql-parser/grammar/expression/compound.treetop +22 -0
  27. data/lib/oracle-sql-parser/grammar/expression/cursor.treetop +15 -0
  28. data/lib/oracle-sql-parser/grammar/expression/datetime.treetop +36 -0
  29. data/lib/oracle-sql-parser/grammar/expression/function.treetop +47 -0
  30. data/lib/oracle-sql-parser/grammar/expression/interval.treetop +47 -0
  31. data/lib/oracle-sql-parser/grammar/expression/simple.treetop +29 -0
  32. data/lib/oracle-sql-parser/grammar/grammar.treetop +1 -1
  33. data/lib/oracle-sql-parser/grammar/reserved_word_generator.rb +14 -2
  34. data/lib/oracle-sql-parser/grammar/select.treetop +11 -513
  35. data/lib/oracle-sql-parser/grammar/select/for_update.treetop +48 -0
  36. data/lib/oracle-sql-parser/grammar/select/group.treetop +62 -0
  37. data/lib/oracle-sql-parser/grammar/select/join.treetop +165 -0
  38. data/lib/oracle-sql-parser/grammar/select/order.treetop +43 -0
  39. data/lib/oracle-sql-parser/grammar/select/query_block.treetop +116 -0
  40. data/lib/oracle-sql-parser/grammar/select/union.treetop +48 -0
  41. data/lib/oracle-sql-parser/grammar/update.treetop +1 -1
  42. data/lib/oracle-sql-parser/version.rb +1 -1
  43. data/oracle-sql-parser.gemspec +1 -0
  44. metadata +55 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c22d14e6cc145a7909642ce9fbf5ee1ed4505dce
4
- data.tar.gz: bcbf3e19c992400efb172bc4991cd10cae160b03
3
+ metadata.gz: 06f11ebfa70f31aa92b69ef030d96237fc3260da
4
+ data.tar.gz: cbed0b80bfeb24be973d852c87746a982a7b5c6a
5
5
  SHA512:
6
- metadata.gz: 26aa6a1d48cae2f2d7e75cc1913fcdd55bdd423a3d90136978d490d466e118a8e573759c80ce5217ebc8fefe18338360f053b2fd98aecb713dfcf351574ffaf9
7
- data.tar.gz: 2ea9c404658076bc7c69a1c9ac74ed7b59a365ba738ac78364b400a8cfd90a09485996900a0e14809469c8915998e51e071990cc51eae8967b33c7889c266fb8
6
+ metadata.gz: 686cb870a07ec984d265515e38a65fa8d106ded9e65c92d2e1bf256940bbde33f908d26a533da1de96b97867ca5cfaf6b89f566659a5587fd59622dc3b45f117
7
+ data.tar.gz: 4c39e070b5d14881aaa806d32f17cab0e3f6adb7393f35bb93126f6a9b5c5dd4e9c456dd726f877cbad251f81f245d6ec78a919db3ae4a0dba8a5f27bb282c6a
data/.gitignore CHANGED
@@ -8,13 +8,16 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  lib/oracle-sql-parser/grammar/condition.rb
11
+ lib/oracle-sql-parser/grammar/condition/*.rb
11
12
  lib/oracle-sql-parser/grammar/delete.rb
12
13
  lib/oracle-sql-parser/grammar/expression.rb
14
+ lib/oracle-sql-parser/grammar/expression/*.rb
13
15
  lib/oracle-sql-parser/grammar/grammar.rb
14
16
  lib/oracle-sql-parser/grammar/insert.rb
15
17
  lib/oracle-sql-parser/grammar/reserved_word.rb
16
18
  lib/oracle-sql-parser/grammar/reserved_word.treetop
17
19
  lib/oracle-sql-parser/grammar/select.rb
20
+ lib/oracle-sql-parser/grammar/select/*.rb
18
21
  lib/oracle-sql-parser/grammar/update.rb
19
22
  test/oracle_enhanced-adapter/connection_params.yml
20
23
  *.sw?
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.9.0
2
+ * Syntax
3
+ * added cursor expression
4
+ * added datetime expression
5
+ * added interval expression
6
+
1
7
  ### 0.8.1
2
8
  * Fix README.md
3
9
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require "bundler/gem_tasks"
2
2
  require 'rake'
3
3
  require 'rake/testtask'
4
4
 
5
- GRAMMAR_FILES = FileList['lib/oracle-sql-parser/grammar/*.treetop']
5
+ GRAMMAR_FILES = FileList['lib/oracle-sql-parser/grammar/**/*.treetop']
6
6
 
7
7
  desc "generate parser files"
8
8
  task :gen do
@@ -30,16 +30,8 @@ end
30
30
  Rake::TestTask.new do |t|
31
31
  t.libs << "test"
32
32
  t.test_files = FileList[
33
- 'test/grammar/select_test.rb',
34
- 'test/grammar/update_test.rb',
35
- 'test/grammar/expression_test.rb',
36
- 'test/grammar/condition_test.rb',
37
- 'test/grammar/delete_test.rb',
38
- 'test/grammar/insert_test.rb',
39
- 'test/ast/replace_literal_test.rb',
40
- 'test/ast/number_literal_test.rb',
41
- 'test/ast/text_literal_test.rb',
42
- 'test/ast/text_literal_test.rb',
33
+ 'test/grammar/*_test.rb',
34
+ 'test/ast/*_test.rb',
43
35
  'test/oracle_enhanced-adapter/select_test.rb'
44
36
  ]
45
37
  t.verbose = true
@@ -17,7 +17,7 @@ require 'oracle-sql-parser/ast/on_clause.rb'
17
17
  require 'oracle-sql-parser/ast/using_clause.rb'
18
18
  require 'oracle-sql-parser/ast/cross_natural_join_clause.rb'
19
19
  require 'oracle-sql-parser/ast/where_clause.rb'
20
- require 'oracle-sql-parser/ast/simple_comparision_condition.rb'
20
+ require 'oracle-sql-parser/ast/simple_comparison_condition.rb'
21
21
  require 'oracle-sql-parser/ast/logical_condition.rb'
22
22
  require 'oracle-sql-parser/ast/like_condition.rb'
23
23
  require 'oracle-sql-parser/ast/regexp_condition.rb'
@@ -45,6 +45,10 @@ require 'oracle-sql-parser/ast/compound_expression.rb'
45
45
  require 'oracle-sql-parser/ast/simple_case_expression.rb'
46
46
  require 'oracle-sql-parser/ast/searched_case_expression.rb'
47
47
  require 'oracle-sql-parser/ast/function_expression.rb'
48
+ require 'oracle-sql-parser/ast/cursor_expression.rb'
49
+ require 'oracle-sql-parser/ast/datetime_expression.rb'
50
+ require 'oracle-sql-parser/ast/interval_expression.rb'
51
+ require 'oracle-sql-parser/ast/timezone_clause.rb'
48
52
  require 'oracle-sql-parser/ast/current_of.rb'
49
53
  require 'oracle-sql-parser/ast/delete_statement.rb'
50
54
  require 'oracle-sql-parser/ast/delete_target.rb'
@@ -0,0 +1,13 @@
1
+ module OracleSqlParser::Ast
2
+ class CursorExpression < Hash
3
+ def to_sql(options = {})
4
+ [
5
+ @ast[:cursor],
6
+ '(',
7
+ @ast[:subquery],
8
+ ')',
9
+ ].map(&:to_sql).join
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,8 @@
1
+ module OracleSqlParser::Ast
2
+ class DatetimeExpression < Hash
3
+ def to_sql(options = {})
4
+ @ast.values_at(:expr, :at, :local, :timezone).compact.map(&:to_sql).join(' ')
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,27 @@
1
+ module OracleSqlParser::Ast
2
+ class IntervalExpression < Hash
3
+ def to_sql(options = {})
4
+ result = []
5
+ result << '('
6
+ result << @ast[:left]
7
+ result << '-'
8
+ result << @ast[:right]
9
+ result << ')'
10
+ result << (@ast[:day] || @ast[:year])
11
+ if @ast[:leading_field_precision]
12
+ result << '('
13
+ result << @ast[:leading_field_precision]
14
+ result << ')'
15
+ end
16
+ result << @ast[:to]
17
+ result << (@ast[:second] || @ast[:month])
18
+ if @ast[:fractional_second_precision]
19
+ result << '('
20
+ result << @ast[:fractional_second_precision]
21
+ result << ')'
22
+ end
23
+ result.compact.map(&:to_sql).join(' ')
24
+ end
25
+ end
26
+ end
27
+
@@ -1,5 +1,5 @@
1
1
  module OracleSqlParser::Ast
2
- class SimpleComparisionCondition < Hash
2
+ class SimpleComparisonCondition < Hash
3
3
  def to_sql(options ={})
4
4
  @ast.values_at(:left, :op, :right).map(&:to_sql).join(' ')
5
5
  end
@@ -0,0 +1,8 @@
1
+ module OracleSqlParser::Ast
2
+ class TimezoneClause < Hash
3
+ def to_sql(options = {})
4
+ @ast.values_at(:time, :zone, :expr).map(&:to_sql).join(' ')
5
+ end
6
+ end
7
+ end
8
+
@@ -1,8 +1,32 @@
1
1
  module OracleSqlParser::Grammar
2
2
  end
3
3
  require "oracle-sql-parser/grammar/reserved_word.rb"
4
+ require "oracle-sql-parser/grammar/expression/simple.rb"
5
+ require "oracle-sql-parser/grammar/expression/compound.rb"
6
+ require "oracle-sql-parser/grammar/expression/function.rb"
7
+ require "oracle-sql-parser/grammar/expression/case.rb"
8
+ require "oracle-sql-parser/grammar/expression/simple.rb"
9
+ require "oracle-sql-parser/grammar/expression/cursor.rb"
10
+ require "oracle-sql-parser/grammar/expression/datetime.rb"
11
+ require "oracle-sql-parser/grammar/expression/interval.rb"
4
12
  require "oracle-sql-parser/grammar/expression.rb"
13
+ require "oracle-sql-parser/grammar/condition/comparison.rb"
14
+ require "oracle-sql-parser/grammar/condition/floating_point.rb"
15
+ require "oracle-sql-parser/grammar/condition/multiset.rb"
16
+ require "oracle-sql-parser/grammar/condition/pattern_matching.rb"
17
+ require "oracle-sql-parser/grammar/condition/null.rb"
18
+ require "oracle-sql-parser/grammar/condition/compound.rb"
19
+ require "oracle-sql-parser/grammar/condition/between.rb"
20
+ require "oracle-sql-parser/grammar/condition/exists.rb"
21
+ require "oracle-sql-parser/grammar/condition/in.rb"
22
+ require "oracle-sql-parser/grammar/condition/is_of_type.rb"
5
23
  require "oracle-sql-parser/grammar/condition.rb"
24
+ require "oracle-sql-parser/grammar/select/group.rb"
25
+ require "oracle-sql-parser/grammar/select/order.rb"
26
+ require "oracle-sql-parser/grammar/select/join.rb"
27
+ require "oracle-sql-parser/grammar/select/for_update.rb"
28
+ require "oracle-sql-parser/grammar/select/union.rb"
29
+ require "oracle-sql-parser/grammar/select/query_block.rb"
6
30
  require "oracle-sql-parser/grammar/select.rb"
7
31
  require "oracle-sql-parser/grammar/update.rb"
8
32
  require "oracle-sql-parser/grammar/delete.rb"
@@ -1,5 +1,16 @@
1
1
  module OracleSqlParser::Grammar
2
2
  grammar Condition
3
+ include OracleSqlParser::Grammar::Condition::Comparison
4
+ include OracleSqlParser::Grammar::Condition::FloatingPoint
5
+ include OracleSqlParser::Grammar::Condition::Multiset
6
+ include OracleSqlParser::Grammar::Condition::PatternMatching
7
+ include OracleSqlParser::Grammar::Condition::Null
8
+ include OracleSqlParser::Grammar::Condition::Compound
9
+ include OracleSqlParser::Grammar::Condition::Between
10
+ include OracleSqlParser::Grammar::Condition::Exists
11
+ include OracleSqlParser::Grammar::Condition::In
12
+ include OracleSqlParser::Grammar::Condition::IsOfType
13
+
3
14
  # where
4
15
  rule where_clause
5
16
  where_keyword space? logical_condition {
@@ -10,7 +21,7 @@ module OracleSqlParser::Grammar
10
21
  end
11
22
 
12
23
  rule condition
13
- comparision_condition /
24
+ comparison_condition /
14
25
  floating_point_condition /
15
26
  model_condition /
16
27
  mutiset_condition /
@@ -54,301 +65,13 @@ module OracleSqlParser::Grammar
54
65
  }
55
66
  end
56
67
 
57
- rule comparision_condition
58
- (
59
- simple_comparision_condition /
60
- group_comparision_condition
61
- ) {
62
- def ast
63
- super
64
- end
65
- }
66
- end
67
-
68
- rule group_comparision_condition
69
- 'group_comparision_condition'
70
- end
71
-
72
- rule simple_comparision_condition
73
- (
74
- left:expr space? op:('!=' / '^=' / '<>' / '>=' / '<=' / '=' / '>' / '<') space? right:expr /
75
- '(' space? left:exprs space? ')' op:space? ('!=' / '^=' / '<>' / '=') space? '(' space? right:subquery space? ')'
76
- ) {
77
- def ast
78
- OracleSqlParser::Ast::SimpleComparisionCondition[
79
- :left => left.ast,
80
- :op => op.text_value,
81
- :right => right.ast]
82
- end
83
- }
84
- end
85
-
86
- rule floating_point_condition
87
- expr space? is_keyword space? not_keyword:not_keyword? space?
88
- value:(
89
- nan_keyword /
90
- infinite_keyword
91
- ) {
92
- def ast
93
- OracleSqlParser::Ast::FloatingPointCondition[
94
- :target => expr.ast,
95
- :is => is_keyword.ast,
96
- :not => not_keyword.ast,
97
- :value => value.ast
98
- ]
99
- end
100
- }
101
- end
102
-
103
68
  rule model_condition
104
69
  'model_condition'
105
70
  end
106
71
 
107
- rule mutiset_condition
108
- is_a_set_condition /
109
- is_empty_condition /
110
- member_condition /
111
- submultiset_condition {
112
- def ast
113
- super
114
- end
115
- }
116
- end
117
-
118
- rule nested_table
119
- ident {
120
- def ast
121
- super
122
- end
123
- }
124
- end
125
-
126
- rule is_a_set_condition
127
- nested_table space? is_keyword space? not_keyword:not_keyword? space? a:[Aa] space? set_keyword {
128
- def ast
129
- OracleSqlParser::Ast::IsASetCondition[
130
- :target => nested_table.ast,
131
- :is => is_keyword.ast,
132
- :not => not_keyword.ast,
133
- :a => OracleSqlParser::Ast::Keyword[:name => a.text_value],
134
- :set => set_keyword.ast
135
- ]
136
- end
137
- }
138
- end
139
-
140
- rule is_empty_condition
141
- nested_table space? is_keyword space? not_keyword:not_keyword? space? empty_keyword {
142
- def ast
143
- OracleSqlParser::Ast::IsEmptyCondition[
144
- :target => nested_table.ast,
145
- :is => is_keyword.ast,
146
- :not => not_keyword.ast,
147
- :empty => empty_keyword.ast
148
- ]
149
- end
150
- }
151
- end
152
-
153
- rule member_condition
154
- expr space? not_keyword:not_keyword? space? member_keyword space? of_keyword space? nested_table {
155
- def ast
156
- OracleSqlParser::Ast::MemberCondition[
157
- :target => expr.ast,
158
- :not => not_keyword.ast,
159
- :member => member_keyword.ast,
160
- :of => of_keyword.ast,
161
- :table => nested_table.ast
162
- ]
163
- end
164
- }
165
- end
166
-
167
- rule submultiset_condition
168
- table1:nested_table space?
169
- not_keyword:not_keyword? space?
170
- submultiset_keyword space?
171
- of_keyword:of_keyword? space?
172
- table2:nested_table {
173
- def ast
174
- OracleSqlParser::Ast::SubmultisetCondition[
175
- :target => table1.ast,
176
- :not => not_keyword.ast,
177
- :submultiset => submultiset_keyword.ast,
178
- :of => of_keyword.ast,
179
- :table => table2.ast
180
- ]
181
- end
182
- }
183
- end
184
-
185
- rule pattern_maching_condition
186
- (
187
- like_condition /
188
- regexp_like_condition
189
- ) {
190
- def ast
191
- super
192
- end
193
- }
194
- end
195
-
196
- rule like_condition
197
- target:ident space
198
- n:(not_keyword:not_keyword space)?
199
- like:(like_keyword / like2_keyword / like4_keyword / likec_keyword) space
200
- text:text_literal
201
- e:(space escape_keyword space escape_text:text_literal)? {
202
- def ast
203
- OracleSqlParser::Ast::LikeCondition[
204
- :target => target.ast,
205
- :not => not_keyword.ast,
206
- :like => like.ast,
207
- :text => text.ast,
208
- :escape => escape_text.ast]
209
- end
210
-
211
- def not_keyword
212
- n.elements && n.elements.first
213
- end
214
-
215
- def escape_text
216
- if e.respond_to? :escape_text
217
- e.escape_text
218
- end
219
- end
220
- }
221
- end
222
-
223
- rule regexp_like_condition
224
- regexp_like_keyword '(' space? target:ident space? ',' space? regexp:text_literal space? ')' {
225
- def ast
226
- OracleSqlParser::Ast::RegexpCondition[
227
- :target => target.ast,
228
- :regexp => regexp.ast]
229
- end
230
- }
231
- end
232
-
233
- rule null_condition
234
- expr space is_keyword space n:(not_keyword space)? null_keyword {
235
- def ast
236
- OracleSqlParser::Ast::NullCondition[
237
- :target => expr.ast,
238
- :not => not_keyword.ast]
239
- end
240
-
241
- def not_keyword
242
- n.elements && n.elements.first
243
- end
244
- }
245
- end
246
-
247
72
  rule xml_condition
248
73
  'xml_condition'
249
74
  end
250
75
 
251
- rule compound_condition
252
- '(' logical_condition ')' {
253
- def ast
254
- OracleSqlParser::Ast::CompoundCondition[:condition => logical_condition.ast]
255
- end
256
- }
257
- end
258
-
259
- rule between_condition
260
- target:expr space n:(not_keyword space)? between_keyword space from:expr space and_keyword space to:expr {
261
- def ast
262
- OracleSqlParser::Ast::BetweenCondition[
263
- :target => target.ast,
264
- :not => not_keyword.ast,
265
- :from => from.ast,
266
- :to => to.ast
267
- ]
268
- end
269
-
270
- def not_keyword
271
- n.elements && n.elements.first
272
- end
273
- }
274
- end
275
-
276
- rule exists_condition
277
- exists_keyword space? '(' space? subquery space? ')' {
278
- def ast
279
- OracleSqlParser::Ast::ExistsCondition[
280
- :target => subquery.ast
281
- ]
282
- end
283
- }
284
- end
285
-
286
- rule in_condition
287
- target:expr space n:(not_keyword space)? in_keyword space? '(' space? values:( exprs / subquery ) space? ')' {
288
- def ast
289
- OracleSqlParser::Ast::InCondition[
290
- :target => target.ast,
291
- :not => not_keyword.ast,
292
- :values => values.ast
293
- ]
294
- end
295
-
296
- def not_keyword
297
- n.elements && n.elements.first
298
- end
299
- }
300
- end
301
-
302
- rule is_of_type_condition
303
- expr space?
304
- is_keyword space?
305
- not_keyword:not_keyword? space?
306
- of_keyword space?
307
- type_keyword:type_keyword? space?
308
- '(' space? types space? ')' {
309
- def ast
310
- OracleSqlParser::Ast::IsOfTypeCondition[
311
- :target => expr.ast,
312
- :is => is_keyword.ast,
313
- :not => not_keyword.ast,
314
- :of => of_keyword.ast,
315
- :type => type_keyword.ast,
316
- :types => types.ast
317
- ]
318
- end
319
- }
320
- end
321
-
322
- rule types
323
- only_and_type space? more:(',' space? only_and_type space?)* {
324
- def ast
325
- OracleSqlParser::Ast::Array[only_and_type.ast, *more_only_and_types.map(&:ast)]
326
- end
327
-
328
- def more_only_and_types
329
- more.elements.map(&:only_and_type)
330
- end
331
- }
332
- end
333
-
334
- rule only_and_type
335
- only_keyword:only_keyword? space? type {
336
- def ast
337
- OracleSqlParser::Ast::OnlyAndType[
338
- :only => only_keyword.ast,
339
- :type => type.ast
340
- ]
341
- end
342
- }
343
- end
344
-
345
- rule type
346
- schema_name '.' ident /
347
- ident {
348
- def ast
349
- OracleSqlParser::Ast::Identifier[:name => text_value]
350
- end
351
- }
352
- end
353
76
  end
354
77
  end