ruby-plsql 0.5.3 → 0.8.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.
- checksums.yaml +5 -5
- data/.github/stale.yml +37 -0
- data/.github/workflows/rubocop.yml +37 -0
- data/.github/workflows/test.yml +69 -0
- data/.rubocop.yml +147 -0
- data/.travis.yml +88 -0
- data/.travis/oracle/download.sh +15 -0
- data/.travis/oracle/install.sh +32 -0
- data/.travis/setup_accounts.sh +9 -0
- data/Gemfile +17 -9
- data/History.txt +76 -0
- data/README.md +29 -6
- data/Rakefile +31 -26
- data/VERSION +1 -1
- data/Vagrantfile +4 -4
- data/ci/network/admin/tnsnames.ora +7 -0
- data/ci/setup_accounts.sh +9 -0
- data/gemfiles/Gemfile.activerecord-5.0 +21 -0
- data/gemfiles/Gemfile.activerecord-5.1 +21 -0
- data/gemfiles/Gemfile.activerecord-5.2 +21 -0
- data/gemfiles/Gemfile.activerecord-6.0 +21 -0
- data/gemfiles/Gemfile.activerecord-6.1 +21 -0
- data/gemfiles/Gemfile.activerecord-main +21 -0
- data/lib/plsql/connection.rb +19 -22
- data/lib/plsql/helpers.rb +1 -3
- data/lib/plsql/jdbc_connection.rb +70 -68
- data/lib/plsql/oci8_patches.rb +2 -2
- data/lib/plsql/oci_connection.rb +62 -77
- data/lib/plsql/package.rb +61 -46
- data/lib/plsql/procedure.rb +358 -78
- data/lib/plsql/procedure_call.rb +508 -463
- data/lib/plsql/schema.rb +96 -101
- data/lib/plsql/sequence.rb +10 -13
- data/lib/plsql/sql_statements.rb +9 -11
- data/lib/plsql/table.rb +60 -63
- data/lib/plsql/type.rb +71 -76
- data/lib/plsql/variable.rb +90 -94
- data/lib/plsql/version.rb +1 -1
- data/lib/plsql/view.rb +16 -19
- data/ruby-plsql.gemspec +55 -35
- data/spec/plsql/connection_spec.rb +72 -66
- data/spec/plsql/package_spec.rb +63 -14
- data/spec/plsql/procedure_spec.rb +603 -261
- data/spec/plsql/schema_spec.rb +47 -23
- data/spec/plsql/sequence_spec.rb +2 -2
- data/spec/plsql/sql_statements_spec.rb +6 -6
- data/spec/plsql/table_spec.rb +84 -79
- data/spec/plsql/type_spec.rb +24 -30
- data/spec/plsql/variable_spec.rb +80 -88
- data/spec/plsql/version_spec.rb +4 -4
- data/spec/plsql/view_spec.rb +42 -42
- data/spec/spec_helper.rb +38 -35
- data/spec/support/create_arunit_user.sql +2 -0
- data/spec/support/custom_config.rb.sample +14 -0
- data/spec/support/test_db.rb +12 -13
- data/spec/support/unlock_and_setup_hr_user.sql +2 -0
- metadata +111 -34
data/ruby-plsql.gemspec
CHANGED
@@ -1,23 +1,31 @@
|
|
1
|
-
# Generated by
|
1
|
+
# Generated by juwelier
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit
|
3
|
+
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
|
5
|
+
|
6
|
+
# stub: ruby-plsql 0.8.0 ruby lib
|
6
7
|
|
7
8
|
Gem::Specification.new do |s|
|
8
|
-
s.name = "ruby-plsql"
|
9
|
-
s.version = "0.
|
9
|
+
s.name = "ruby-plsql".freeze
|
10
|
+
s.version = "0.8.0"
|
10
11
|
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
-
s.require_paths = ["lib"]
|
13
|
-
s.authors = ["Raimonds Simanovskis"]
|
14
|
-
s.date = "
|
15
|
-
s.description = "ruby-plsql gem provides simple Ruby API for calling Oracle PL/SQL procedures.\
|
16
|
-
s.email = "raimonds.simanovskis@gmail.com"
|
12
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
13
|
+
s.require_paths = ["lib".freeze]
|
14
|
+
s.authors = ["Raimonds Simanovskis".freeze]
|
15
|
+
s.date = "2018-09-03"
|
16
|
+
s.description = " ruby-plsql gem provides simple Ruby API for calling Oracle PL/SQL procedures.\n It could be used both for accessing Oracle PL/SQL API procedures in legacy applications\n as well as it could be used to create PL/SQL unit tests using Ruby testing libraries.\n".freeze
|
17
|
+
s.email = "raimonds.simanovskis@gmail.com".freeze
|
17
18
|
s.extra_rdoc_files = [
|
18
19
|
"README.md"
|
19
20
|
]
|
20
21
|
s.files = [
|
22
|
+
".codeclimate.yml",
|
23
|
+
".github/stale.yml",
|
24
|
+
".rubocop.yml",
|
25
|
+
".travis.yml",
|
26
|
+
".travis/oracle/download.sh",
|
27
|
+
".travis/oracle/install.sh",
|
28
|
+
".travis/setup_accounts.sh",
|
21
29
|
"Gemfile",
|
22
30
|
"History.txt",
|
23
31
|
"License.txt",
|
@@ -25,6 +33,9 @@ Gem::Specification.new do |s|
|
|
25
33
|
"Rakefile",
|
26
34
|
"VERSION",
|
27
35
|
"Vagrantfile",
|
36
|
+
"gemfiles/Gemfile.activerecord-5.0",
|
37
|
+
"gemfiles/Gemfile.activerecord-5.1",
|
38
|
+
"gemfiles/Gemfile.activerecord-5.2",
|
28
39
|
"lib/plsql/connection.rb",
|
29
40
|
"lib/plsql/helpers.rb",
|
30
41
|
"lib/plsql/jdbc_connection.rb",
|
@@ -57,38 +68,47 @@ Gem::Specification.new do |s|
|
|
57
68
|
"spec/plsql/view_spec.rb",
|
58
69
|
"spec/spec.opts",
|
59
70
|
"spec/spec_helper.rb",
|
71
|
+
"spec/support/create_arunit_user.sql",
|
72
|
+
"spec/support/custom_config.rb.sample",
|
60
73
|
"spec/support/file_check_script.sh",
|
61
|
-
"spec/support/test_db.rb"
|
74
|
+
"spec/support/test_db.rb",
|
75
|
+
"spec/support/unlock_and_setup_hr_user.sql"
|
62
76
|
]
|
63
|
-
s.homepage = "http://github.com/rsim/ruby-plsql"
|
64
|
-
s.
|
65
|
-
s.
|
77
|
+
s.homepage = "http://github.com/rsim/ruby-plsql".freeze
|
78
|
+
s.licenses = ["MIT".freeze]
|
79
|
+
s.rubygems_version = "2.7.7".freeze
|
80
|
+
s.summary = "Ruby API for calling Oracle PL/SQL procedures.".freeze
|
66
81
|
|
67
82
|
if s.respond_to? :specification_version then
|
68
83
|
s.specification_version = 4
|
69
84
|
|
70
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new(
|
71
|
-
s.add_development_dependency(
|
72
|
-
s.add_development_dependency(
|
73
|
-
s.add_development_dependency(
|
74
|
-
s.add_development_dependency(
|
75
|
-
s.add_development_dependency(
|
76
|
-
s.add_development_dependency(
|
85
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("1.2.0") then
|
86
|
+
s.add_development_dependency("juwelier".freeze, ["~> 2.0"])
|
87
|
+
s.add_development_dependency("rspec_junit_formatter".freeze, [">= 0"])
|
88
|
+
s.add_development_dependency("rake".freeze, [">= 10.0"])
|
89
|
+
s.add_development_dependency("rspec".freeze, ["~> 3.1"])
|
90
|
+
s.add_development_dependency("activerecord".freeze, ["~> 5.0"])
|
91
|
+
s.add_development_dependency("activerecord-oracle_enhanced-adapter".freeze, ["~> 1.7"])
|
92
|
+
s.add_development_dependency("simplecov".freeze, [">= 0"])
|
93
|
+
s.add_development_dependency("ruby-oci8".freeze, ["~> 2.1"])
|
77
94
|
else
|
78
|
-
s.add_dependency(
|
79
|
-
s.add_dependency(
|
80
|
-
s.add_dependency(
|
81
|
-
s.add_dependency(
|
82
|
-
s.add_dependency(
|
83
|
-
s.add_dependency(
|
95
|
+
s.add_dependency("juwelier".freeze, ["~> 2.0"])
|
96
|
+
s.add_dependency("rspec_junit_formatter".freeze, [">= 0"])
|
97
|
+
s.add_dependency("rake".freeze, [">= 10.0"])
|
98
|
+
s.add_dependency("rspec".freeze, ["~> 3.1"])
|
99
|
+
s.add_dependency("activerecord".freeze, ["~> 5.0"])
|
100
|
+
s.add_dependency("activerecord-oracle_enhanced-adapter".freeze, ["~> 1.7"])
|
101
|
+
s.add_dependency("simplecov".freeze, [">= 0"])
|
102
|
+
s.add_dependency("ruby-oci8".freeze, ["~> 2.1"])
|
84
103
|
end
|
85
104
|
else
|
86
|
-
s.add_dependency(
|
87
|
-
s.add_dependency(
|
88
|
-
s.add_dependency(
|
89
|
-
s.add_dependency(
|
90
|
-
s.add_dependency(
|
91
|
-
s.add_dependency(
|
105
|
+
s.add_dependency("juwelier".freeze, ["~> 2.0"])
|
106
|
+
s.add_dependency("rspec_junit_formatter".freeze, [">= 0"])
|
107
|
+
s.add_dependency("rake".freeze, [">= 10.0"])
|
108
|
+
s.add_dependency("rspec".freeze, ["~> 3.1"])
|
109
|
+
s.add_dependency("activerecord".freeze, ["~> 5.0"])
|
110
|
+
s.add_dependency("activerecord-oracle_enhanced-adapter".freeze, ["~> 1.7"])
|
111
|
+
s.add_dependency("simplecov".freeze, [">= 0"])
|
112
|
+
s.add_dependency("ruby-oci8".freeze, ["~> 2.1"])
|
92
113
|
end
|
93
114
|
end
|
94
|
-
|
@@ -1,13 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe "Connection" do
|
6
6
|
|
7
7
|
before(:all) do
|
8
8
|
@raw_conn = get_connection
|
9
|
-
@conn = PLSQL::Connection.create(
|
10
|
-
@conn.set_time_zone
|
9
|
+
@conn = PLSQL::Connection.create(@raw_conn)
|
11
10
|
end
|
12
11
|
|
13
12
|
after(:all) do
|
@@ -24,8 +23,7 @@ describe "Connection" do
|
|
24
23
|
end
|
25
24
|
|
26
25
|
before(:each) do
|
27
|
-
@conn1 = PLSQL::Connection.create(
|
28
|
-
@conn1.set_time_zone
|
26
|
+
@conn1 = PLSQL::Connection.create(@raw_conn1)
|
29
27
|
end
|
30
28
|
|
31
29
|
it "should create connection" do
|
@@ -53,38 +51,43 @@ describe "Connection" do
|
|
53
51
|
# Ruby 1.8 and 1.9
|
54
52
|
unless defined?(JRuby)
|
55
53
|
describe "OCI data type conversions" do
|
54
|
+
it "should translate PL/SQL VARCHAR to Ruby String" do
|
55
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR", data_length: 100)).to eq [String, 100]
|
56
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR", data_length: nil)).to eq [String, 32767]
|
57
|
+
end
|
58
|
+
|
56
59
|
it "should translate PL/SQL VARCHAR2 to Ruby String" do
|
57
|
-
expect(@conn.plsql_to_ruby_data_type(:
|
58
|
-
expect(@conn.plsql_to_ruby_data_type(:
|
60
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR2", data_length: 100)).to eq [String, 100]
|
61
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR2", data_length: nil)).to eq [String, 32767]
|
59
62
|
end
|
60
63
|
|
61
64
|
it "should translate PL/SQL CLOB to Ruby String" do
|
62
|
-
expect(@conn.plsql_to_ruby_data_type(:
|
63
|
-
expect(@conn.plsql_to_ruby_data_type(:
|
65
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "CLOB", data_length: 100_000)).to eq [OCI8::CLOB, nil]
|
66
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "CLOB", data_length: nil)).to eq [OCI8::CLOB, nil]
|
64
67
|
end
|
65
68
|
|
66
69
|
it "should translate PL/SQL NUMBER to Ruby OraNumber" do
|
67
|
-
expect(@conn.plsql_to_ruby_data_type(:
|
70
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "NUMBER", data_length: 15)).to eq [OraNumber, nil]
|
68
71
|
end
|
69
72
|
|
70
73
|
it "should translate PL/SQL DATE to Ruby DateTime" do
|
71
|
-
expect(@conn.plsql_to_ruby_data_type(:
|
74
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "DATE", data_length: nil)).to eq [DateTime, nil]
|
72
75
|
end
|
73
76
|
|
74
77
|
it "should translate PL/SQL TIMESTAMP to Ruby Time" do
|
75
|
-
expect(@conn.plsql_to_ruby_data_type(:
|
78
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "TIMESTAMP", data_length: nil)).to eq [Time, nil]
|
76
79
|
end
|
77
80
|
|
78
|
-
it "should not translate Ruby
|
81
|
+
it "should not translate small Ruby Integer when OraNumber type specified" do
|
79
82
|
expect(@conn.ruby_value_to_ora_value(100, OraNumber)).to eql(100)
|
80
83
|
end
|
81
84
|
|
82
|
-
it "should translate Ruby
|
85
|
+
it "should not translate big Ruby Integer when OraNumber type specified" do
|
83
86
|
ora_number = @conn.ruby_value_to_ora_value(12345678901234567890, OraNumber)
|
84
|
-
expect(ora_number
|
87
|
+
expect(ora_number).to be_an Integer
|
85
88
|
expect(ora_number.to_s).to eq "12345678901234567890"
|
86
89
|
# OraNumber has more numeric comparison methods in ruby-oci8 2.0
|
87
|
-
expect(ora_number).to eq OraNumber.new("12345678901234567890") if OCI8::VERSION >=
|
90
|
+
expect(ora_number).to eq OraNumber.new("12345678901234567890") if OCI8::VERSION >= "2.0.0"
|
88
91
|
end
|
89
92
|
|
90
93
|
it "should translate Ruby String value to OCI8::CLOB when OCI8::CLOB type specified" do
|
@@ -96,7 +99,7 @@ describe "Connection" do
|
|
96
99
|
expect(ora_value.read).to eq large_text
|
97
100
|
end
|
98
101
|
|
99
|
-
it "should translate Oracle OraNumber integer value to
|
102
|
+
it "should translate Oracle OraNumber integer value to Integer" do
|
100
103
|
expect(@conn.ora_value_to_ruby_value(OraNumber.new(100))).to eql(100)
|
101
104
|
end
|
102
105
|
|
@@ -105,7 +108,7 @@ describe "Connection" do
|
|
105
108
|
end
|
106
109
|
|
107
110
|
# ruby-oci8 2.0 returns DATE as Time or DateTime
|
108
|
-
if OCI8::VERSION <
|
111
|
+
if OCI8::VERSION < "2.0.0"
|
109
112
|
it "should translate Oracle OraDate value to Time" do
|
110
113
|
now = OraDate.now
|
111
114
|
expect(@conn.ora_value_to_ruby_value(now)).to eql(now.to_time)
|
@@ -124,32 +127,36 @@ describe "Connection" do
|
|
124
127
|
else
|
125
128
|
|
126
129
|
describe "JDBC data type conversions" do
|
130
|
+
it "should translate PL/SQL VARCHAR to Ruby String" do
|
131
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR", data_length: 100)).to eq [String, 100]
|
132
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR", data_length: nil)).to eq [String, 32767]
|
133
|
+
end
|
127
134
|
it "should translate PL/SQL VARCHAR2 to Ruby String" do
|
128
|
-
expect(@conn.plsql_to_ruby_data_type(:
|
129
|
-
expect(@conn.plsql_to_ruby_data_type(:
|
135
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR2", data_length: 100)).to eq [String, 100]
|
136
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR2", data_length: nil)).to eq [String, 32767]
|
130
137
|
end
|
131
138
|
|
132
139
|
it "should translate PL/SQL NUMBER to Ruby BigDecimal" do
|
133
|
-
expect(@conn.plsql_to_ruby_data_type(:
|
140
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "NUMBER", data_length: 15)).to eq [BigDecimal, nil]
|
134
141
|
end
|
135
142
|
|
136
143
|
it "should translate PL/SQL DATE to Ruby DateTime" do
|
137
|
-
expect(@conn.plsql_to_ruby_data_type(:
|
144
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "DATE", data_length: nil)).to eq [DateTime, nil]
|
138
145
|
end
|
139
146
|
|
140
147
|
it "should translate PL/SQL TIMESTAMP to Ruby Time" do
|
141
|
-
expect(@conn.plsql_to_ruby_data_type(:
|
148
|
+
expect(@conn.plsql_to_ruby_data_type(data_type: "TIMESTAMP", data_length: nil)).to eq [Time, nil]
|
142
149
|
end
|
143
150
|
|
144
|
-
it "should not translate Ruby
|
151
|
+
it "should not translate Ruby Integer when BigDecimal type specified" do
|
145
152
|
expect(@conn.ruby_value_to_ora_value(100, BigDecimal)).to eq java.math.BigDecimal.new(100)
|
146
153
|
end
|
147
154
|
|
148
155
|
it "should translate Ruby String to string value" do
|
149
|
-
expect(@conn.ruby_value_to_ora_value(1.1, String)).to eq
|
156
|
+
expect(@conn.ruby_value_to_ora_value(1.1, String)).to eq "1.1"
|
150
157
|
end
|
151
158
|
|
152
|
-
it "should translate Ruby
|
159
|
+
it "should translate Ruby Integer value to BigDecimal when BigDecimal type specified" do
|
153
160
|
big_decimal = @conn.ruby_value_to_ora_value(12345678901234567890, BigDecimal)
|
154
161
|
expect(big_decimal).to eq java.math.BigDecimal.new("12345678901234567890")
|
155
162
|
end
|
@@ -168,7 +175,7 @@ describe "Connection" do
|
|
168
175
|
expect(ora_value).to be_nil
|
169
176
|
end
|
170
177
|
|
171
|
-
it "should translate Oracle BigDecimal integer value to
|
178
|
+
it "should translate Oracle BigDecimal integer value to Integer" do
|
172
179
|
expect(@conn.ora_value_to_ruby_value(BigDecimal("100"))).to eql(100)
|
173
180
|
end
|
174
181
|
|
@@ -195,87 +202,87 @@ describe "Connection" do
|
|
195
202
|
describe "SQL SELECT statements" do
|
196
203
|
|
197
204
|
it "should execute SQL statement and return first result" do
|
198
|
-
@now = Time.local(2008,05,31,23,22,11)
|
205
|
+
@now = Time.local(2008, 05, 31, 23, 22, 11)
|
199
206
|
expect(@conn.select_first("SELECT 'abc',123,123.456,
|
200
207
|
TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
|
201
|
-
FROM dual")).to eq ["abc",123,123.456
|
208
|
+
FROM dual")).to eq ["abc", 123, 123.456, @now]
|
202
209
|
end
|
203
210
|
|
204
211
|
it "should execute SQL statement and return first result as hash" do
|
205
|
-
@now = Time.local(2008,05,31,23,22,11)
|
212
|
+
@now = Time.local(2008, 05, 31, 23, 22, 11)
|
206
213
|
expect(@conn.select_hash_first("SELECT 'abc' a, 123 b, 123.456 c,
|
207
214
|
TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}', 'YYYY-MM-DD HH24:MI:SS') d
|
208
|
-
FROM dual")).to eq(
|
215
|
+
FROM dual")).to eq(a: "abc", b: 123, c: 123.456, d: @now)
|
209
216
|
end
|
210
217
|
|
211
218
|
it "should execute SQL statement with bind parameters and return first result" do
|
212
219
|
@today = Date.parse("2008-05-31")
|
213
|
-
@now = Time.local(2008,05,31,23,22,11)
|
220
|
+
@now = Time.local(2008, 05, 31, 23, 22, 11)
|
214
221
|
expect(@conn.select_first("SELECT :1,:2,:3,:4,:5 FROM dual",
|
215
|
-
|
222
|
+
"abc", 123, 123.456, @now, @today)).to eq ["abc", 123, 123.456, @now, Time.parse(@today.to_s)]
|
216
223
|
end
|
217
224
|
|
218
225
|
it "should execute SQL statement with NULL values and return first result" do
|
219
|
-
@now = Time.local(2008,05,31,23,22,11)
|
226
|
+
@now = Time.local(2008, 05, 31, 23, 22, 11)
|
220
227
|
expect(@conn.select_first("SELECT NULL,123,123.456,
|
221
228
|
TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
|
222
|
-
FROM dual")).to eq [nil,123,123.456
|
229
|
+
FROM dual")).to eq [nil, 123, 123.456, @now]
|
223
230
|
end
|
224
231
|
|
225
232
|
if defined?(JRuby)
|
226
233
|
|
227
234
|
it "should execute SQL statement with NULL values as bind parameters and return first result" do
|
228
235
|
@today = Date.parse("2008-05-31")
|
229
|
-
@now = Time.local(2008,05,31,23,22,11)
|
236
|
+
@now = Time.local(2008, 05, 31, 23, 22, 11)
|
230
237
|
expect(@conn.select_first("SELECT :1,:2,:3,:4,:5 FROM dual",
|
231
|
-
nil,123,123.456
|
238
|
+
nil, 123, 123.456, @now, @today)).to eq [nil, 123, 123.456, @now, Time.parse(@today.to_s)]
|
232
239
|
end
|
233
240
|
|
234
241
|
end
|
235
242
|
|
236
243
|
it "should execute SQL statement and return all results" do
|
237
|
-
@now = Time.local(2008,05,31,23,22,11)
|
244
|
+
@now = Time.local(2008, 05, 31, 23, 22, 11)
|
238
245
|
expect(@conn.select_all("SELECT 'abc',123,123.456,
|
239
246
|
TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
|
240
247
|
FROM dual
|
241
248
|
UNION ALL SELECT 'abc',123,123.456,
|
242
249
|
TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
|
243
|
-
FROM dual")).to eq [["abc",123,123.456
|
250
|
+
FROM dual")).to eq [["abc", 123, 123.456, @now], ["abc", 123, 123.456, @now]]
|
244
251
|
end
|
245
252
|
|
246
253
|
it "should execute SQL statement and return all results as hash" do
|
247
|
-
@now = Time.local(2008,05,31,23,22,11)
|
254
|
+
@now = Time.local(2008, 05, 31, 23, 22, 11)
|
248
255
|
expect(@conn.select_hash_all("SELECT 'abc' a, 123 b, 123.456 c,
|
249
256
|
TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS') d
|
250
257
|
FROM dual
|
251
258
|
UNION ALL SELECT 'def' a, 123 b, 123.456 c,
|
252
259
|
TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS') d
|
253
|
-
FROM dual")).to eq [{:
|
260
|
+
FROM dual")).to eq [{ a: "abc", b: 123, c: 123.456, d: @now }, { a: "def", b: 123, c: 123.456, d: @now }]
|
254
261
|
end
|
255
262
|
|
256
263
|
it "should execute SQL statement with bind parameters and return all results" do
|
257
|
-
@now = Time.local(2008,05,31,23,22,11)
|
264
|
+
@now = Time.local(2008, 05, 31, 23, 22, 11)
|
258
265
|
expect(@conn.select_all("SELECT :1,:2,:3,:4 FROM dual UNION ALL SELECT :1,:2,:3,:4 FROM dual",
|
259
|
-
|
266
|
+
"abc", 123, 123.456, @now, "abc", 123, 123.456, @now)).to eq [["abc", 123, 123.456, @now], ["abc", 123, 123.456, @now]]
|
260
267
|
end
|
261
268
|
|
262
269
|
it "should execute SQL statement and yield all results in block" do
|
263
|
-
@now = Time.local(2008,05,31,23,22,11)
|
270
|
+
@now = Time.local(2008, 05, 31, 23, 22, 11)
|
264
271
|
expect(@conn.select_all("SELECT 'abc',123,123.456,
|
265
272
|
TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
|
266
273
|
FROM dual
|
267
274
|
UNION ALL SELECT 'abc',123,123.456,
|
268
275
|
TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
|
269
276
|
FROM dual") do |r|
|
270
|
-
expect(r).to eq ["abc",123,123.456
|
277
|
+
expect(r).to eq ["abc", 123, 123.456, @now]
|
271
278
|
end).to eq 2
|
272
279
|
end
|
273
280
|
|
274
281
|
it "should execute SQL statement with bind parameters and yield all results in block" do
|
275
|
-
@now = Time.local(2008,05,31,23,22,11)
|
282
|
+
@now = Time.local(2008, 05, 31, 23, 22, 11)
|
276
283
|
expect(@conn.select_all("SELECT :1,:2,:3,:4 FROM dual UNION ALL SELECT :1,:2,:3,:4 FROM dual",
|
277
|
-
|
278
|
-
expect(r).to eq ["abc",123,123.456
|
284
|
+
"abc", 123, 123.456, @now, "abc", 123, 123.456, @now) do |r|
|
285
|
+
expect(r).to eq ["abc", 123, 123.456, @now]
|
279
286
|
end).to eq 2
|
280
287
|
end
|
281
288
|
|
@@ -284,7 +291,7 @@ describe "Connection" do
|
|
284
291
|
describe "PL/SQL procedures" do
|
285
292
|
before(:all) do
|
286
293
|
@random = rand(1000)
|
287
|
-
@now = Time.local(2008,05,31,23,22,11)
|
294
|
+
@now = Time.local(2008, 05, 31, 23, 22, 11)
|
288
295
|
sql = <<-SQL
|
289
296
|
CREATE OR REPLACE FUNCTION test_add_random (p_number NUMBER, p_varchar IN OUT VARCHAR2, p_date IN OUT DATE)
|
290
297
|
RETURN NUMBER
|
@@ -307,10 +314,10 @@ describe "Connection" do
|
|
307
314
|
END;
|
308
315
|
SQL
|
309
316
|
cursor = @conn.parse(sql)
|
310
|
-
cursor.bind_param(":result", nil, :
|
311
|
-
cursor.bind_param(":p_number", 100, :
|
312
|
-
cursor.bind_param(":p_varchar", "abc", :
|
313
|
-
cursor.bind_param(":p_date", @now, :
|
317
|
+
cursor.bind_param(":result", nil, data_type: "NUMBER", in_out: "OUT")
|
318
|
+
cursor.bind_param(":p_number", 100, data_type: "NUMBER", in_out: "IN")
|
319
|
+
cursor.bind_param(":p_varchar", "abc", data_type: "VARCHAR2", in_out: "IN/OUT")
|
320
|
+
cursor.bind_param(":p_date", @now, data_type: "DATE", in_out: "IN/OUT")
|
314
321
|
cursor.exec
|
315
322
|
expect(cursor[":result"]).to eq @random + 100
|
316
323
|
expect(cursor[":p_varchar"]).to eq "abc"
|
@@ -394,21 +401,21 @@ describe "Connection" do
|
|
394
401
|
end
|
395
402
|
|
396
403
|
it "should describe local synonym" do
|
397
|
-
expect(@conn.describe_synonym(
|
398
|
-
expect(@conn.describe_synonym(
|
399
|
-
expect(@conn.describe_synonym(:hr
|
404
|
+
expect(@conn.describe_synonym("HR", "SYNONYM_FOR_DUAL")).to eq ["SYS", "DUAL"]
|
405
|
+
expect(@conn.describe_synonym("hr", "synonym_for_dual")).to eq ["SYS", "DUAL"]
|
406
|
+
expect(@conn.describe_synonym(:hr, :synonym_for_dual)).to eq ["SYS", "DUAL"]
|
400
407
|
end
|
401
408
|
|
402
409
|
it "should return nil on non-existing synonym" do
|
403
|
-
expect(@conn.describe_synonym(
|
404
|
-
expect(@conn.describe_synonym(
|
405
|
-
expect(@conn.describe_synonym(:hr
|
410
|
+
expect(@conn.describe_synonym("HR", "SYNONYM_FOR_XXX")).to be_nil
|
411
|
+
expect(@conn.describe_synonym("hr", "synonym_for_xxx")).to be_nil
|
412
|
+
expect(@conn.describe_synonym(:hr, :synonym_for_xxx)).to be_nil
|
406
413
|
end
|
407
414
|
|
408
415
|
it "should describe public synonym" do
|
409
|
-
expect(@conn.describe_synonym(
|
410
|
-
expect(@conn.describe_synonym(
|
411
|
-
expect(@conn.describe_synonym(
|
416
|
+
expect(@conn.describe_synonym("PUBLIC", "DUAL")).to eq ["SYS", "DUAL"]
|
417
|
+
expect(@conn.describe_synonym("PUBLIC", "dual")).to eq ["SYS", "DUAL"]
|
418
|
+
expect(@conn.describe_synonym("PUBLIC", :dual)).to eq ["SYS", "DUAL"]
|
412
419
|
end
|
413
420
|
|
414
421
|
end
|
@@ -416,7 +423,7 @@ describe "Connection" do
|
|
416
423
|
describe "session information" do
|
417
424
|
it "should get database version" do
|
418
425
|
# using Oracle version 10.2.0.4 for unit tests
|
419
|
-
expect(@conn.database_version).to eq DATABASE_VERSION.split(
|
426
|
+
expect(@conn.database_version).to eq DATABASE_VERSION.split(".").map { |n| n.to_i }
|
420
427
|
end
|
421
428
|
|
422
429
|
it "should get session ID" do
|
@@ -446,7 +453,7 @@ describe "Connection" do
|
|
446
453
|
end
|
447
454
|
|
448
455
|
it "should not drop other session ruby temporary tables" do
|
449
|
-
tmp_table = "ruby_#{@conn.session_id+1}_222_333"
|
456
|
+
tmp_table = "ruby_#{@conn.session_id + 1}_222_333"
|
450
457
|
@conn.exec "CREATE GLOBAL TEMPORARY TABLE #{tmp_table} (dummy CHAR(1))"
|
451
458
|
expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.not_to raise_error
|
452
459
|
@conn.drop_session_ruby_temporary_tables
|
@@ -467,8 +474,7 @@ describe "Connection" do
|
|
467
474
|
|
468
475
|
def reconnect_connection
|
469
476
|
@raw_conn = get_connection
|
470
|
-
@conn = PLSQL::Connection.create(
|
471
|
-
@conn.set_time_zone
|
477
|
+
@conn = PLSQL::Connection.create(@raw_conn)
|
472
478
|
end
|
473
479
|
|
474
480
|
it "should drop current session ruby temporary tables" do
|