vorax 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/vorax/parser/parser.rb +27 -3
- data/lib/vorax/version.rb +1 -1
- data/spec/parser_spec.rb +24 -0
- metadata +1 -1
data/Rakefile
CHANGED
data/lib/vorax/parser/parser.rb
CHANGED
@@ -303,14 +303,38 @@ module Vorax
|
|
303
303
|
if opts[:sqlplus_commands]
|
304
304
|
walker.register_spot(Parser::SQLPLUS_TERMINATOR) do |scanner|
|
305
305
|
type = Parser.statement_type(scanner.string[(start_pos..scanner.pos)])
|
306
|
-
if type
|
307
|
-
|
308
|
-
|
306
|
+
if type
|
307
|
+
if type == 'SQLPLUS'
|
308
|
+
if (start_pos..scanner.pos-1).include?(position)
|
309
|
+
end_pos = scanner.pos - scanner.matched.length
|
310
|
+
scanner.terminate
|
311
|
+
else
|
312
|
+
start_pos = scanner.pos
|
313
|
+
end
|
314
|
+
else
|
315
|
+
if opts[:plsql_blocks]
|
316
|
+
#this is a plsql block, eat till the slash terminator
|
317
|
+
if scanner.scan_until(Parser::SLASH_TERMINATOR)
|
318
|
+
if (start_pos..scanner.pos-1).include?(position)
|
319
|
+
end_pos = scanner.pos
|
320
|
+
scanner.terminate
|
321
|
+
else
|
322
|
+
start_pos = scanner.pos
|
323
|
+
end
|
324
|
+
else
|
325
|
+
#it's an invalid statement
|
326
|
+
scanner.terminate
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
#else
|
331
|
+
#start_pos = scanner.pos
|
309
332
|
end
|
310
333
|
end
|
311
334
|
end
|
312
335
|
|
313
336
|
walker.walk
|
337
|
+
end_pos = script_content.length if end_pos == 0 #partial statement
|
314
338
|
{:statement => script_content[(start_pos...end_pos)], :range => (start_pos...end_pos)}
|
315
339
|
|
316
340
|
end
|
data/lib/vorax/version.rb
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -294,6 +294,30 @@ STRING
|
|
294
294
|
Parser.current_statement(text, 71, :sqlplus_commands => true, :plsql_blocks => false)[:statement].should eq("\nbegin\n null;")
|
295
295
|
Parser.current_statement(text, 71, :sqlplus_commands => true, :plsql_blocks => true)[:statement].should eq("\nbegin\n null;\nend;\n/\n")
|
296
296
|
Parser.current_statement(text, 88, :sqlplus_commands => true, :plsql_blocks => true)[:statement].should eq("select c2 from t1\n/\n")
|
297
|
+
|
298
|
+
text = <<STRING
|
299
|
+
select * from all_objects where rownum <= 1000;
|
300
|
+
|
301
|
+
set serveroutput on
|
302
|
+
begin
|
303
|
+
dbms_output.put_line('Hello Vorax!');
|
304
|
+
end;
|
305
|
+
/
|
306
|
+
|
307
|
+
with
|
308
|
+
x as (select *
|
309
|
+
from (select file_id, file_name from dba_data_files) t,
|
310
|
+
(select * from (select 'abc' col1, 'xyz' col2 from dual) x)
|
311
|
+
)
|
312
|
+
select *
|
313
|
+
from x;
|
314
|
+
STRING
|
315
|
+
Parser.current_statement(text, 90, :sqlplus_commands => true, :plsql_blocks => true).
|
316
|
+
should eq({:statement=>"begin\n\tdbms_output.put_line('Hello Vorax!');\nend;\n/\n", :range=>69...121})
|
317
|
+
|
318
|
+
text = "exec dbms_crypto.encrypt("
|
319
|
+
Parser.current_statement(text, 10, :plslq_blocks => true, :sqlplus_commands => true).
|
320
|
+
should eq({:statement=>"exec dbms_crypto.encrypt(", :range=>0...25})
|
297
321
|
end# }}}
|
298
322
|
|
299
323
|
end
|