ruby-plsql 0.8.0 → 0.9.9

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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +2 -0
  3. data/README.md +19 -3
  4. data/VERSION +1 -1
  5. data/lib/plsql/connection.rb +14 -14
  6. data/lib/plsql/helpers.rb +3 -3
  7. data/lib/plsql/jdbc_connection.rb +62 -22
  8. data/lib/plsql/oci_connection.rb +10 -10
  9. data/lib/plsql/package.rb +3 -3
  10. data/lib/plsql/procedure.rb +57 -22
  11. data/lib/plsql/procedure_call.rb +15 -15
  12. data/lib/plsql/schema.rb +17 -10
  13. data/lib/plsql/sequence.rb +2 -2
  14. data/lib/plsql/table.rb +6 -6
  15. data/lib/plsql/type.rb +7 -7
  16. data/lib/plsql/variable.rb +6 -5
  17. data/lib/plsql/version.rb +1 -1
  18. data/lib/plsql/view.rb +2 -2
  19. metadata +14 -140
  20. data/.github/stale.yml +0 -37
  21. data/.github/workflows/rubocop.yml +0 -37
  22. data/.github/workflows/test.yml +0 -69
  23. data/.rubocop.yml +0 -147
  24. data/.travis/oracle/download.sh +0 -15
  25. data/.travis/oracle/install.sh +0 -32
  26. data/.travis/setup_accounts.sh +0 -9
  27. data/.travis.yml +0 -88
  28. data/Gemfile +0 -24
  29. data/Rakefile +0 -53
  30. data/Vagrantfile +0 -38
  31. data/ci/network/admin/tnsnames.ora +0 -7
  32. data/ci/setup_accounts.sh +0 -9
  33. data/gemfiles/Gemfile.activerecord-5.0 +0 -21
  34. data/gemfiles/Gemfile.activerecord-5.1 +0 -21
  35. data/gemfiles/Gemfile.activerecord-5.2 +0 -21
  36. data/gemfiles/Gemfile.activerecord-6.0 +0 -21
  37. data/gemfiles/Gemfile.activerecord-6.1 +0 -21
  38. data/gemfiles/Gemfile.activerecord-main +0 -21
  39. data/lib/plsql/oci8_patches.rb +0 -25
  40. data/ruby-plsql.gemspec +0 -114
  41. data/spec/plsql/connection_spec.rb +0 -505
  42. data/spec/plsql/package_spec.rb +0 -172
  43. data/spec/plsql/procedure_spec.rb +0 -2390
  44. data/spec/plsql/schema_spec.rb +0 -364
  45. data/spec/plsql/sequence_spec.rb +0 -67
  46. data/spec/plsql/sql_statements_spec.rb +0 -91
  47. data/spec/plsql/table_spec.rb +0 -376
  48. data/spec/plsql/type_spec.rb +0 -299
  49. data/spec/plsql/variable_spec.rb +0 -497
  50. data/spec/plsql/version_spec.rb +0 -8
  51. data/spec/plsql/view_spec.rb +0 -264
  52. data/spec/spec.opts +0 -6
  53. data/spec/spec_helper.rb +0 -121
  54. data/spec/support/create_arunit_user.sql +0 -2
  55. data/spec/support/custom_config.rb.sample +0 -14
  56. data/spec/support/file_check_script.sh +0 -9
  57. data/spec/support/test_db.rb +0 -149
  58. data/spec/support/unlock_and_setup_hr_user.sql +0 -2
data/ruby-plsql.gemspec DELETED
@@ -1,114 +0,0 @@
1
- # Generated by juwelier
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- # stub: ruby-plsql 0.8.0 ruby lib
7
-
8
- Gem::Specification.new do |s|
9
- s.name = "ruby-plsql".freeze
10
- s.version = "0.8.0"
11
-
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
18
- s.extra_rdoc_files = [
19
- "README.md"
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",
29
- "Gemfile",
30
- "History.txt",
31
- "License.txt",
32
- "README.md",
33
- "Rakefile",
34
- "VERSION",
35
- "Vagrantfile",
36
- "gemfiles/Gemfile.activerecord-5.0",
37
- "gemfiles/Gemfile.activerecord-5.1",
38
- "gemfiles/Gemfile.activerecord-5.2",
39
- "lib/plsql/connection.rb",
40
- "lib/plsql/helpers.rb",
41
- "lib/plsql/jdbc_connection.rb",
42
- "lib/plsql/oci8_patches.rb",
43
- "lib/plsql/oci_connection.rb",
44
- "lib/plsql/package.rb",
45
- "lib/plsql/procedure.rb",
46
- "lib/plsql/procedure_call.rb",
47
- "lib/plsql/schema.rb",
48
- "lib/plsql/sequence.rb",
49
- "lib/plsql/sql_statements.rb",
50
- "lib/plsql/table.rb",
51
- "lib/plsql/type.rb",
52
- "lib/plsql/variable.rb",
53
- "lib/plsql/version.rb",
54
- "lib/plsql/view.rb",
55
- "lib/ruby-plsql.rb",
56
- "lib/ruby_plsql.rb",
57
- "ruby-plsql.gemspec",
58
- "spec/plsql/connection_spec.rb",
59
- "spec/plsql/package_spec.rb",
60
- "spec/plsql/procedure_spec.rb",
61
- "spec/plsql/schema_spec.rb",
62
- "spec/plsql/sequence_spec.rb",
63
- "spec/plsql/sql_statements_spec.rb",
64
- "spec/plsql/table_spec.rb",
65
- "spec/plsql/type_spec.rb",
66
- "spec/plsql/variable_spec.rb",
67
- "spec/plsql/version_spec.rb",
68
- "spec/plsql/view_spec.rb",
69
- "spec/spec.opts",
70
- "spec/spec_helper.rb",
71
- "spec/support/create_arunit_user.sql",
72
- "spec/support/custom_config.rb.sample",
73
- "spec/support/file_check_script.sh",
74
- "spec/support/test_db.rb",
75
- "spec/support/unlock_and_setup_hr_user.sql"
76
- ]
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
81
-
82
- if s.respond_to? :specification_version then
83
- s.specification_version = 4
84
-
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"])
94
- else
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"])
103
- end
104
- else
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"])
113
- end
114
- end
@@ -1,505 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe "Connection" do
6
-
7
- before(:all) do
8
- @raw_conn = get_connection
9
- @conn = PLSQL::Connection.create(@raw_conn)
10
- end
11
-
12
- after(:all) do
13
- unless defined?(JRuby)
14
- @raw_conn.logoff rescue nil
15
- else
16
- @raw_conn.close rescue nil
17
- end
18
- end
19
-
20
- describe "create and destroy" do
21
- before(:all) do
22
- @raw_conn1 = get_connection
23
- end
24
-
25
- before(:each) do
26
- @conn1 = PLSQL::Connection.create(@raw_conn1)
27
- end
28
-
29
- it "should create connection" do
30
- expect(@conn1.raw_connection).to eq @raw_conn1
31
- end
32
-
33
- unless defined?(JRuby)
34
- it "should be oci connection" do
35
- expect(@conn1).to be_oci
36
- expect(@conn1.raw_driver).to eq :oci
37
- end
38
- else
39
- it "should be jdbc connection" do
40
- expect(@conn1).to be_jdbc
41
- expect(@conn1.raw_driver).to eq :jdbc
42
- end
43
- end
44
-
45
- it "should logoff connection" do
46
- expect(@conn1.logoff).to be true
47
- end
48
-
49
- end
50
-
51
- # Ruby 1.8 and 1.9
52
- unless defined?(JRuby)
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
-
59
- it "should translate PL/SQL VARCHAR2 to Ruby String" do
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]
62
- end
63
-
64
- it "should translate PL/SQL CLOB to Ruby String" do
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]
67
- end
68
-
69
- it "should translate PL/SQL NUMBER to Ruby OraNumber" do
70
- expect(@conn.plsql_to_ruby_data_type(data_type: "NUMBER", data_length: 15)).to eq [OraNumber, nil]
71
- end
72
-
73
- it "should translate PL/SQL DATE to Ruby DateTime" do
74
- expect(@conn.plsql_to_ruby_data_type(data_type: "DATE", data_length: nil)).to eq [DateTime, nil]
75
- end
76
-
77
- it "should translate PL/SQL TIMESTAMP to Ruby Time" do
78
- expect(@conn.plsql_to_ruby_data_type(data_type: "TIMESTAMP", data_length: nil)).to eq [Time, nil]
79
- end
80
-
81
- it "should not translate small Ruby Integer when OraNumber type specified" do
82
- expect(@conn.ruby_value_to_ora_value(100, OraNumber)).to eql(100)
83
- end
84
-
85
- it "should not translate big Ruby Integer when OraNumber type specified" do
86
- ora_number = @conn.ruby_value_to_ora_value(12345678901234567890, OraNumber)
87
- expect(ora_number).to be_an Integer
88
- expect(ora_number.to_s).to eq "12345678901234567890"
89
- # OraNumber has more numeric comparison methods in ruby-oci8 2.0
90
- expect(ora_number).to eq OraNumber.new("12345678901234567890") if OCI8::VERSION >= "2.0.0"
91
- end
92
-
93
- it "should translate Ruby String value to OCI8::CLOB when OCI8::CLOB type specified" do
94
- large_text = "x" * 100_000
95
- ora_value = @conn.ruby_value_to_ora_value(large_text, OCI8::CLOB)
96
- expect(ora_value.class).to eq OCI8::CLOB
97
- expect(ora_value.size).to eq 100_000
98
- ora_value.rewind
99
- expect(ora_value.read).to eq large_text
100
- end
101
-
102
- it "should translate Oracle OraNumber integer value to Integer" do
103
- expect(@conn.ora_value_to_ruby_value(OraNumber.new(100))).to eql(100)
104
- end
105
-
106
- it "should translate Oracle OraNumber float value to BigDecimal" do
107
- expect(@conn.ora_value_to_ruby_value(OraNumber.new(100.11))).to eql(BigDecimal("100.11"))
108
- end
109
-
110
- # ruby-oci8 2.0 returns DATE as Time or DateTime
111
- if OCI8::VERSION < "2.0.0"
112
- it "should translate Oracle OraDate value to Time" do
113
- now = OraDate.now
114
- expect(@conn.ora_value_to_ruby_value(now)).to eql(now.to_time)
115
- end
116
- end
117
-
118
- it "should translate Oracle CLOB value to String" do
119
- large_text = "x" * 100_000
120
- clob = OCI8::CLOB.new(@raw_conn, large_text)
121
- expect(@conn.ora_value_to_ruby_value(clob)).to eq large_text
122
- end
123
-
124
- end
125
-
126
- # JRuby
127
- else
128
-
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
134
- it "should translate PL/SQL VARCHAR2 to Ruby String" do
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]
137
- end
138
-
139
- it "should translate PL/SQL NUMBER to Ruby BigDecimal" do
140
- expect(@conn.plsql_to_ruby_data_type(data_type: "NUMBER", data_length: 15)).to eq [BigDecimal, nil]
141
- end
142
-
143
- it "should translate PL/SQL DATE to Ruby DateTime" do
144
- expect(@conn.plsql_to_ruby_data_type(data_type: "DATE", data_length: nil)).to eq [DateTime, nil]
145
- end
146
-
147
- it "should translate PL/SQL TIMESTAMP to Ruby Time" do
148
- expect(@conn.plsql_to_ruby_data_type(data_type: "TIMESTAMP", data_length: nil)).to eq [Time, nil]
149
- end
150
-
151
- it "should not translate Ruby Integer when BigDecimal type specified" do
152
- expect(@conn.ruby_value_to_ora_value(100, BigDecimal)).to eq java.math.BigDecimal.new(100)
153
- end
154
-
155
- it "should translate Ruby String to string value" do
156
- expect(@conn.ruby_value_to_ora_value(1.1, String)).to eq "1.1"
157
- end
158
-
159
- it "should translate Ruby Integer value to BigDecimal when BigDecimal type specified" do
160
- big_decimal = @conn.ruby_value_to_ora_value(12345678901234567890, BigDecimal)
161
- expect(big_decimal).to eq java.math.BigDecimal.new("12345678901234567890")
162
- end
163
-
164
- it "should translate Ruby String value to Java::OracleSql::CLOB when Java::OracleSql::CLOB type specified" do
165
- large_text = "x" * 100_000
166
- ora_value = @conn.ruby_value_to_ora_value(large_text, Java::OracleSql::CLOB)
167
- expect(ora_value.class).to eq Java::OracleSql::CLOB
168
- expect(ora_value.length).to eq 100_000
169
- expect(ora_value.getSubString(1, ora_value.length)).to eq large_text
170
- ora_value.freeTemporary
171
- end
172
-
173
- it "should translate Ruby nil value to nil when Java::OracleSql::CLOB type specified" do
174
- ora_value = @conn.ruby_value_to_ora_value(nil, Java::OracleSql::CLOB)
175
- expect(ora_value).to be_nil
176
- end
177
-
178
- it "should translate Oracle BigDecimal integer value to Integer" do
179
- expect(@conn.ora_value_to_ruby_value(BigDecimal("100"))).to eql(100)
180
- end
181
-
182
- it "should translate Oracle BigDecimal float value to BigDecimal" do
183
- expect(@conn.ora_value_to_ruby_value(BigDecimal("100.11"))).to eql(BigDecimal("100.11"))
184
- end
185
-
186
- it "should translate Oracle CLOB value to String" do
187
- large_text = "āčē" * 100_000
188
- clob = @conn.ruby_value_to_ora_value(large_text, Java::OracleSql::CLOB)
189
- expect(@conn.ora_value_to_ruby_value(clob)).to eq large_text
190
- clob.freeTemporary
191
- end
192
-
193
- it "should translate empty Oracle CLOB value to nil" do
194
- clob = @conn.ruby_value_to_ora_value(nil, Java::OracleSql::CLOB)
195
- expect(@conn.ora_value_to_ruby_value(clob)).to be_nil
196
- end
197
-
198
- end
199
-
200
- end
201
-
202
- describe "SQL SELECT statements" do
203
-
204
- it "should execute SQL statement and return first result" do
205
- @now = Time.local(2008, 05, 31, 23, 22, 11)
206
- expect(@conn.select_first("SELECT 'abc',123,123.456,
207
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
208
- FROM dual")).to eq ["abc", 123, 123.456, @now]
209
- end
210
-
211
- it "should execute SQL statement and return first result as hash" do
212
- @now = Time.local(2008, 05, 31, 23, 22, 11)
213
- expect(@conn.select_hash_first("SELECT 'abc' a, 123 b, 123.456 c,
214
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}', 'YYYY-MM-DD HH24:MI:SS') d
215
- FROM dual")).to eq(a: "abc", b: 123, c: 123.456, d: @now)
216
- end
217
-
218
- it "should execute SQL statement with bind parameters and return first result" do
219
- @today = Date.parse("2008-05-31")
220
- @now = Time.local(2008, 05, 31, 23, 22, 11)
221
- expect(@conn.select_first("SELECT :1,:2,:3,:4,:5 FROM dual",
222
- "abc", 123, 123.456, @now, @today)).to eq ["abc", 123, 123.456, @now, Time.parse(@today.to_s)]
223
- end
224
-
225
- it "should execute SQL statement with NULL values and return first result" do
226
- @now = Time.local(2008, 05, 31, 23, 22, 11)
227
- expect(@conn.select_first("SELECT NULL,123,123.456,
228
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
229
- FROM dual")).to eq [nil, 123, 123.456, @now]
230
- end
231
-
232
- if defined?(JRuby)
233
-
234
- it "should execute SQL statement with NULL values as bind parameters and return first result" do
235
- @today = Date.parse("2008-05-31")
236
- @now = Time.local(2008, 05, 31, 23, 22, 11)
237
- expect(@conn.select_first("SELECT :1,:2,:3,:4,:5 FROM dual",
238
- nil, 123, 123.456, @now, @today)).to eq [nil, 123, 123.456, @now, Time.parse(@today.to_s)]
239
- end
240
-
241
- end
242
-
243
- it "should execute SQL statement and return all results" do
244
- @now = Time.local(2008, 05, 31, 23, 22, 11)
245
- expect(@conn.select_all("SELECT 'abc',123,123.456,
246
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
247
- FROM dual
248
- UNION ALL SELECT 'abc',123,123.456,
249
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
250
- FROM dual")).to eq [["abc", 123, 123.456, @now], ["abc", 123, 123.456, @now]]
251
- end
252
-
253
- it "should execute SQL statement and return all results as hash" do
254
- @now = Time.local(2008, 05, 31, 23, 22, 11)
255
- expect(@conn.select_hash_all("SELECT 'abc' a, 123 b, 123.456 c,
256
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS') d
257
- FROM dual
258
- UNION ALL SELECT 'def' a, 123 b, 123.456 c,
259
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS') d
260
- FROM dual")).to eq [{ a: "abc", b: 123, c: 123.456, d: @now }, { a: "def", b: 123, c: 123.456, d: @now }]
261
- end
262
-
263
- it "should execute SQL statement with bind parameters and return all results" do
264
- @now = Time.local(2008, 05, 31, 23, 22, 11)
265
- expect(@conn.select_all("SELECT :1,:2,:3,:4 FROM dual UNION ALL SELECT :1,:2,:3,:4 FROM dual",
266
- "abc", 123, 123.456, @now, "abc", 123, 123.456, @now)).to eq [["abc", 123, 123.456, @now], ["abc", 123, 123.456, @now]]
267
- end
268
-
269
- it "should execute SQL statement and yield all results in block" do
270
- @now = Time.local(2008, 05, 31, 23, 22, 11)
271
- expect(@conn.select_all("SELECT 'abc',123,123.456,
272
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
273
- FROM dual
274
- UNION ALL SELECT 'abc',123,123.456,
275
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
276
- FROM dual") do |r|
277
- expect(r).to eq ["abc", 123, 123.456, @now]
278
- end).to eq 2
279
- end
280
-
281
- it "should execute SQL statement with bind parameters and yield all results in block" do
282
- @now = Time.local(2008, 05, 31, 23, 22, 11)
283
- expect(@conn.select_all("SELECT :1,:2,:3,:4 FROM dual UNION ALL SELECT :1,:2,:3,:4 FROM dual",
284
- "abc", 123, 123.456, @now, "abc", 123, 123.456, @now) do |r|
285
- expect(r).to eq ["abc", 123, 123.456, @now]
286
- end).to eq 2
287
- end
288
-
289
- end
290
-
291
- describe "PL/SQL procedures" do
292
- before(:all) do
293
- @random = rand(1000)
294
- @now = Time.local(2008, 05, 31, 23, 22, 11)
295
- sql = <<-SQL
296
- CREATE OR REPLACE FUNCTION test_add_random (p_number NUMBER, p_varchar IN OUT VARCHAR2, p_date IN OUT DATE)
297
- RETURN NUMBER
298
- IS
299
- BEGIN
300
- RETURN p_number + #{@random};
301
- END test_add_random;
302
- SQL
303
- expect(@conn.exec(sql)).to be true
304
- end
305
-
306
- after(:all) do
307
- @conn.exec "DROP FUNCTION test_add_random"
308
- end
309
-
310
- it "should parse PL/SQL procedure call and bind parameters and exec and get bind parameter value" do
311
- sql = <<-SQL
312
- BEGIN
313
- :result := test_add_random (:p_number, :p_varchar, :p_date);
314
- END;
315
- SQL
316
- cursor = @conn.parse(sql)
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")
321
- cursor.exec
322
- expect(cursor[":result"]).to eq @random + 100
323
- expect(cursor[":p_varchar"]).to eq "abc"
324
- expect(cursor[":p_date"]).to eq @now
325
- expect(cursor.close).to be_nil
326
- end
327
-
328
- end
329
-
330
- describe "commit and rollback" do
331
- before(:all) do
332
- expect(@conn.exec("CREATE TABLE test_commit (dummy VARCHAR2(100))")).to be true
333
- @conn.autocommit = false
334
- expect(@conn).not_to be_autocommit
335
- end
336
-
337
- after(:all) do
338
- @conn.exec "DROP TABLE test_commit"
339
- end
340
-
341
- after(:each) do
342
- @conn.exec "DELETE FROM test_commit"
343
- @conn.commit
344
- end
345
-
346
- it "should do commit" do
347
- @conn.exec("INSERT INTO test_commit VALUES ('test')")
348
- @conn.commit
349
- expect(@conn.select_first("SELECT COUNT(*) FROM test_commit")[0]).to eq 1
350
- end
351
-
352
- it "should do rollback" do
353
- @conn.exec("INSERT INTO test_commit VALUES ('test')")
354
- @conn.rollback
355
- expect(@conn.select_first("SELECT COUNT(*) FROM test_commit")[0]).to eq 0
356
- end
357
-
358
- it "should do commit and rollback should not undo commited transaction" do
359
- @conn.exec("INSERT INTO test_commit VALUES ('test')")
360
- @conn.commit
361
- @conn.rollback
362
- expect(@conn.select_first("SELECT COUNT(*) FROM test_commit")[0]).to eq 1
363
- end
364
-
365
- end
366
-
367
- describe "prefetch rows" do
368
- after(:each) do
369
- @conn.prefetch_rows = 1 # set back to default
370
- end
371
-
372
- it "should set prefetch rows for connection" do
373
- sql = "SELECT 1 FROM dual UNION ALL SELECT 1/0 FROM dual"
374
- @conn.prefetch_rows = 2
375
- expect {
376
- @conn.cursor_from_query(sql)
377
- }.to raise_error(/divisor is equal to zero/)
378
- @conn.prefetch_rows = 1
379
- expect {
380
- @conn.cursor_from_query(sql)
381
- }.not_to raise_error
382
- end
383
-
384
- it "should fetch just one row when using select_first" do
385
- sql = "SELECT 1 FROM dual UNION ALL SELECT 1/0 FROM dual"
386
- @conn.prefetch_rows = 2
387
- expect {
388
- @conn.select_first(sql)
389
- }.not_to raise_error
390
- end
391
-
392
- end
393
-
394
- describe "describe synonym" do
395
- before(:all) do
396
- @conn.exec "CREATE SYNONYM hr.synonym_for_dual FOR sys.dual"
397
- end
398
-
399
- after(:all) do
400
- @conn.exec "DROP SYNONYM hr.synonym_for_dual"
401
- end
402
-
403
- it "should describe local synonym" do
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"]
407
- end
408
-
409
- it "should return nil on non-existing synonym" do
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
413
- end
414
-
415
- it "should describe public synonym" do
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"]
419
- end
420
-
421
- end
422
-
423
- describe "session information" do
424
- it "should get database version" do
425
- # using Oracle version 10.2.0.4 for unit tests
426
- expect(@conn.database_version).to eq DATABASE_VERSION.split(".").map { |n| n.to_i }
427
- end
428
-
429
- it "should get session ID" do
430
- expect(@conn.session_id).to eq @conn.select_first("SELECT USERENV('SESSIONID') FROM dual")[0].to_i
431
- end
432
- end
433
-
434
- describe "drop ruby temporary tables" do
435
- after(:all) do
436
- @conn.drop_all_ruby_temporary_tables
437
- end
438
-
439
- it "should drop all ruby temporary tables" do
440
- tmp_table = "ruby_111_222_333"
441
- @conn.exec "CREATE GLOBAL TEMPORARY TABLE #{tmp_table} (dummy CHAR(1))"
442
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.not_to raise_error
443
- @conn.drop_all_ruby_temporary_tables
444
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.to raise_error(/table or view does not exist/)
445
- end
446
-
447
- it "should drop current session ruby temporary tables" do
448
- tmp_table = "ruby_#{@conn.session_id}_222_333"
449
- @conn.exec "CREATE GLOBAL TEMPORARY TABLE #{tmp_table} (dummy CHAR(1))"
450
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.not_to raise_error
451
- @conn.drop_session_ruby_temporary_tables
452
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.to raise_error(/table or view does not exist/)
453
- end
454
-
455
- it "should not drop other session ruby temporary tables" do
456
- tmp_table = "ruby_#{@conn.session_id + 1}_222_333"
457
- @conn.exec "CREATE GLOBAL TEMPORARY TABLE #{tmp_table} (dummy CHAR(1))"
458
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.not_to raise_error
459
- @conn.drop_session_ruby_temporary_tables
460
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.not_to raise_error
461
- end
462
-
463
- end
464
-
465
- describe "logoff" do
466
- before(:each) do
467
- # restore connection before each test
468
- reconnect_connection
469
- end
470
-
471
- after(:all) do
472
- @conn.exec "DROP TABLE test_dummy_table" rescue nil
473
- end
474
-
475
- def reconnect_connection
476
- @raw_conn = get_connection
477
- @conn = PLSQL::Connection.create(@raw_conn)
478
- end
479
-
480
- it "should drop current session ruby temporary tables" do
481
- tmp_table = "ruby_#{@conn.session_id}_222_333"
482
- @conn.exec "CREATE GLOBAL TEMPORARY TABLE #{tmp_table} (dummy CHAR(1))"
483
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.not_to raise_error
484
- @conn.logoff
485
- reconnect_connection
486
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.to raise_error(/table or view does not exist/)
487
- end
488
-
489
- it "should rollback any uncommited transactions" do
490
- tmp_table = "ruby_#{@conn.session_id}_222_333"
491
- old_autocommit = @conn.autocommit?
492
- @conn.autocommit = false
493
- @conn.exec "CREATE GLOBAL TEMPORARY TABLE #{tmp_table} (dummy CHAR(1))"
494
- @conn.exec "CREATE TABLE test_dummy_table (dummy CHAR(1))"
495
- @conn.exec "INSERT INTO test_dummy_table VALUES ('1')"
496
- # logoff will drop ruby temporary tables, it should do rollback before drop table
497
- @conn.logoff
498
- reconnect_connection
499
- expect(@conn.select_first("SELECT * FROM test_dummy_table")).to eq nil
500
- @conn.autocommit = old_autocommit
501
- end
502
-
503
- end
504
-
505
- end