vorax 0.4.2 → 5.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 (56) hide show
  1. data/README.md +4 -29
  2. data/vorax.gemspec +3 -11
  3. metadata +4 -92
  4. data/.rspec +0 -1
  5. data/Rakefile +0 -30
  6. data/lib/vorax.rb +0 -60
  7. data/lib/vorax/base_funnel.rb +0 -30
  8. data/lib/vorax/output/html_convertor.rb +0 -120
  9. data/lib/vorax/output/html_funnel.rb +0 -79
  10. data/lib/vorax/output/pagezip_convertor.rb +0 -20
  11. data/lib/vorax/output/tablezip_convertor.rb +0 -22
  12. data/lib/vorax/output/vertical_convertor.rb +0 -53
  13. data/lib/vorax/output/zip_convertor.rb +0 -117
  14. data/lib/vorax/parser/argument.rb~ +0 -125
  15. data/lib/vorax/parser/conn_string.rb +0 -104
  16. data/lib/vorax/parser/grammars/alias.rb +0 -904
  17. data/lib/vorax/parser/grammars/alias.rl +0 -138
  18. data/lib/vorax/parser/grammars/column.rb +0 -454
  19. data/lib/vorax/parser/grammars/column.rl +0 -64
  20. data/lib/vorax/parser/grammars/common.rl +0 -107
  21. data/lib/vorax/parser/grammars/declare.rb +0 -9606
  22. data/lib/vorax/parser/grammars/declare.rl +0 -160
  23. data/lib/vorax/parser/grammars/for_block.rb +0 -440
  24. data/lib/vorax/parser/grammars/for_block.rl +0 -73
  25. data/lib/vorax/parser/grammars/plsql_def.rb +0 -539
  26. data/lib/vorax/parser/grammars/plsql_def.rl +0 -73
  27. data/lib/vorax/parser/grammars/statement.rb +0 -925
  28. data/lib/vorax/parser/grammars/statement.rl +0 -83
  29. data/lib/vorax/parser/parser.rb +0 -344
  30. data/lib/vorax/parser/plsql_structure.rb +0 -222
  31. data/lib/vorax/parser/plsql_walker.rb +0 -143
  32. data/lib/vorax/parser/statement_inspector.rb~ +0 -52
  33. data/lib/vorax/parser/stmt_inspector.rb +0 -78
  34. data/lib/vorax/parser/target_ref.rb +0 -110
  35. data/lib/vorax/sqlplus.rb +0 -273
  36. data/lib/vorax/version.rb +0 -7
  37. data/lib/vorax/vorax_io.rb +0 -70
  38. data/spec/column_spec.rb +0 -40
  39. data/spec/conn_string_spec.rb +0 -53
  40. data/spec/declare_spec.rb +0 -281
  41. data/spec/pagezip_spec.rb +0 -153
  42. data/spec/parser_spec.rb +0 -352
  43. data/spec/plsql_structure_spec.rb +0 -68
  44. data/spec/spec_helper.rb +0 -13
  45. data/spec/sql/create_objects.sql +0 -69
  46. data/spec/sql/dbms_crypto.spc +0 -339
  47. data/spec/sql/dbms_stats.spc +0 -4097
  48. data/spec/sql/drop_user.sql +0 -10
  49. data/spec/sql/muci.spc +0 -26
  50. data/spec/sql/setup_user.sql +0 -22
  51. data/spec/sql/test.fnc +0 -12
  52. data/spec/sql/test.pkg +0 -83
  53. data/spec/sqlplus_spec.rb +0 -52
  54. data/spec/stmt_inspector_spec.rb +0 -96
  55. data/spec/tablezip_spec.rb +0 -111
  56. data/spec/vertical_spec.rb +0 -150
@@ -1,153 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- include Vorax
4
-
5
- describe 'pagezip layout' do
6
-
7
- before(:each) do# {{{
8
- @sp = Sqlplus.new('sqlplus')
9
- @sp.default_convertor = :pagezip
10
- @prep = [VORAX_CSTR,
11
- "set tab off",
12
- "set linesize 10000",
13
- "set markup html on",
14
- "set echo off",
15
- "set pause off",
16
- "set define &",
17
- "set termout on",
18
- "set verify off",
19
- "set pagesize 5"].join("\n")
20
- @result = ""
21
- end# }}}
22
-
23
- it 'should work with multi line records' do# {{{
24
- @sp.exec("select * from departments where id in (1, 2, 6);", :prep => @prep)
25
- @result << @sp.read_output(32767) while @sp.busy?
26
- expected = <<OUTPUT
27
-
28
- SQL>
29
-
30
- ID NAME DESCRIPTION
31
- -- ----------- -----------------------------------
32
- 1 Bookkeeping This department is responsible for:
33
- - financial reporting
34
- - analysis
35
- - other boring tasks
36
- 2 Marketing  
37
- 6 Management The bad guys department
38
-
39
- SQL>
40
- OUTPUT
41
- @result.should eq(expected)
42
- end# }}}
43
-
44
- it 'should work with a single line record' do# {{{
45
- @sp.exec("select * from departments where id=2;", :prep => @prep)
46
- @result << @sp.read_output(32767) while @sp.busy?
47
- expected = <<OUTPUT
48
-
49
- SQL>
50
-
51
- ID NAME DESCRIPTION
52
- -- --------- -----------
53
- 2 Marketing  
54
-
55
- SQL>
56
- OUTPUT
57
- @result.should eq(expected)
58
- end# }}}
59
-
60
- it 'should work without headers' do# {{{
61
- @sp.exec("select * from departments where id<=4;", :prep => "#@prep\nset pagesize 0")
62
- @result << @sp.read_output(32767) while @sp.busy?
63
- expected = <<OUTPUT
64
-
65
- SQL>
66
-
67
- 1 Bookkeeping This department is responsible for:
68
- - financial reporting
69
- - analysis
70
- - other boring tasks
71
- 2 Marketing  
72
- 3 Deliveries  
73
- 4 CRM  
74
-
75
- SQL>
76
- OUTPUT
77
- @result.should eq(expected)
78
- end# }}}
79
-
80
- it 'should work with special unicode chars' do# {{{
81
- @sp.exec("select * from employees where id=1;", :prep => @prep)
82
- @result << @sp.read_output(32767) while @sp.busy?
83
- expected = <<OUTPUT
84
-
85
- SQL>
86
-
87
- ID NAME SALARY DEPARTMENT_ID
88
- -- ----------- ------ -------------
89
- 1 Tică Șerban 570 1
90
-
91
- SQL>
92
- OUTPUT
93
- @result.should eq(expected)
94
- end# }}}
95
-
96
- it 'should work with multiple pages' do# {{{
97
- @sp.exec("select * from departments where id<=10;", :prep => "#@prep\nset pagesize 4")
98
- @result << @sp.read_output(32767) while @sp.busy?
99
- expected = <<OUTPUT
100
-
101
- SQL>
102
-
103
- ID NAME DESCRIPTION
104
- -- ----------- -----------------------------------
105
- 1 Bookkeeping This department is responsible for:
106
- - financial reporting
107
- - analysis
108
- - other boring tasks
109
- 2 Marketing  
110
- 3 Deliveries  
111
- 4 CRM  
112
-
113
- ID NAME DESCRIPTION
114
- -- ---------------- -----------------------
115
- 5 Legal Stuff  
116
- 6 Management The bad guys department
117
- 7 Cooking  
118
- 8 Public Relations  
119
-
120
- ID NAME DESCRIPTION
121
- -- ----------- -----------
122
- 9 Aquisitions  
123
- 10 Cleaning  
124
-
125
- 10 rows selected.
126
-
127
- SQL>
128
- OUTPUT
129
- #puts @result
130
- @result.should eq(expected)
131
- end# }}}
132
-
133
- it 'should work with accept prompts' do# {{{
134
- begin
135
- pack_file = Tempfile.new(['vorax', '.sql'])
136
- @sp.exec("accept var prompt \"Enter var: \"\nprompt &var", :prep => @prep, :pack_file => pack_file.path)
137
- Timeout::timeout(10) {
138
- @result << @sp.read_output(32767) while @result !~ /Enter var:\z/
139
- @sp.send_text("muci\n")
140
- @result << @sp.read_output(32767) while @result !~ /muci\n\z/
141
- }
142
- ensure
143
- pack_file.unlink
144
- end
145
- end# }}}
146
-
147
- after(:each) do# {{{
148
- @sp.terminate
149
- end# }}}
150
-
151
- end
152
-
153
-
@@ -1,352 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- include Vorax
4
-
5
- describe 'Parser' do
6
-
7
- it 'should detect the end of a subprogram' do# {{{
8
- text = "end;"
9
- Parser.plsql_def(text)[:end_def].should be >0;
10
- text = "end if;"
11
- Parser.plsql_def(text)[:end_type].should_not == 'END';
12
- text = "end loop;"
13
- Parser.plsql_def(text)[:type].should_not == 'END' ;
14
- text = "end my_func;"
15
- Parser.plsql_def(text)[:end_def].should be >0;
16
- text = "end/*test*/my_prog;"
17
- Parser.plsql_def(text)[:end_def].should be >0;
18
- text = "end/*test*/\"my_special_prog\";"
19
- Parser.plsql_def(text)[:end_def].should be >0;
20
- text = "end is_AdminBasket;\r\n\r\n function get_BasketId(pi_impkey in integer, pi_tablename in varchar2)\r\n "
21
- Parser.plsql_def(text)[:end_def].should be >0;
22
- end# }}}
23
-
24
- it 'shuld detect the end of a loop statement' do
25
- Parser.plsql_def("end loop;")[:type].should == 'END_LOOP'
26
- Parser.plsql_def("end/*test*/ loop ; ")[:type].should == 'END_LOOP'
27
- Parser.plsql_def("end \"loop\"; ")[:type].should_not == 'END_LOOP'
28
- end
29
-
30
- it 'shuld detect the end of a if statement' do
31
- Parser.plsql_def("end if;")[:type].should == 'END_IF'
32
- Parser.plsql_def("end/*test*/ if ; ")[:type].should == 'END_IF'
33
- Parser.plsql_def("end \"if\"; ")[:type].should_not == 'END_IF'
34
- end
35
-
36
- it 'should detect the definition of a plsql module' do# {{{
37
- text = "PACKAGE muci AS "
38
- result = Parser.plsql_def(text)
39
- result[:end_def].should be >0
40
- result[:name].should == 'muci'
41
- result[:type].should == 'SPEC'
42
- text = "package\nbody muci.buci/* bla bla*/ as "
43
- result = Parser.plsql_def(text)
44
- result[:end_def].should be >0;
45
- result[:name].should == 'muci.buci'
46
- result[:type].should == 'BODY'
47
- text = "package bdy muci.buci/* bla bla*/ as "
48
- Parser.plsql_def(text)[:end_def].should be <0;
49
- end# }}}
50
-
51
- it 'should work with balanced paren' do# {{{
52
- Parser.walk_balanced_paren('(a(b)c)').should eq("(a(b)c)")
53
- Parser.walk_balanced_paren('(a(b)(xyz)c)').should eq("(a(b)(xyz)c)")
54
- Parser.walk_balanced_paren("(a')'(b)c)bla bla bla").should eq("(a')'(b)c)")
55
- Parser.walk_balanced_paren('(a")"(b)c)bla bla bla').should eq('(a")"(b)c)')
56
- Parser.walk_balanced_paren("(a/*)*/(b)c)bla bla bla").should eq("(a/*)*/(b)c)")
57
- Parser.walk_balanced_paren("(a--)\n(b)c)bla bla bla").should eq("(a--)\n(b)c)")
58
- Parser.walk_balanced_paren("(aq[')]'(b)c)bla bla bla").should eq("(aq[')]'(b)c)")
59
- end# }}}
60
-
61
- it 'should add the proper end delimitator' do# {{{
62
- text = "select * from cat"
63
- Parser.prepare_exec(text).should eq("select * from cat;")
64
-
65
- text = <<TEXT
66
- begin
67
- null;
68
- end;
69
- TEXT
70
- Parser.prepare_exec(text).should eq("begin\n null;\nend;\n/\n")
71
-
72
- text = "set serveroutput on"
73
- Parser.prepare_exec(text).should eq("set serveroutput on")
74
-
75
- text = "select * from dual;"
76
- Parser.prepare_exec(text).should eq("select * from dual;")
77
- end# }}}
78
-
79
- describe 'Comments parsing' do# {{{
80
-
81
- it 'should be smart enough to leave quotes unchanged' do# {{{
82
- stmt = <<STR
83
- select '/*muci*/' from/*abc*/dual;
84
- STR
85
- Parser.remove_all_comments(stmt).should eq("select '/*muci*/' from dual;\n")
86
- end# }}}
87
-
88
- it 'should remove all comments' do# {{{
89
- stmt = <<STR
90
- select /* muci */ * from --muhah
91
- --bla
92
- dual
93
- /* muha
94
- ha*/
95
- ;
96
- STR
97
- Parser.remove_all_comments(stmt).should eq("select * from dual\n \n;\n")
98
- end# }}}
99
-
100
- it 'should remove all comments from incomplete statements' do# {{{
101
- Parser.remove_all_comments('select /* bla').should eq('select /* bla')
102
- end# }}}
103
-
104
- it 'should remove trailing comments' do# {{{
105
- text = <<TEXT
106
- select * from cat --comment
107
- -- alt comment
108
- -- si inca un comment
109
- TEXT
110
- Parser.remove_trailing_comments(text).should eq("select * from cat ")
111
-
112
- text = <<TEXT
113
- select * from cat
114
- /* multi
115
- line comment */
116
- /* inca
117
- unul */
118
- TEXT
119
- Parser.remove_trailing_comments(text).should eq("select * from cat\n")
120
-
121
- text = <<TEXT
122
- select * from cat
123
- /* multi
124
- line comment */
125
- -- single line comment
126
- /* inca
127
- unul */
128
- -- muhaha
129
- TEXT
130
- Parser.remove_trailing_comments(text).should eq("select * from cat\n")
131
- end# }}}
132
-
133
- end# }}}
134
-
135
- describe 'Arguments parsing' do# {{{
136
-
137
- it 'should detect basic argument owner' do# {{{
138
- text = 'select col1, 1+2, func(a, b, my_f(x, y), c, \'a\'\'bc\', "xxx".y, d,'
139
- Parser.argument_belongs_to(text, 65).should eq('func')
140
- Parser.argument_belongs_to(text, 37).should eq('my_f')
141
- end# }}}
142
-
143
- it 'should handle whitespaces between function name and open paran' do# {{{
144
- Parser.argument_belongs_to('exec dbms_stats.gather_schema_stats (owname => user, ').should eq('dbms_stats.gather_schema_stats')
145
- Parser.argument_belongs_to("begin dbms_stats.gather_schema_stats \n\t (owname => user, ").should eq('dbms_stats.gather_schema_stats')
146
- end# }}}
147
-
148
- it 'should handle quoted identifiers' do# {{{
149
- Parser.argument_belongs_to('exec "My user" . "bla@hei.la" @ dblink.hop.hu(owname => user, ').should eq("\"My user\".\"bla@hei.la\"@dblink.hop.hu")
150
- Parser.argument_belongs_to('exec "ABC!"."bla"(owname => user, ').should eq("\"ABC!\".\"bla\"")
151
- Parser.argument_belongs_to('exec owner."pkg"."my func"(owname => user, ').should eq("owner.\"pkg\".\"my func\"")
152
- end# }}}
153
-
154
- it 'should ignore comments' do# {{{
155
- Parser.argument_belongs_to('exec dbms_stats./*muci*/gather_schema_stats/*abc*/ (owname => user, ').should eq('dbms_stats.gather_schema_stats')
156
- end# }}}
157
-
158
- it 'should handle plsql quoting' do# {{{
159
- text = "exec pkg.my_proc(q'[Isn't the \"(\" character sweet?]', "
160
- Parser.argument_belongs_to(text).should eq('pkg.my_proc')
161
- text = "exec pkg.my_proc(q'{Isn't the \"(\" character sweet?}', "
162
- Parser.argument_belongs_to(text).should eq('pkg.my_proc')
163
- text = "exec pkg.my_proc(q'<Isn't the \"(\" character sweet?>', "
164
- Parser.argument_belongs_to(text).should eq('pkg.my_proc')
165
- end# }}}
166
-
167
- it 'should fallback to simple quoting' do# {{{
168
- text = "exec pkg.my_proc('<Isn''t the \"(\" character sweet?>', "
169
- Parser.argument_belongs_to(text).should eq('pkg.my_proc')
170
- end# }}}
171
-
172
- end# }}}
173
-
174
- describe 'Statement type' do# {{{
175
-
176
- it 'should detect an anonymous block' do# {{{
177
- Parser.statement_type("begin dbms_output.put_line('xx');").should eq("ANONYMOUS")
178
- Parser.statement_type("declare l_test varchar2(10);").should eq("ANONYMOUS")
179
- Parser.statement_type("bbegin dbms_output.put_line('xx');").should be_nil
180
- Parser.statement_type("ddeclare dbms_output.put_line('xx');").should be_nil
181
- Parser.statement_type("select 1 from dual;").should be_nil
182
- end# }}}
183
-
184
- it 'should detect a function' do# {{{
185
- Parser.statement_type("create or\nreplace function muci as").should eq("FUNCTION")
186
- Parser.statement_type("create orreplace function muci as").should be_nil
187
- end# }}}
188
-
189
- it 'should detect a procedure' do# {{{
190
- Parser.statement_type("create or replace\n procedure muci as").should eq("PROCEDURE")
191
- Parser.statement_type("create or replace proceduremuci as").should be_nil
192
- end# }}}
193
-
194
- it 'should detect a trigger' do# {{{
195
- Parser.statement_type("create or replace\n trigger muci as").should eq("TRIGGER")
196
- Parser.statement_type("createor replace trigger as").should be_nil
197
- end# }}}
198
-
199
- it 'should detect a package spec' do# {{{
200
- Parser.statement_type("create or replace\n package muci as").should eq("PACKAGE")
201
- Parser.statement_type("createor replace package as").should be_nil
202
- end# }}}
203
-
204
- it 'should detect a package body' do# {{{
205
- Parser.statement_type("create or replace\n package body muci as").should eq("PACKAGE BODY")
206
- Parser.statement_type("create or replace packagebody as").should be_nil
207
- Parser.statement_type("create or replace package bodyas").should_not eq("PACKAGE BODY")
208
- end# }}}
209
-
210
- it 'should detect a type spec' do# {{{
211
- Parser.statement_type("create or replace\n type muci as").should eq("TYPE")
212
- Parser.statement_type("createor replace type as").should be_nil
213
- end# }}}
214
-
215
- it 'should detect a type body' do# {{{
216
- Parser.statement_type("create or replace\n type body muci as").should eq("TYPE BODY")
217
- Parser.statement_type("create or replace typebody as").should be_nil
218
- Parser.statement_type("create or replace type bodyas").should_not eq("TYPE BODY")
219
- end# }}}
220
-
221
- it 'should detect java source' do# {{{
222
- Parser.statement_type("create or replace java muci as").should eq("JAVA")
223
- Parser.statement_type("create java muci as").should eq("JAVA")
224
- Parser.statement_type("create or replace and compile java muci as").should eq("JAVA")
225
- Parser.statement_type("create or replace and resolve noforce java muci as").should eq("JAVA")
226
- Parser.statement_type("create or replace and resolvenoforce java muci as").should_not eq("JAVA")
227
- end# }}}
228
-
229
- it 'should detect sqlplus command' do# {{{
230
- Parser.statement_type("accept muci").should eq("SQLPLUS")
231
- Parser.statement_type("acc muci").should eq("SQLPLUS")
232
- Parser.statement_type("acce muci").should eq("SQLPLUS")
233
- Parser.statement_type("@muci.sql").should eq("SQLPLUS")
234
- Parser.statement_type("@@muci.sql").should eq("SQLPLUS")
235
- Parser.statement_type("/").should eq("SQLPLUS")
236
- Parser.statement_type("archive log list").should eq("SQLPLUS")
237
- Parser.statement_type("attribute muci").should eq("SQLPLUS")
238
- Parser.statement_type("break on whatever").should eq("SQLPLUS")
239
- Parser.statement_type("btitle abc").should eq("SQLPLUS")
240
- Parser.statement_type("btit abc").should eq("SQLPLUS")
241
- Parser.statement_type("cle").should eq("SQLPLUS")
242
- Parser.statement_type("colu abc format a15").should eq("SQLPLUS")
243
- Parser.statement_type("compute on bla bla bla").should eq("SQLPLUS")
244
- Parser.statement_type("connect muci/buci@db").should eq("SQLPLUS")
245
- Parser.statement_type("copy").should eq("SQLPLUS")
246
- Parser.statement_type("def var").should eq("SQLPLUS")
247
- Parser.statement_type("desc my_table").should eq("SQLPLUS")
248
- Parser.statement_type("discon").should eq("SQLPLUS")
249
- Parser.statement_type("execu dbms_output.put_line('abc');").should eq("SQLPLUS")
250
- Parser.statement_type("exit").should eq("SQLPLUS")
251
- Parser.statement_type("quit").should eq("SQLPLUS")
252
- Parser.statement_type("help").should eq("SQLPLUS")
253
- Parser.statement_type("host ls -al").should eq("SQLPLUS")
254
- Parser.statement_type("!ls -al").should eq("SQLPLUS")
255
- Parser.statement_type("passw").should eq("SQLPLUS")
256
- Parser.statement_type("password user").should eq("SQLPLUS")
257
- Parser.statement_type("pause press any key").should eq("SQLPLUS")
258
- Parser.statement_type("print curs").should eq("SQLPLUS")
259
- Parser.statement_type("prom var").should eq("SQLPLUS")
260
- Parser.statement_type("recover database").should eq("SQLPLUS")
261
- Parser.statement_type("rem comment").should eq("SQLPLUS")
262
- Parser.statement_type("repf on").should eq("SQLPLUS")
263
- Parser.statement_type("rephe off").should eq("SQLPLUS")
264
- Parser.statement_type("sav muci.sql").should eq("SQLPLUS")
265
- Parser.statement_type("set pagesize 100").should eq("SQLPLUS")
266
- Parser.statement_type("set transaction name muci;").should be_nil
267
- Parser.statement_type("show pagesize").should eq("SQLPLUS")
268
- Parser.statement_type("shutdown").should eq("SQLPLUS")
269
- Parser.statement_type("spool muci.log").should eq("SQLPLUS")
270
- Parser.statement_type("start muci.sql").should eq("SQLPLUS")
271
- Parser.statement_type("startup").should eq("SQLPLUS")
272
- Parser.statement_type("store set options.sql").should eq("SQLPLUS")
273
- Parser.statement_type("timing stop").should eq("SQLPLUS")
274
- Parser.statement_type("title abc").should eq("SQLPLUS")
275
- Parser.statement_type("undef var").should eq("SQLPLUS")
276
- Parser.statement_type("var muci").should eq("SQLPLUS")
277
- Parser.statement_type("whenever oserror exit").should eq("SQLPLUS")
278
- Parser.statement_type("xquery bla bla bla").should eq("SQLPLUS")
279
- Parser.statement_type("\n-- APEX RMS DB UPDATES FILE\n").should be_nil
280
- end# }}}
281
-
282
- end# }}}
283
-
284
- it 'should get the current statement' do# {{{
285
- text = <<STRING
286
- select /* comment: ; */ 'muci;buci''s yea' from dual; -- interesting ha;ha?
287
- select * from cat;
288
- STRING
289
- Parser.current_statement(text, 10)[:statement].should eq("select /* comment: ; */ 'muci;buci''s yea' from dual;")
290
- Parser.current_statement(text, 85)[:statement].should eq(" -- interesting ha;ha?\nselect * from cat;")
291
-
292
- text = <<STRING
293
- set serveroutput on
294
- column c1 format a10
295
- select 1 from dual;
296
- begin
297
- null;
298
- end;
299
- /
300
- select c2 from t1
301
- /
302
- update t set x=1;
303
- STRING
304
- Parser.current_statement(text, 10, :sqlplus_commands => false, :plsql_blocks => false)[:statement].should eq("set serveroutput on\ncolumn c1 format a10\nselect 1 from dual;")
305
- Parser.current_statement(text, 10, :sqlplus_commands => true, :plsql_blocks => false)[:statement].should eq("set serveroutput on")
306
- Parser.current_statement(text, 71, :sqlplus_commands => true, :plsql_blocks => false)[:statement].should eq("\nbegin\n null;")
307
- Parser.current_statement(text, 71, :sqlplus_commands => true, :plsql_blocks => true)[:statement].should eq("\nbegin\n null;\nend;\n/\n")
308
- Parser.current_statement(text, 88, :sqlplus_commands => true, :plsql_blocks => true)[:statement].should eq("select c2 from t1\n/\n")
309
-
310
- text = <<STRING
311
- select * from all_objects where rownum <= 1000;
312
-
313
- set serveroutput on
314
- begin
315
- dbms_output.put_line('Hello Vorax!');
316
- end;
317
- /
318
-
319
- with
320
- x as (select *
321
- from (select file_id, file_name from dba_data_files) t,
322
- (select * from (select 'abc' col1, 'xyz' col2 from dual) x)
323
- )
324
- select *
325
- from x;
326
- STRING
327
- Parser.current_statement(text, 90, :sqlplus_commands => true, :plsql_blocks => true).
328
- should eq({:statement=>"begin\n\tdbms_output.put_line('Hello Vorax!');\nend;\n/\n", :range=>69...121})
329
-
330
- text = "exec dbms_crypto.encrypt("
331
- Parser.current_statement(text, 10, :plslq_blocks => true, :sqlplus_commands => true).
332
- should eq({:statement=>"exec dbms_crypto.encrypt(", :range=>0...25})
333
- end# }}}
334
-
335
- it 'should detect a for statement' do# {{{
336
- text = "for x in (select * from dual) loop "
337
- Parser.describe_for(text).should == {:cursor_var=>nil, :for_var=>"x", :expr=>"(select * from dual)", :end_pos=>34}
338
- text = "for x in l_cursor loop "
339
- Parser.describe_for(text).should == {:cursor_var=>"l_cursor", :for_var=>"x", :expr=>nil, :end_pos=>22}
340
- text = "for x in reverse 1..10 loop "
341
- Parser.describe_for(text).should == {:cursor_var=>nil, :for_var=>"x", :expr=>nil, :end_pos=>27}
342
- text = "for x in(select * from dual)loop "
343
- Parser.describe_for(text).should == {:cursor_var=>nil, :for_var=>"x", :expr=>"(select * from dual)", :end_pos=>32}
344
- text = "for x in reverse 1..10 loops "
345
- Parser.describe_for(text)[:end_pos].should == -1
346
- text = "for x in p.cursor loop "
347
- Parser.describe_for(text).should == {:cursor_var=>"p.cursor", :for_var=>"x", :expr=>nil, :end_pos=>22}
348
- text = "for x in user.p.cursor loop "
349
- Parser.describe_for(text).should == {:cursor_var=>"user.p.cursor", :for_var=>"x", :expr=>nil, :end_pos=>27}
350
- end# }}}
351
-
352
- end