oracle-sql-parser 0.9.2 → 1.1.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 (57) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +213 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +66 -3
  5. data/Rakefile +62 -10
  6. data/lib/oracle-sql-parser/ast/fetch.rb +12 -0
  7. data/lib/oracle-sql-parser/ast/number_literal.rb +1 -1
  8. data/lib/oracle-sql-parser/ast/offset.rb +11 -0
  9. data/lib/oracle-sql-parser/ast/row_limiting_clause.rb +10 -0
  10. data/lib/oracle-sql-parser/ast/subquery.rb +8 -4
  11. data/lib/oracle-sql-parser/ast.rb +3 -0
  12. data/lib/oracle-sql-parser/grammar/condition/between.rb +5 -3
  13. data/lib/oracle-sql-parser/grammar/condition/comparison.rb +5 -3
  14. data/lib/oracle-sql-parser/grammar/condition/comparison.treetop +1 -0
  15. data/lib/oracle-sql-parser/grammar/condition/compound.rb +5 -3
  16. data/lib/oracle-sql-parser/grammar/condition/exists.rb +5 -3
  17. data/lib/oracle-sql-parser/grammar/condition/floating_point.rb +5 -3
  18. data/lib/oracle-sql-parser/grammar/condition/in.rb +5 -3
  19. data/lib/oracle-sql-parser/grammar/condition/is_of_type.rb +5 -3
  20. data/lib/oracle-sql-parser/grammar/condition/multiset.rb +5 -3
  21. data/lib/oracle-sql-parser/grammar/condition/null.rb +5 -3
  22. data/lib/oracle-sql-parser/grammar/condition/pattern_matching.rb +5 -3
  23. data/lib/oracle-sql-parser/grammar/condition.rb +5 -3
  24. data/lib/oracle-sql-parser/grammar/delete.rb +5 -3
  25. data/lib/oracle-sql-parser/grammar/expression/case.rb +5 -3
  26. data/lib/oracle-sql-parser/grammar/expression/compound.rb +5 -3
  27. data/lib/oracle-sql-parser/grammar/expression/cursor.rb +5 -3
  28. data/lib/oracle-sql-parser/grammar/expression/datetime.rb +5 -3
  29. data/lib/oracle-sql-parser/grammar/expression/function.rb +5 -3
  30. data/lib/oracle-sql-parser/grammar/expression/interval.rb +5 -3
  31. data/lib/oracle-sql-parser/grammar/expression/simple.rb +5 -3
  32. data/lib/oracle-sql-parser/grammar/expression.rb +5 -27
  33. data/lib/oracle-sql-parser/grammar/expression.treetop +0 -4
  34. data/lib/oracle-sql-parser/grammar/grammar.rb +5 -29
  35. data/lib/oracle-sql-parser/grammar/grammar.treetop +0 -8
  36. data/lib/oracle-sql-parser/grammar/insert.rb +5 -3
  37. data/lib/oracle-sql-parser/grammar/reserved_word.rb +662 -42
  38. data/lib/oracle-sql-parser/grammar/reserved_word.treetop +1150 -0
  39. data/lib/oracle-sql-parser/grammar/reserved_word_generator.rb +7 -1
  40. data/lib/oracle-sql-parser/grammar/select/for_update.rb +5 -3
  41. data/lib/oracle-sql-parser/grammar/select/group.rb +5 -3
  42. data/lib/oracle-sql-parser/grammar/select/join.rb +5 -3
  43. data/lib/oracle-sql-parser/grammar/select/order.rb +5 -3
  44. data/lib/oracle-sql-parser/grammar/select/query_block.rb +5 -3
  45. data/lib/oracle-sql-parser/grammar/select/row_limit.rb +407 -0
  46. data/lib/oracle-sql-parser/grammar/select/row_limit.treetop +49 -0
  47. data/lib/oracle-sql-parser/grammar/select/union.rb +5 -3
  48. data/lib/oracle-sql-parser/grammar/select.rb +46 -5
  49. data/lib/oracle-sql-parser/grammar/select.treetop +4 -1
  50. data/lib/oracle-sql-parser/grammar/update.rb +5 -3
  51. data/lib/oracle-sql-parser/grammar.rb +1 -0
  52. data/lib/oracle-sql-parser/version.rb +1 -1
  53. data/oracle-sql-parser.gemspec +14 -12
  54. metadata +40 -53
  55. data/.gitignore +0 -24
  56. data/Gemfile +0 -4
  57. data/HISTORY.md +0 -70
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 14516df0bf4d0246870b6c5562a6d15ad728d722
4
- data.tar.gz: d065209079f19de48af5fff9b16084b2218303ea
2
+ SHA256:
3
+ metadata.gz: 799c6ff0310cf192261588ddf5ba07eb0aac1b5034b369b8dbbdf15d7decd9aa
4
+ data.tar.gz: b67a6a2237d6e7651ee4697e88dd2f4f6fd284ce840e25cdb186e15f9fff28f9
5
5
  SHA512:
6
- metadata.gz: ac8b4437bc7d8c1128cfe3301a81962006813c17d6f8ec71ea12ebc4499188d8835a82c9e438229b936928f2c531668f8b477fef1b04b0213b686d1a59db3cb1
7
- data.tar.gz: 94e34a58144479026131f0b75ead2f38fb6ce80caadac5bbd4078621d05eabf5c337734a0b4aea2d47146a79ee9ecd28d1dee161e908f7108d6b9ed30dcc5b59
6
+ metadata.gz: 3e528a35215101f8475613ac2fdafa5408db2d91f58c9b01caa06a03e7556d13f3eb3752ec7ad2eedae3ea52e9e0b558c24d68ed6c341ac03de5f3fbc0663f4f
7
+ data.tar.gz: 06b56b949569df4b737af0edb00b29ab71daad9ef14711775c3ff09a9750f4367ac1b9bc2ddf2e1f169c2743de3cb853ca0dea1073df5faa43de8c2b910c8972
data/CHANGELOG.md ADDED
@@ -0,0 +1,213 @@
1
+ # Changelog
2
+
3
+ > This file covers releases up to v1.0.0 and is no longer updated. Release
4
+ > notes for later versions live on
5
+ > [GitHub Releases](https://github.com/jksy/sql_parser/releases).
6
+
7
+ ## [v1.0.0](https://github.com/jksy/sql_parser/tree/v1.0.0) (2020-02-28)
8
+
9
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.9.2...v1.0.0)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - version 1.0.0 [\#22](https://github.com/jksy/sql_parser/pull/22) ([jksy](https://github.com/jksy))
14
+ - Feature/support rails5 [\#21](https://github.com/jksy/sql_parser/pull/21) ([jksy](https://github.com/jksy))
15
+ - v0.9.2 [\#20](https://github.com/jksy/sql_parser/pull/20) ([jksy](https://github.com/jksy))
16
+
17
+ ## [v0.9.2](https://github.com/jksy/sql_parser/tree/v0.9.2) (2017-12-28)
18
+
19
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.9.1...v0.9.2)
20
+
21
+ **Merged pull requests:**
22
+
23
+ - fix method not found "keys" on hash [\#19](https://github.com/jksy/sql_parser/pull/19) ([jksy](https://github.com/jksy))
24
+ - Feature/update ruby versions [\#18](https://github.com/jksy/sql_parser/pull/18) ([jksy](https://github.com/jksy))
25
+
26
+ ## [v0.9.1](https://github.com/jksy/sql_parser/tree/v0.9.1) (2017-09-18)
27
+
28
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.9.0...v0.9.1)
29
+
30
+ **Closed issues:**
31
+
32
+ - Three or more ANDs in WHERE clause fails parsing [\#16](https://github.com/jksy/sql_parser/issues/16)
33
+
34
+ **Merged pull requests:**
35
+
36
+ - fix https://github.com/jksy/sql\_parser/issues/16 [\#17](https://github.com/jksy/sql_parser/pull/17) ([jksy](https://github.com/jksy))
37
+ - ruby 2.4.1 [\#15](https://github.com/jksy/sql_parser/pull/15) ([jksy](https://github.com/jksy))
38
+
39
+ ## [v0.9.0](https://github.com/jksy/sql_parser/tree/v0.9.0) (2016-09-03)
40
+
41
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.8.1...v0.9.0)
42
+
43
+ **Closed issues:**
44
+
45
+ - Parser fails when parsing table aliases. [\#8](https://github.com/jksy/sql_parser/issues/8)
46
+
47
+ **Merged pull requests:**
48
+
49
+ - release v0.9.0 [\#14](https://github.com/jksy/sql_parser/pull/14) ([jksy](https://github.com/jksy))
50
+ - Feature/expression [\#13](https://github.com/jksy/sql_parser/pull/13) ([jksy](https://github.com/jksy))
51
+
52
+ ## [v0.8.1](https://github.com/jksy/sql_parser/tree/v0.8.1) (2016-08-14)
53
+
54
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.8.0...v0.8.1)
55
+
56
+ ## [v0.8.0](https://github.com/jksy/sql_parser/tree/v0.8.0) (2016-08-14)
57
+
58
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.7.0...v0.8.0)
59
+
60
+ **Merged pull requests:**
61
+
62
+ - Feature/compound expression [\#11](https://github.com/jksy/sql_parser/pull/11) ([jksy](https://github.com/jksy))
63
+ - Feature/subqueries [\#10](https://github.com/jksy/sql_parser/pull/10) ([jksy](https://github.com/jksy))
64
+
65
+ ## [v0.7.0](https://github.com/jksy/sql_parser/tree/v0.7.0) (2016-07-02)
66
+
67
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.6.0...v0.7.0)
68
+
69
+ **Merged pull requests:**
70
+
71
+ - added table alias syntax [\#9](https://github.com/jksy/sql_parser/pull/9) ([jksy](https://github.com/jksy))
72
+
73
+ ## [v0.6.0](https://github.com/jksy/sql_parser/tree/v0.6.0) (2016-01-13)
74
+
75
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.5.1...v0.6.0)
76
+
77
+ ## [v0.5.1](https://github.com/jksy/sql_parser/tree/v0.5.1) (2016-01-02)
78
+
79
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.5.0...v0.5.1)
80
+
81
+ **Merged pull requests:**
82
+
83
+ - Support rails query [\#7](https://github.com/jksy/sql_parser/pull/7) ([jksy](https://github.com/jksy))
84
+ - Fix spell [\#6](https://github.com/jksy/sql_parser/pull/6) ([jksy](https://github.com/jksy))
85
+ - added Travis-CI [\#5](https://github.com/jksy/sql_parser/pull/5) ([jksy](https://github.com/jksy))
86
+ - refactor gemspec [\#4](https://github.com/jksy/sql_parser/pull/4) ([jksy](https://github.com/jksy))
87
+ - added history.md [\#3](https://github.com/jksy/sql_parser/pull/3) ([jksy](https://github.com/jksy))
88
+
89
+ ## [v0.5.0](https://github.com/jksy/sql_parser/tree/v0.5.0) (2015-12-28)
90
+
91
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.4.0...v0.5.0)
92
+
93
+ **Merged pull requests:**
94
+
95
+ - added NumberLiteral\#to\_cecimal, TextLiteral\#to\_s [\#2](https://github.com/jksy/sql_parser/pull/2) ([jksy](https://github.com/jksy))
96
+
97
+ ## [v0.4.0](https://github.com/jksy/sql_parser/tree/v0.4.0) (2015-09-01)
98
+
99
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.3.1...v0.4.0)
100
+
101
+ ## [v0.3.1](https://github.com/jksy/sql_parser/tree/v0.3.1) (2015-08-27)
102
+
103
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.3.0...v0.3.1)
104
+
105
+ ## [v0.3.0](https://github.com/jksy/sql_parser/tree/v0.3.0) (2015-08-27)
106
+
107
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.2.0...v0.3.0)
108
+
109
+ ## [v0.2.0](https://github.com/jksy/sql_parser/tree/v0.2.0) (2015-08-24)
110
+
111
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.1.1...v0.2.0)
112
+
113
+ ## [v0.1.1](https://github.com/jksy/sql_parser/tree/v0.1.1) (2015-08-12)
114
+
115
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/v0.1.0...v0.1.1)
116
+
117
+ ## [v0.1.0](https://github.com/jksy/sql_parser/tree/v0.1.0) (2015-08-03)
118
+
119
+ [Full Changelog](https://github.com/jksy/sql_parser/compare/131eba24eb79a0617c59210535da5d00dd6ee012...v0.1.0)
120
+
121
+ **Merged pull requests:**
122
+
123
+ - racc -\> treetop [\#1](https://github.com/jksy/sql_parser/pull/1) ([jksy](https://github.com/jksy))
124
+
125
+ ## Release notes (formerly HISTORY.md)
126
+
127
+ ### 1.0.0
128
+ * Pass test on Rails 5.1.7
129
+ * Drop support version before 2.3.8
130
+ * Added grammer for "SELECT * FROM {table_name} FETCH FIRST {number} ROWS ONLY".
131
+ * The grammer is used by Model.limit(10) with Oracle 18g through ActiveRecord
132
+ * Remove code for Ruby version 1.9.x
133
+
134
+ ### 0.9.2
135
+ * bug fix method not found "keys" on hash
136
+
137
+ ### 0.9.1
138
+ * Syntax
139
+ * Three or more ANDs in WHERE clause fails parsing https://github.com/jksy/sql_parser/issues/16
140
+
141
+ ### 0.9.0
142
+ * Syntax
143
+ * added cursor expression
144
+ * added datetime expression
145
+ * added interval expression
146
+
147
+ ### 0.8.1
148
+ * Fix README.md
149
+
150
+ ### 0.8.0
151
+ * Syntax
152
+ * subquery https://github.com/jksy/sql_parser/issues/8
153
+ * "select col1 from table1 union select col2 from table2 union select col3 from table3"
154
+ * "select col1 from table1 union (select col2 from table2)"
155
+ * compound expression https://github.com/jksy/sql_parser/issues/8
156
+ * "select 1-1 from table1"
157
+ * Broken changes
158
+ * select_list.
159
+ Ast::Array[ Ast::Ident[..], Ast::Ident[..]] Ast::Array[ Ast::SelectColumn[:expr => Ast::Ident[..]],...]
160
+
161
+ ### 0.7.0
162
+ * Syntax
163
+ * table alias, like "select a.* from table1 a". https://github.com/jksy/sql_parser/issues/8
164
+
165
+ ### 0.6.0
166
+ * Enchancement
167
+ * added travis-ci
168
+ * added oracle enhanced adapter query(select, includes, joins, where)
169
+ * Syntax
170
+ * added syntax for column_alias
171
+
172
+ ### 0.5.1
173
+ * Bug fix
174
+ * fix spell. to_pameternized is deprecated and will be removed. use to_parameterized
175
+
176
+ ### 0.5.0
177
+ * Enchancement
178
+ * added NumberLiteral#to_cecimal, TextLiteral#to_s
179
+
180
+ ### 0.4.0
181
+ * Bugfix
182
+ * rename ParameternizedQuery#query -> ParameternizedQuery#to_sql
183
+ * Syntax
184
+ * union [all]
185
+ * intersect
186
+ * minus
187
+ * [inner|outer] join
188
+ * conditions
189
+ * floating point condition
190
+ * multiset condition
191
+ * is_of_type condition
192
+
193
+ ### 0.3.0
194
+ * Enchancement
195
+ * added to_parameternized method
196
+
197
+ * Bug fix
198
+ * to_sql when select multiple column query parsed
199
+
200
+ ### 0.2.0
201
+ * Bug fix
202
+ * Identifier[:value => ..] -> Identifier[:name => ..] when use sequence.nextval
203
+ * refactor test cases
204
+
205
+ ### 0.1.1
206
+ * Syntax
207
+ * support double-quoted identifer
208
+
209
+ ### 0.1.0
210
+ * Initial version
211
+
212
+
213
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Junichiro Kasuya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,9 +1,16 @@
1
1
  # OracleSqlParser
2
2
 
3
- [![Build Status](https://travis-ci.org/jksy/sql_parser.svg?branch=master)](https://travis-ci.org/jksy/sql_parser)
3
+ [![ci](https://github.com/jksy/sql_parser/actions/workflows/ci.yml/badge.svg)](https://github.com/jksy/sql_parser/actions/workflows/ci.yml)
4
+ [![codecov](https://codecov.io/gh/jksy/sql_parser/branch/master/graph/badge.svg?token=0HSMBU0CD8)](https://codecov.io/gh/jksy/sql_parser)
4
5
 
5
6
  SQL Parser for Oracle
6
7
 
8
+ ## Requirements
9
+
10
+ Ruby 3.2 or later (CI runs on 3.2, 3.3, 3.4 and 4.0). The gem itself does not
11
+ need an Oracle client; only the connection tests described under
12
+ [Development](#development) do.
13
+
7
14
  ## Installation
8
15
 
9
16
  Add this line to your application's Gemfile:
@@ -78,10 +85,66 @@ p.params.inspect
78
85
  => {"a0"=>#<OracleSqlParser::Ast::NumberLiteral {:value=>"1"}>}
79
86
  </pre>
80
87
 
88
+ ## Development
89
+
90
+ $ bundle install
91
+ $ bundle exec rake test:unit # parser tests, no Oracle required
92
+
93
+ The parsers under `lib/oracle-sql-parser/grammar/` are generated from the
94
+ `.treetop` grammars next to them and the generated `.rb` files are committed.
95
+ After editing a grammar (or `reserved_word_generator.rb`), regenerate and
96
+ commit the result; CI fails if the committed parsers are out of date:
97
+
98
+ $ bundle exec rake gen_force # compile **/*.treetop
99
+
100
+ The tests under `test/oracle_enhanced-adapter` run real queries through
101
+ [activerecord-oracle_enhanced-adapter](https://github.com/rsim/oracle-enhanced)
102
+ and need Oracle Instant Client plus a reachable Oracle database. The easiest
103
+ way to get both is the dev container in `.devcontainer/`, which starts
104
+ [Oracle Database Free](https://github.com/gvenzl/oci-oracle-free) next to a
105
+ Ruby container that has Instant Client installed. Open the repository in the
106
+ container (VS Code "Reopen in Container", or the
107
+ [devcontainer CLI](https://github.com/devcontainers/cli)) and run the tests:
108
+
109
+ $ devcontainer up --workspace-folder .
110
+ $ devcontainer exec --workspace-folder . bundle exec rake test # test:unit and test:adapter
111
+
112
+ The Oracle gems are managed with [Appraisal](https://github.com/thoughtbot/appraisal)
113
+ so that a plain `bundle install` works without Oracle; `rake test:adapter`
114
+ switches to `gemfiles/adapter_6.gemfile` by itself when the current bundle does
115
+ not have them. There is one appraisal per ActiveRecord version the tests are
116
+ run against (6.1, 7.2 and 8.1, see `Appraisals`); to run the tests with all of
117
+ them:
118
+
119
+ $ bundle exec appraisal rake test:adapter:run
120
+
121
+ To run against another Oracle database instead, install the appraisal gems and
122
+ point the tests at it:
123
+
124
+ $ bundle exec appraisal install
125
+ $ export ORACLE_USERNAME=... ORACLE_PASSWORD=... ORACLE_HOST=localhost ORACLE_PORT=1521 ORACLE_SID=FREEPDB1
126
+ $ bundle exec rake test:adapter
127
+
128
+ Connection settings can also be put in `test/oracle_enhanced-adapter/connection_params.yml`
129
+ (ignored by git).
130
+
131
+ ## Release
132
+
133
+ Release notes live on [GitHub Releases](https://github.com/jksy/sql_parser/releases)
134
+ and are generated from the merged pull requests, grouped by label
135
+ (`.github/release.yml`). `CHANGELOG.md` is kept for history only.
136
+
137
+ 1. Open a pull request that updates `lib/oracle-sql-parser/version.rb`, label
138
+ it `release` (so it is left out of the notes) and merge it.
139
+ 2. On `master`, run `bundle exec rake release`, which creates the `v<version>`
140
+ tag, pushes it and publishes the gem to [rubygems.org](https://rubygems.org).
141
+ 3. On GitHub, draft a release for the tag, click "Generate release notes" and
142
+ publish it.
143
+
81
144
  ## Contributing
82
145
 
83
146
  Bug reports and pull requests are welcome on GitHub at https://github.com/jksy/sql_parser.
84
147
 
85
- ## Test Page
148
+ ## License
86
149
 
87
- http://dev.jksy.org/
150
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -3,6 +3,9 @@ require 'rake'
3
3
  require 'rake/testtask'
4
4
 
5
5
  GRAMMAR_FILES = FileList['lib/oracle-sql-parser/grammar/**/*.treetop']
6
+ # The Oracle gems live in the appraisal gemfiles (see Appraisals); test:adapter
7
+ # re-runs itself under this one when the current bundle does not have them.
8
+ ADAPTER_GEMFILE = 'gemfiles/adapter_6.gemfile'.freeze
6
9
 
7
10
  desc "generate parser files"
8
11
  task :gen do
@@ -18,20 +21,69 @@ desc "clean files"
18
21
  task :clean do
19
22
  GRAMMAR_FILES.each do |f|
20
23
  file = "#{f.gsub(/\.treetop$/,'')}.rb"
21
- File.unlink file if File.exists? file
24
+ File.unlink file if File.exist? file
22
25
  end
23
26
  end
24
27
 
25
- Rake::TestTask.new do |t|
26
- t.libs << "test"
27
- t.test_files = FileList[
28
- 'test/grammar/*_test.rb',
29
- 'test/ast/*_test.rb',
30
- 'test/oracle_enhanced-adapter/select_test.rb'
31
- ]
32
- t.verbose = true
28
+ namespace :test do
29
+ Rake::TestTask.new(:unit) do |t|
30
+ t.description = "run parser tests (no Oracle required)"
31
+ t.libs << "test"
32
+ t.test_files = FileList[
33
+ 'test/grammar/*_test.rb',
34
+ 'test/ast/*_test.rb'
35
+ ]
36
+ t.verbose = true
37
+ end
38
+
39
+ namespace :adapter do
40
+ Rake::TestTask.new(:run) do |t|
41
+ t.description = "run Oracle connection tests in the current bundle"
42
+ t.libs << "test"
43
+ t.test_files = FileList['test/oracle_enhanced-adapter/select_test.rb']
44
+ t.verbose = true
45
+ end
46
+ end
47
+
48
+ desc "run Oracle connection tests (needs an Oracle DB; uses #{ADAPTER_GEMFILE} unless the current bundle has the adapter)"
49
+ task :adapter do
50
+ if adapter_gems_available?
51
+ Rake::Task['test:adapter:run'].invoke
52
+ else
53
+ sh({ 'BUNDLE_GEMFILE' => ADAPTER_GEMFILE }, 'bundle', 'exec', 'rake', 'test:adapter:run')
54
+ end
55
+ end
56
+ end
57
+
58
+ # Name each SimpleCov run so results from test:unit and test:adapter merge.
59
+ task 'test:unit:coverage_name' do
60
+ ENV['SIMPLECOV_COMMAND_NAME'] = 'unit'
61
+ end
62
+ task 'test:adapter:coverage_name' do
63
+ ENV['SIMPLECOV_COMMAND_NAME'] = 'adapter'
33
64
  end
65
+ task 'test:unit' => 'test:unit:coverage_name'
66
+ task 'test:adapter:run' => 'test:adapter:coverage_name'
34
67
 
68
+ desc "run all tests (test:unit and test:adapter)"
69
+ task :test => ['test:unit', 'test:adapter']
70
+
71
+ desc "run RuboCop"
72
+ task :rubocop do
73
+ sh "rubocop"
74
+ end
75
+
76
+ desc "run what CI runs: RuboCop and the parser tests"
77
+ task :ci => [:rubocop, 'test:unit']
78
+
79
+ task :default => 'test:unit'
80
+
81
+
82
+ def adapter_gems_available?
83
+ Bundler.load.specs.any? { |spec| spec.name == 'activerecord-oracle_enhanced-adapter' }
84
+ rescue Bundler::BundlerError
85
+ false
86
+ end
35
87
 
36
88
  def generate_parser_files(force = false)
37
89
  word_generator = "lib/oracle-sql-parser/grammar/reserved_word_generator.rb"
@@ -54,7 +106,7 @@ def tt(f, force = false)
54
106
  end
55
107
 
56
108
  def do_if_changed(src, output, force = false, &block)
57
- force = true unless File.exists?(output)
109
+ force = true unless File.exist?(output)
58
110
  if force || File::Stat.new(src).mtime >= File::Stat.new(output).mtime
59
111
  yield
60
112
  end
@@ -0,0 +1,12 @@
1
+ module OracleSqlParser::Ast
2
+ class Fetch < Hash
3
+ def to_sql(options = {})
4
+ @ast.values_at(
5
+ :fetch, :first,
6
+ :rowcount, :percentage, :percentage_keyword,
7
+ :rows, :only, :with, :ties,
8
+ ).compact.map(&:to_sql).join(' ')
9
+ end
10
+ end
11
+ end
12
+
@@ -5,7 +5,7 @@ module OracleSqlParser::Ast
5
5
  end
6
6
 
7
7
  def to_decimal
8
- BigDecimal.new(@ast[:value])
8
+ BigDecimal(@ast[:value])
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,11 @@
1
+ module OracleSqlParser::Ast
2
+ class Offset < Hash
3
+ def to_sql(options = {})
4
+ @ast.values_at(
5
+ :offset_keyword, :offset,
6
+ :row_keyword, :rows_keyword,
7
+ ).compact.map(&:to_sql).join(' ')
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,10 @@
1
+ module OracleSqlParser::Ast
2
+ class RowLimitingClause < Hash
3
+ def to_sql(options = {})
4
+ @ast.values_at(
5
+ :offset,
6
+ :fetch,
7
+ ).compact.map(&:to_sql).join(' ')
8
+ end
9
+ end
10
+ end
@@ -1,10 +1,14 @@
1
1
  module OracleSqlParser::Ast
2
2
  class Subquery < Hash
3
3
  def to_sql(options = {})
4
- result = @ast.values_at(:query_block,
5
- :subqueries,
6
- :subquery,
7
- :order_by_clause).map(&:to_sql)
4
+ result = @ast.values_at(
5
+ :query_block,
6
+ :subqueries,
7
+ :subquery,
8
+ :order_by_clause,
9
+ :row_limiting_clause,
10
+ ).map(&:to_sql)
11
+
8
12
  if @ast[:has_parenthesis]
9
13
  result.unshift('(')
10
14
  result.push(')')
@@ -13,6 +13,9 @@ require 'oracle-sql-parser/ast/query_block.rb'
13
13
  require 'oracle-sql-parser/ast/inner_cross_join_clause.rb'
14
14
  require 'oracle-sql-parser/ast/inner_join_clause.rb'
15
15
  require 'oracle-sql-parser/ast/outer_join_clause.rb'
16
+ require 'oracle-sql-parser/ast/row_limiting_clause.rb'
17
+ require 'oracle-sql-parser/ast/fetch.rb'
18
+ require 'oracle-sql-parser/ast/offset.rb'
16
19
  require 'oracle-sql-parser/ast/on_clause.rb'
17
20
  require 'oracle-sql-parser/ast/using_clause.rb'
18
21
  require 'oracle-sql-parser/ast/cross_natural_join_clause.rb'
@@ -158,10 +158,12 @@ module OracleSqlParser::Grammar::Condition
158
158
  r0
159
159
  end
160
160
 
161
- end
162
161
 
163
- class BetweenParser < Treetop::Runtime::CompiledParser
164
- include Between
162
+ class Parser < Treetop::Runtime::CompiledParser
163
+ include Between
164
+ end
165
165
  end
166
166
 
167
+ (remove_const(:BetweenParser) if const_defined?(:BetweenParser)) rescue nil; BetweenParser = Between::Parser
168
+
167
169
  end
@@ -443,10 +443,12 @@ module OracleSqlParser::Grammar::Condition
443
443
  r0
444
444
  end
445
445
 
446
- end
447
446
 
448
- class ComparisonParser < Treetop::Runtime::CompiledParser
449
- include Comparison
447
+ class Parser < Treetop::Runtime::CompiledParser
448
+ include Comparison
449
+ end
450
450
  end
451
451
 
452
+ (remove_const(:ComparisonParser) if const_defined?(:ComparisonParser)) rescue nil; ComparisonParser = Comparison::Parser
453
+
452
454
  end
@@ -12,6 +12,7 @@ module OracleSqlParser::Grammar::Condition
12
12
  end
13
13
 
14
14
  rule group_comparison_condition
15
+ # not implemented
15
16
  'group_comparison_condition'
16
17
  end
17
18
 
@@ -70,10 +70,12 @@ module OracleSqlParser::Grammar::Condition
70
70
  r0
71
71
  end
72
72
 
73
- end
74
73
 
75
- class CompoundParser < Treetop::Runtime::CompiledParser
76
- include Compound
74
+ class Parser < Treetop::Runtime::CompiledParser
75
+ include Compound
76
+ end
77
77
  end
78
78
 
79
+ (remove_const(:CompoundParser) if const_defined?(:CompoundParser)) rescue nil; CompoundParser = Compound::Parser
80
+
79
81
  end
@@ -107,10 +107,12 @@ module OracleSqlParser::Grammar::Condition
107
107
  r0
108
108
  end
109
109
 
110
- end
111
110
 
112
- class ExistsParser < Treetop::Runtime::CompiledParser
113
- include Exists
111
+ class Parser < Treetop::Runtime::CompiledParser
112
+ include Exists
113
+ end
114
114
  end
115
115
 
116
+ (remove_const(:ExistsParser) if const_defined?(:ExistsParser)) rescue nil; ExistsParser = Exists::Parser
117
+
116
118
  end
@@ -124,10 +124,12 @@ module OracleSqlParser::Grammar::Condition
124
124
  r0
125
125
  end
126
126
 
127
- end
128
127
 
129
- class FloatingPointParser < Treetop::Runtime::CompiledParser
130
- include FloatingPoint
128
+ class Parser < Treetop::Runtime::CompiledParser
129
+ include FloatingPoint
130
+ end
131
131
  end
132
132
 
133
+ (remove_const(:FloatingPointParser) if const_defined?(:FloatingPointParser)) rescue nil; FloatingPointParser = FloatingPoint::Parser
134
+
133
135
  end
@@ -179,10 +179,12 @@ module OracleSqlParser::Grammar::Condition
179
179
  r0
180
180
  end
181
181
 
182
- end
183
182
 
184
- class InParser < Treetop::Runtime::CompiledParser
185
- include In
183
+ class Parser < Treetop::Runtime::CompiledParser
184
+ include In
185
+ end
186
186
  end
187
187
 
188
+ (remove_const(:InParser) if const_defined?(:InParser)) rescue nil; InParser = In::Parser
189
+
188
190
  end
@@ -442,10 +442,12 @@ module OracleSqlParser::Grammar::Condition
442
442
  r0
443
443
  end
444
444
 
445
- end
446
445
 
447
- class IsOfTypeParser < Treetop::Runtime::CompiledParser
448
- include IsOfType
446
+ class Parser < Treetop::Runtime::CompiledParser
447
+ include IsOfType
448
+ end
449
449
  end
450
450
 
451
+ (remove_const(:IsOfTypeParser) if const_defined?(:IsOfTypeParser)) rescue nil; IsOfTypeParser = IsOfType::Parser
452
+
451
453
  end
@@ -556,11 +556,13 @@ module OracleSqlParser::Grammar::Condition
556
556
  r0
557
557
  end
558
558
 
559
- end
560
559
 
561
- class MultisetParser < Treetop::Runtime::CompiledParser
562
- include Multiset
560
+ class Parser < Treetop::Runtime::CompiledParser
561
+ include Multiset
562
+ end
563
563
  end
564
564
 
565
+ (remove_const(:MultisetParser) if const_defined?(:MultisetParser)) rescue nil; MultisetParser = Multiset::Parser
566
+
565
567
  end
566
568