each_sql 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +4 -0
- data/VERSION +1 -1
- data/lib/each_sql/each_sql.rb +10 -2
- data/lib/each_sql/parser/sql.citrus.erb +1 -1
- data/test/test_each_sql.rb +23 -26
- data/test/yml/common.yml +4 -0
- metadata +3 -3
data/CHANGELOG.markdown
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/each_sql/each_sql.rb
CHANGED
@@ -5,12 +5,13 @@ class EachSQL
|
|
5
5
|
include Enumerable
|
6
6
|
|
7
7
|
# @param[Symbol] type RDBMS type: :default|:mysql|:oracle|:postgres
|
8
|
-
|
8
|
+
# @param[String] delimiter Script delimiter.
|
9
|
+
def initialize type, delimiter = ';'
|
9
10
|
@type = type
|
10
11
|
@data = ''
|
11
12
|
@sqls = []
|
12
13
|
|
13
|
-
self.delimiter =
|
14
|
+
self.delimiter = delimiter
|
14
15
|
end
|
15
16
|
|
16
17
|
# @param[String] delim SQL delimiter
|
@@ -35,6 +36,13 @@ class EachSQL
|
|
35
36
|
self
|
36
37
|
end
|
37
38
|
|
39
|
+
# Clears the buffer
|
40
|
+
# @return [EachSQL]
|
41
|
+
def clear
|
42
|
+
@data = ''
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
38
46
|
# Parses current buffer and returns the result in Hash.
|
39
47
|
# :sqls is an Array of processed executable SQL blocks,
|
40
48
|
# :leftover is the unparsed trailing data
|
data/test/test_each_sql.rb
CHANGED
@@ -5,10 +5,30 @@ require 'helper'
|
|
5
5
|
require 'yaml'
|
6
6
|
|
7
7
|
class TestEachSql < Test::Unit::TestCase
|
8
|
-
def
|
8
|
+
def test_each_sql
|
9
|
+
esql = EachSQL.new(:default)
|
10
|
+
esql << "select"
|
11
|
+
result = esql.shift
|
12
|
+
assert_equal 0, result[:sqls].length
|
13
|
+
assert_equal 'select', result[:leftover]
|
14
|
+
|
15
|
+
esql << " * from table1; select * from table2;"
|
16
|
+
result = esql.shift
|
17
|
+
assert_equal ['select * from table1', 'select * from table2'], result[:sqls]
|
18
|
+
assert_equal nil, result[:leftover]
|
19
|
+
|
20
|
+
esql << "select * from table3;"
|
21
|
+
assert_equal esql, esql.clear
|
22
|
+
result = esql.shift
|
23
|
+
assert_equal 0, result[:sqls].length
|
24
|
+
assert_equal nil, result[:leftover]
|
25
|
+
end
|
26
|
+
|
27
|
+
# Acceptance tests
|
28
|
+
# ================
|
29
|
+
def test_empty
|
9
30
|
[nil, "", " \n" * 10].each do |input|
|
10
31
|
EachSQL(input).each do |sql|
|
11
|
-
p sql
|
12
32
|
assert false, 'Should not enumerate'
|
13
33
|
end
|
14
34
|
|
@@ -20,7 +40,7 @@ class TestEachSql < Test::Unit::TestCase
|
|
20
40
|
end
|
21
41
|
end
|
22
42
|
|
23
|
-
def
|
43
|
+
def test_parser_cache
|
24
44
|
[:default, :mysql, :oracle, :postgres].each do |typ|
|
25
45
|
%w[';', '$$', '//'].each do |delim|
|
26
46
|
arr =
|
@@ -71,27 +91,4 @@ class TestEachSql < Test::Unit::TestCase
|
|
71
91
|
assert_equal EachSQL(script, typ).to_a, EachSQL(script, typ).map { |e| e }
|
72
92
|
end
|
73
93
|
end
|
74
|
-
|
75
|
-
# def test_oracle
|
76
|
-
# EachSQL(@oracle_script, :oracle).each_with_index do |sql,idx|
|
77
|
-
# puts sql
|
78
|
-
# puts '-' * 40
|
79
|
-
# assert_equal @oracle[idx], sql
|
80
|
-
# end
|
81
|
-
# end
|
82
|
-
|
83
|
-
# def test_mysql
|
84
|
-
# EachSQL(@mysql_script, :mysql).each_with_index do |sql,idx|
|
85
|
-
# puts sql
|
86
|
-
# puts '-' * 40
|
87
|
-
# assert_equal @mysql[idx], sql
|
88
|
-
# end
|
89
|
-
# end
|
90
|
-
|
91
|
-
# def _test_postgres
|
92
|
-
# EachSQL(File.read(File.dirname(__FILE__) + '/postgres.sql'), :postgres).each_with_index do |sql,idx|
|
93
|
-
# puts sql
|
94
|
-
# puts '-' * 40
|
95
|
-
# end
|
96
|
-
# end
|
97
94
|
end
|
data/test/yml/common.yml
CHANGED
@@ -293,7 +293,9 @@ all: |
|
|
293
293
|
select
|
294
294
|
begin , begin.* from begin;
|
295
295
|
select b `begin` from dual;
|
296
|
+
begin transaction;
|
296
297
|
commit;
|
298
|
+
start transaction;
|
297
299
|
rollback;
|
298
300
|
select b "begin" from dual
|
299
301
|
|
@@ -596,6 +598,8 @@ each:
|
|
596
598
|
select
|
597
599
|
begin , begin.* from begin
|
598
600
|
- select b `begin` from dual
|
601
|
+
- begin transaction
|
599
602
|
- commit
|
603
|
+
- start transaction
|
600
604
|
- rollback
|
601
605
|
- select b "begin" from dual
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: each_sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: citrus
|
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
segments:
|
137
137
|
- 0
|
138
|
-
hash:
|
138
|
+
hash: 4467039074985070644
|
139
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
140
|
none: false
|
141
141
|
requirements:
|