Class: Ruport::Query::SqlSplit

Inherits:
Array
  • Object
show all
Defined in:
lib/ruport/query/sql_split.rb

Overview

This class properly splits up multi-statement SQL input for use with Ruby/DBI

Instance Method Summary collapse

Methods inherited from Array

#to_ds

Constructor Details

#initialize(sql) ⇒ SqlSplit

Returns a new instance of SqlSplit.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ruport/query/sql_split.rb', line 16

def initialize( sql )
	super()
	next_sql = ''
	sql.each do |line|
		unless line =~ /^--/ or line =~ %r{^/\*.*\*/;} or line =~ /^\s*$/
			next_sql << line
			if line =~ /;$/
				next_sql.gsub!( /;\s$/, '' )
				self << next_sql
				next_sql = ''
			end
		end
	end
	self << next_sql if next_sql != ''
end