ruby-plsql 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +30 -0
- data/.github/stale.yml +37 -0
- data/.rubocop.yml +153 -0
- data/.travis.yml +20 -6
- data/.travis/oracle/download.sh +9 -10
- data/.travis/oracle/install.sh +6 -6
- data/Gemfile +13 -9
- data/History.txt +26 -0
- data/README.md +9 -5
- data/Rakefile +31 -26
- data/VERSION +1 -1
- data/Vagrantfile +2 -2
- 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/lib/plsql/connection.rb +16 -18
- data/lib/plsql/helpers.rb +1 -3
- data/lib/plsql/jdbc_connection.rb +66 -61
- data/lib/plsql/oci8_patches.rb +2 -2
- data/lib/plsql/oci_connection.rb +51 -69
- data/lib/plsql/package.rb +5 -8
- data/lib/plsql/procedure.rb +75 -78
- data/lib/plsql/procedure_call.rb +498 -501
- data/lib/plsql/schema.rb +95 -100
- data/lib/plsql/sequence.rb +10 -13
- data/lib/plsql/sql_statements.rb +9 -11
- data/lib/plsql/table.rb +59 -63
- data/lib/plsql/type.rb +71 -76
- data/lib/plsql/variable.rb +89 -94
- data/lib/plsql/version.rb +1 -1
- data/lib/plsql/view.rb +16 -19
- data/ruby-plsql.gemspec +41 -37
- data/spec/plsql/connection_spec.rb +67 -67
- data/spec/plsql/package_spec.rb +15 -15
- data/spec/plsql/procedure_spec.rb +286 -233
- data/spec/plsql/schema_spec.rb +22 -23
- data/spec/plsql/sequence_spec.rb +2 -2
- data/spec/plsql/sql_statements_spec.rb +5 -5
- data/spec/plsql/table_spec.rb +77 -77
- data/spec/plsql/type_spec.rb +23 -29
- data/spec/plsql/variable_spec.rb +59 -59
- data/spec/plsql/version_spec.rb +4 -4
- data/spec/plsql/view_spec.rb +42 -42
- data/spec/spec_helper.rb +37 -29
- data/spec/support/test_db.rb +12 -13
- metadata +44 -26
- data/.travis/oracle/LICENSE +0 -5
- data/.travis/oracle/README.md +0 -64
- data/.travis/oracle/download.js +0 -100
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe "Parameter type mapping /" do
|
6
6
|
|
@@ -17,12 +17,12 @@ describe "Parameter type mapping /" do
|
|
17
17
|
END test_uppercase;
|
18
18
|
SQL
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
after(:all) do
|
22
22
|
plsql.execute "DROP FUNCTION test_uppercase"
|
23
23
|
plsql.logoff
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should find existing procedure" do
|
27
27
|
expect(PLSQL::Procedure.find(plsql, :test_uppercase)).not_to be_nil
|
28
28
|
end
|
@@ -32,23 +32,23 @@ describe "Parameter type mapping /" do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should execute function and return correct value" do
|
35
|
-
expect(plsql.test_uppercase(
|
35
|
+
expect(plsql.test_uppercase("xxx")).to eq("XXX")
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should execute function with named parameters and return correct value" do
|
39
|
-
expect(plsql.test_uppercase(:
|
39
|
+
expect(plsql.test_uppercase(p_string: "xxx")).to eq("XXX")
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should raise error if wrong number of arguments is passed" do
|
43
|
-
expect { plsql.test_uppercase(
|
43
|
+
expect { plsql.test_uppercase("xxx", "yyy") }.to raise_error(ArgumentError)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should raise error if wrong named argument is passed" do
|
47
|
-
expect { plsql.test_uppercase(:
|
47
|
+
expect { plsql.test_uppercase(p_string2: "xxx") }.to raise_error(ArgumentError)
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
it "should execute function with schema name specified" do
|
51
|
-
expect(plsql.hr.test_uppercase(
|
51
|
+
expect(plsql.hr.test_uppercase("xxx")).to eq("XXX")
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should process nil parameter as NULL" do
|
@@ -57,7 +57,7 @@ describe "Parameter type mapping /" do
|
|
57
57
|
|
58
58
|
end
|
59
59
|
|
60
|
-
[
|
60
|
+
["VARCHAR", "VARCHAR2"].each do |datatype|
|
61
61
|
describe "Function with #{datatype} parameters" do
|
62
62
|
it_should_behave_like "Function with string parameters", datatype
|
63
63
|
end
|
@@ -76,12 +76,12 @@ describe "Parameter type mapping /" do
|
|
76
76
|
END test_sum;
|
77
77
|
SQL
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
after(:all) do
|
81
81
|
plsql.execute "DROP FUNCTION test_sum"
|
82
82
|
plsql.logoff
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
it "should get #{ora_data_type} variable type mapped to #{class_.to_s}" do
|
86
86
|
expect(plsql.test_sum(num1, num2)).to be_a class_
|
87
87
|
end
|
@@ -95,18 +95,18 @@ describe "Parameter type mapping /" do
|
|
95
95
|
|
96
96
|
end
|
97
97
|
|
98
|
-
@big_number = (
|
98
|
+
@big_number = ("1234567890" * 3).to_i
|
99
99
|
[
|
100
|
-
{:
|
101
|
-
{:
|
102
|
-
{:
|
103
|
-
{:
|
104
|
-
{:
|
105
|
-
{:
|
106
|
-
{:
|
107
|
-
{:
|
108
|
-
{:
|
109
|
-
{:
|
100
|
+
{ ora_data_type: "INTEGER", class: Integer, num1: @big_number, num2: @big_number, expected: @big_number * 2 },
|
101
|
+
{ ora_data_type: "NUMBER", class: BigDecimal, num1: 12345.12345, num2: 12345.12345, expected: 24690.2469 },
|
102
|
+
{ ora_data_type: "PLS_INTEGER", class: Integer, num1: 123456789, num2: 123456789, expected: 246913578 },
|
103
|
+
{ ora_data_type: "BINARY_INTEGER", class: Integer, num1: 123456789, num2: 123456789, expected: 246913578 },
|
104
|
+
{ ora_data_type: "SIMPLE_INTEGER", class: Integer, num1: 123456789, num2: 123456789, expected: 246913578, mandatory: true },
|
105
|
+
{ ora_data_type: "NATURAL", class: Integer, num1: 123456789, num2: 123456789, expected: 246913578 },
|
106
|
+
{ ora_data_type: "NATURALN", class: Integer, num1: 123456789, num2: 123456789, expected: 246913578, mandatory: true },
|
107
|
+
{ ora_data_type: "POSITIVE", class: Integer, num1: 123456789, num2: 123456789, expected: 246913578 },
|
108
|
+
{ ora_data_type: "POSITIVEN", class: Integer, num1: 123456789, num2: 123456789, expected: 246913578, mandatory: true },
|
109
|
+
{ ora_data_type: "SIGNTYPE", class: Integer, num1: 1, num2: -1, expected: 0 },
|
110
110
|
].each do |row|
|
111
111
|
ora_data_type, class_, num1, num2, expected, mandatory = row.values
|
112
112
|
describe ora_data_type do
|
@@ -140,7 +140,7 @@ describe "Parameter type mapping /" do
|
|
140
140
|
end
|
141
141
|
|
142
142
|
describe "Function with date parameters" do
|
143
|
-
|
143
|
+
|
144
144
|
before(:all) do
|
145
145
|
plsql.connect! CONNECTION_PARAMS
|
146
146
|
plsql.execute <<-SQL
|
@@ -153,7 +153,7 @@ describe "Parameter type mapping /" do
|
|
153
153
|
END test_date;
|
154
154
|
SQL
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
before(:each) do
|
158
158
|
plsql.default_timezone = :local
|
159
159
|
end
|
@@ -162,46 +162,46 @@ describe "Parameter type mapping /" do
|
|
162
162
|
plsql.execute "DROP FUNCTION test_date"
|
163
163
|
plsql.logoff
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
it "should process Time parameters" do
|
167
|
-
now = Time.local(2008,8,12,14,28,0)
|
168
|
-
expect(plsql.test_date(now)).to eq(now + 60*60*24)
|
167
|
+
now = Time.local(2008, 8, 12, 14, 28, 0)
|
168
|
+
expect(plsql.test_date(now)).to eq(now + 60 * 60 * 24)
|
169
169
|
end
|
170
170
|
|
171
171
|
it "should process UTC Time parameters" do
|
172
172
|
plsql.default_timezone = :utc
|
173
|
-
now = Time.utc(2008,8,12,14,28,0)
|
174
|
-
expect(plsql.test_date(now)).to eq(now + 60*60*24)
|
173
|
+
now = Time.utc(2008, 8, 12, 14, 28, 0)
|
174
|
+
expect(plsql.test_date(now)).to eq(now + 60 * 60 * 24)
|
175
175
|
end
|
176
176
|
|
177
177
|
it "should process DateTime parameters" do
|
178
|
-
now = DateTime.parse(Time.local(2008,8,12,14,28,0).iso8601)
|
178
|
+
now = DateTime.parse(Time.local(2008, 8, 12, 14, 28, 0).iso8601)
|
179
179
|
result = plsql.test_date(now)
|
180
180
|
expect(result.class).to eq(Time)
|
181
181
|
expect(result).to eq(Time.parse((now + 1).strftime("%c")))
|
182
182
|
end
|
183
|
-
|
183
|
+
|
184
184
|
it "should process old DateTime parameters" do
|
185
|
-
now = DateTime.civil(1901,1,1,12,0,0,plsql.local_timezone_offset)
|
185
|
+
now = DateTime.civil(1901, 1, 1, 12, 0, 0, plsql.local_timezone_offset)
|
186
186
|
result = plsql.test_date(now)
|
187
187
|
expect(result.class).to eq(Time)
|
188
188
|
expect(result).to eq(Time.parse((now + 1).strftime("%c")))
|
189
189
|
end
|
190
190
|
|
191
191
|
it "should process Date parameters" do
|
192
|
-
now = Date.new(2008,8,12)
|
192
|
+
now = Date.new(2008, 8, 12)
|
193
193
|
result = plsql.test_date(now)
|
194
194
|
expect(result.class).to eq(Time)
|
195
195
|
expect(result).to eq(Time.parse((now + 1).strftime("%c")))
|
196
196
|
end
|
197
|
-
|
197
|
+
|
198
198
|
it "should process old Date parameters" do
|
199
|
-
now = Date.new(1901,1,1)
|
199
|
+
now = Date.new(1901, 1, 1)
|
200
200
|
result = plsql.test_date(now)
|
201
201
|
expect(result.class).to eq(Time)
|
202
202
|
expect(result).to eq(Time.parse((now + 1).strftime("%c")))
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
it "should process nil date parameter as NULL" do
|
206
206
|
expect(plsql.test_date(nil)).to be_nil
|
207
207
|
end
|
@@ -221,16 +221,16 @@ describe "Parameter type mapping /" do
|
|
221
221
|
END test_timestamp;
|
222
222
|
SQL
|
223
223
|
end
|
224
|
-
|
224
|
+
|
225
225
|
after(:all) do
|
226
226
|
plsql.execute "DROP FUNCTION test_timestamp"
|
227
227
|
plsql.logoff
|
228
228
|
end
|
229
|
-
|
229
|
+
|
230
230
|
it "should process timestamp parameters" do
|
231
231
|
# now = Time.now
|
232
|
-
now = Time.local(2008,8,12,14,28,0)
|
233
|
-
expect(plsql.test_timestamp(now)).to eq(now + 60*60*24)
|
232
|
+
now = Time.local(2008, 8, 12, 14, 28, 0)
|
233
|
+
expect(plsql.test_timestamp(now)).to eq(now + 60 * 60 * 24)
|
234
234
|
end
|
235
235
|
|
236
236
|
end
|
@@ -238,6 +238,9 @@ describe "Parameter type mapping /" do
|
|
238
238
|
describe "Function or procedure with XMLType parameters" do
|
239
239
|
before(:all) do
|
240
240
|
plsql.connect! CONNECTION_PARAMS
|
241
|
+
@oracle12c_or_higher = !! plsql.connection.select_all(
|
242
|
+
"select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) >= 12")
|
243
|
+
skip "Skip until furtuer investigation for #114" if @oracle12c_or_higher
|
241
244
|
plsql.execute <<-SQL
|
242
245
|
CREATE OR REPLACE FUNCTION test_xmltype
|
243
246
|
( p_xml XMLTYPE )
|
@@ -258,15 +261,15 @@ describe "Parameter type mapping /" do
|
|
258
261
|
end
|
259
262
|
|
260
263
|
after(:all) do
|
261
|
-
plsql.execute "DROP FUNCTION test_xmltype"
|
262
|
-
plsql.execute "DROP PROCEDURE test_xmltype2"
|
264
|
+
plsql.execute "DROP FUNCTION test_xmltype" unless @oracle12c_or_higher
|
265
|
+
plsql.execute "DROP PROCEDURE test_xmltype2" unless @oracle12c_or_higher
|
263
266
|
plsql.logoff
|
264
267
|
end
|
265
268
|
|
266
269
|
it "should process XMLType parameters" do
|
267
|
-
xml =
|
270
|
+
xml = "<DUMMY>value</DUMMY>"
|
268
271
|
result = plsql.test_xmltype(xml)
|
269
|
-
expect(result).to eq(
|
272
|
+
expect(result).to eq("<DUMMY>value</DUMMY>")
|
270
273
|
end
|
271
274
|
|
272
275
|
it "should work when passing a NULL value" do
|
@@ -275,13 +278,12 @@ describe "Parameter type mapping /" do
|
|
275
278
|
end
|
276
279
|
|
277
280
|
it "should assign input parameter to putput parameter" do
|
278
|
-
xml =
|
281
|
+
xml = "<DUMMY>value</DUMMY>"
|
279
282
|
result = plsql.test_xmltype2(xml)
|
280
|
-
expect(result[:po_xml]).to eq(
|
283
|
+
expect(result[:po_xml]).to eq("<DUMMY>value</DUMMY>")
|
281
284
|
end
|
282
285
|
end
|
283
286
|
|
284
|
-
|
285
287
|
describe "Procedure with output parameters" do
|
286
288
|
before(:all) do
|
287
289
|
plsql.connect! CONNECTION_PARAMS
|
@@ -295,26 +297,26 @@ describe "Parameter type mapping /" do
|
|
295
297
|
END test_copy;
|
296
298
|
SQL
|
297
299
|
end
|
298
|
-
|
300
|
+
|
299
301
|
after(:all) do
|
300
302
|
plsql.execute "DROP PROCEDURE test_copy"
|
301
303
|
plsql.logoff
|
302
304
|
end
|
303
|
-
|
305
|
+
|
304
306
|
it "should return hash with output parameters" do
|
305
|
-
expect(plsql.test_copy("abc", nil, nil)).to eq(
|
307
|
+
expect(plsql.test_copy("abc", nil, nil)).to eq(p_to: "abc", p_to_double: "abcabc")
|
306
308
|
end
|
307
309
|
|
308
310
|
it "should return hash with output parameters when called with named parameters" do
|
309
|
-
expect(plsql.test_copy(:
|
311
|
+
expect(plsql.test_copy(p_from: "abc", p_to: nil, p_to_double: nil)).to eq(p_to: "abc", p_to_double: "abcabc")
|
310
312
|
end
|
311
313
|
|
312
314
|
it "should substitute output parameters with nil if they are not specified" do
|
313
|
-
expect(plsql.test_copy("abc")).to eq(
|
315
|
+
expect(plsql.test_copy("abc")).to eq(p_to: "abc", p_to_double: "abcabc")
|
314
316
|
end
|
315
317
|
|
316
318
|
it "should substitute named output parameters with nil if they are not specified" do
|
317
|
-
expect(plsql.test_copy(:
|
319
|
+
expect(plsql.test_copy(p_from: "abc")).to eq(p_to: "abc", p_to_double: "abcabc")
|
318
320
|
end
|
319
321
|
|
320
322
|
end
|
@@ -378,12 +380,12 @@ describe "Parameter type mapping /" do
|
|
378
380
|
SQL
|
379
381
|
|
380
382
|
end
|
381
|
-
|
383
|
+
|
382
384
|
after(:all) do
|
383
385
|
plsql.execute "DROP PACKAGE test_package2"
|
384
386
|
plsql.logoff
|
385
387
|
end
|
386
|
-
|
388
|
+
|
387
389
|
it "should find existing package" do
|
388
390
|
expect(PLSQL::Package.find(plsql, :test_package2)).not_to be_nil
|
389
391
|
end
|
@@ -401,30 +403,30 @@ describe "Parameter type mapping /" do
|
|
401
403
|
end
|
402
404
|
|
403
405
|
it "should execute correct procedures based on number of arguments and return correct value" do
|
404
|
-
expect(plsql.test_package2.test_procedure(
|
405
|
-
expect(plsql.test_package2.test_procedure(
|
406
|
+
expect(plsql.test_package2.test_procedure("xxx")).to eq("XXX")
|
407
|
+
expect(plsql.test_package2.test_procedure("xxx", nil)).to eq(p_result: "XXX")
|
406
408
|
end
|
407
409
|
|
408
410
|
it "should execute correct procedures based on number of named arguments and return correct value" do
|
409
|
-
expect(plsql.test_package2.test_procedure(:
|
410
|
-
expect(plsql.test_package2.test_procedure(:
|
411
|
+
expect(plsql.test_package2.test_procedure(p_string: "xxx")).to eq("XXX")
|
412
|
+
expect(plsql.test_package2.test_procedure(p_string: "xxx", p_result: nil)).to eq(p_result: "XXX")
|
411
413
|
end
|
412
414
|
|
413
415
|
it "should raise exception if procedure cannot be found based on number of arguments" do
|
414
416
|
expect { plsql.test_package2.test_procedure() }.to raise_error(/wrong number or types of arguments/i)
|
415
417
|
end
|
416
|
-
|
418
|
+
|
417
419
|
it "should find procedure based on types of arguments" do
|
418
|
-
expect(plsql.test_package2.test_procedure(111, nil)).to eq(
|
420
|
+
expect(plsql.test_package2.test_procedure(111, nil)).to eq(p_result: "111")
|
419
421
|
end
|
420
422
|
|
421
423
|
it "should find procedure based on names of named arguments" do
|
422
|
-
expect(plsql.test_package2.test_procedure(:
|
424
|
+
expect(plsql.test_package2.test_procedure(p_number: 111, p_result: nil)).to eq(p_result: "111")
|
423
425
|
end
|
424
426
|
|
425
427
|
it "should find matching procedure based on partial list of named arguments" do
|
426
|
-
expect(plsql.test_package2.test_function(:
|
427
|
-
expect(plsql.test_package2.test_function(:
|
428
|
+
expect(plsql.test_package2.test_function(p_string: "xxx")).to eq("xxx ")
|
429
|
+
expect(plsql.test_package2.test_function(p_number: 1)).to eq(2)
|
428
430
|
end
|
429
431
|
|
430
432
|
end
|
@@ -444,24 +446,24 @@ describe "Parameter type mapping /" do
|
|
444
446
|
END test_copy_function;
|
445
447
|
SQL
|
446
448
|
end
|
447
|
-
|
449
|
+
|
448
450
|
after(:all) do
|
449
451
|
plsql.execute "DROP FUNCTION test_copy_function"
|
450
452
|
plsql.logoff
|
451
453
|
end
|
452
|
-
|
454
|
+
|
453
455
|
it "should return array with return value and hash of output parameters" do
|
454
|
-
expect(plsql.test_copy_function("abc", nil, nil)).to eq([3, { :
|
456
|
+
expect(plsql.test_copy_function("abc", nil, nil)).to eq([3, { p_to: "abc", p_to_double: "abcabc" }])
|
455
457
|
end
|
456
458
|
|
457
459
|
it "should return array with return value and hash of output parameters when called with named parameters" do
|
458
|
-
expect(plsql.test_copy_function(:
|
459
|
-
[3, { :
|
460
|
+
expect(plsql.test_copy_function(p_from: "abc", p_to: nil, p_to_double: nil)).to eq(
|
461
|
+
[3, { p_to: "abc", p_to_double: "abcabc" }]
|
460
462
|
)
|
461
463
|
end
|
462
464
|
|
463
465
|
it "should substitute output parameters with nil if they are not specified" do
|
464
|
-
expect(plsql.test_copy_function("abc")).to eq([3, { :
|
466
|
+
expect(plsql.test_copy_function("abc")).to eq([3, { p_to: "abc", p_to_double: "abcabc" }])
|
465
467
|
end
|
466
468
|
|
467
469
|
end
|
@@ -485,7 +487,7 @@ describe "Parameter type mapping /" do
|
|
485
487
|
END test_proc_no_params;
|
486
488
|
SQL
|
487
489
|
end
|
488
|
-
|
490
|
+
|
489
491
|
after(:all) do
|
490
492
|
plsql.execute "DROP FUNCTION test_no_params"
|
491
493
|
plsql.execute "DROP PROCEDURE test_proc_no_params"
|
@@ -531,7 +533,7 @@ describe "Parameter type mapping /" do
|
|
531
533
|
CURSOR clob_cur IS
|
532
534
|
SELECT clob_col
|
533
535
|
FROM test_clob_table;
|
534
|
-
|
536
|
+
|
535
537
|
v_dummy CLOB;
|
536
538
|
BEGIN
|
537
539
|
DELETE FROM test_clob_table;
|
@@ -540,47 +542,47 @@ describe "Parameter type mapping /" do
|
|
540
542
|
OPEN clob_cur;
|
541
543
|
FETCH clob_cur INTO v_dummy;
|
542
544
|
CLOSE clob_cur;
|
543
|
-
|
545
|
+
|
544
546
|
RETURN v_dummy;
|
545
547
|
END test_clob_insert;
|
546
548
|
SQL
|
547
549
|
end
|
548
|
-
|
550
|
+
|
549
551
|
after(:all) do
|
550
552
|
plsql.execute "DROP FUNCTION test_clob"
|
551
553
|
plsql.execute "DROP FUNCTION test_clob_insert"
|
552
554
|
plsql.execute "DROP TABLE test_clob_table"
|
553
555
|
plsql.logoff
|
554
556
|
end
|
555
|
-
|
557
|
+
|
556
558
|
it "should find existing procedure" do
|
557
559
|
expect(PLSQL::Procedure.find(plsql, :test_clob)).not_to be_nil
|
558
560
|
end
|
559
561
|
|
560
562
|
it "should execute function and return correct value" do
|
561
|
-
large_text =
|
563
|
+
large_text = "ābčdēfghij" * 10_000
|
562
564
|
expect(plsql.test_clob(large_text)).to eq(large_text)
|
563
565
|
end
|
564
566
|
|
565
567
|
unless defined?(JRUBY_VERSION)
|
566
568
|
|
567
569
|
it "should execute function with empty string and return nil (oci8 cannot pass empty CLOB parameter)" do
|
568
|
-
text =
|
570
|
+
text = ""
|
569
571
|
expect(plsql.test_clob(text)).to be_nil
|
570
572
|
end
|
571
573
|
|
572
574
|
it "should execute function which inserts the CLOB parameter into a table with empty string and return nil" do
|
573
|
-
text =
|
575
|
+
text = ""
|
574
576
|
expect(plsql.test_clob_insert(text)).to be_nil
|
575
577
|
end
|
576
|
-
|
578
|
+
|
577
579
|
else
|
578
580
|
|
579
581
|
it "should execute function with empty string and return empty string" do
|
580
|
-
text =
|
582
|
+
text = ""
|
581
583
|
expect(plsql.test_clob(text)).to eq(text)
|
582
584
|
end
|
583
|
-
|
585
|
+
|
584
586
|
end
|
585
587
|
|
586
588
|
it "should execute function with nil and return nil" do
|
@@ -590,7 +592,7 @@ describe "Parameter type mapping /" do
|
|
590
592
|
it "should execute function which inserts the CLOB parameter into a table with nil and return nil" do
|
591
593
|
expect(plsql.test_clob_insert(nil)).to be_nil
|
592
594
|
end
|
593
|
-
|
595
|
+
|
594
596
|
end
|
595
597
|
|
596
598
|
describe "Procedrue with CLOB parameter and return value" do
|
@@ -606,18 +608,18 @@ describe "Parameter type mapping /" do
|
|
606
608
|
END test_clob_proc;
|
607
609
|
SQL
|
608
610
|
end
|
609
|
-
|
611
|
+
|
610
612
|
after(:all) do
|
611
613
|
plsql.execute "DROP PROCEDURE test_clob_proc"
|
612
614
|
plsql.logoff
|
613
615
|
end
|
614
|
-
|
616
|
+
|
615
617
|
it "should find existing procedure" do
|
616
618
|
expect(PLSQL::Procedure.find(plsql, :test_clob_proc)).not_to be_nil
|
617
619
|
end
|
618
620
|
|
619
621
|
it "should execute function and return correct value" do
|
620
|
-
large_text =
|
622
|
+
large_text = "ābčdēfghij" * 10_000
|
621
623
|
expect(plsql.test_clob_proc(large_text)[:p_return]).to eq(large_text)
|
622
624
|
end
|
623
625
|
end
|
@@ -635,12 +637,12 @@ describe "Parameter type mapping /" do
|
|
635
637
|
END test_blob_proc;
|
636
638
|
SQL
|
637
639
|
end
|
638
|
-
|
640
|
+
|
639
641
|
after(:all) do
|
640
642
|
plsql.execute "DROP PROCEDURE test_blob_proc"
|
641
643
|
plsql.logoff
|
642
644
|
end
|
643
|
-
|
645
|
+
|
644
646
|
it "should find existing procedure" do
|
645
647
|
expect(PLSQL::Procedure.find(plsql, :test_blob_proc)).not_to be_nil
|
646
648
|
end
|
@@ -716,7 +718,7 @@ describe "Parameter type mapping /" do
|
|
716
718
|
IS
|
717
719
|
CURSOR employees_cur
|
718
720
|
IS
|
719
|
-
SELECT
|
721
|
+
SELECT
|
720
722
|
null employee_id,
|
721
723
|
null first_name,
|
722
724
|
null last_name,
|
@@ -776,16 +778,16 @@ describe "Parameter type mapping /" do
|
|
776
778
|
END test_employee_record2;
|
777
779
|
SQL
|
778
780
|
@p_employee = {
|
779
|
-
:
|
780
|
-
:
|
781
|
-
:
|
782
|
-
:
|
781
|
+
employee_id: 1,
|
782
|
+
first_name: "First",
|
783
|
+
last_name: "Last",
|
784
|
+
hire_date: Time.local(2000, 01, 31)
|
783
785
|
}
|
784
786
|
@p_employee2 = {
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
787
|
+
"employee_id" => 1,
|
788
|
+
"FIRST_NAME" => "Second",
|
789
|
+
"last_name" => "Last",
|
790
|
+
"hire_date" => Time.local(2000, 01, 31)
|
789
791
|
}
|
790
792
|
end
|
791
793
|
|
@@ -803,23 +805,23 @@ describe "Parameter type mapping /" do
|
|
803
805
|
end
|
804
806
|
|
805
807
|
it "should execute function with named parameter and return correct value" do
|
806
|
-
expect(plsql.test_full_name(:
|
808
|
+
expect(plsql.test_full_name(p_employee: @p_employee)).to eq("First Last")
|
807
809
|
end
|
808
810
|
|
809
811
|
it "should execute function with sequential parameter and return correct value" do
|
810
|
-
expect(plsql.test_full_name(@p_employee)).to eq(
|
812
|
+
expect(plsql.test_full_name(@p_employee)).to eq("First Last")
|
811
813
|
end
|
812
814
|
|
813
815
|
it "should execute function with Hash parameter using strings as keys" do
|
814
|
-
expect(plsql.test_full_name(@p_employee2)).to eq(
|
816
|
+
expect(plsql.test_full_name(@p_employee2)).to eq("Second Last")
|
815
817
|
end
|
816
818
|
|
817
819
|
it "should raise error if wrong field name is passed for record parameter" do
|
818
820
|
expect do
|
819
|
-
expect(plsql.test_full_name(@p_employee.merge :
|
821
|
+
expect(plsql.test_full_name(@p_employee.merge xxx: "xxx")).to eq("Second Last")
|
820
822
|
end.to raise_error(ArgumentError)
|
821
823
|
end
|
822
|
-
|
824
|
+
|
823
825
|
it "should return empty table of records" do
|
824
826
|
expect(plsql.test_record.test_empty_records()).to eq([])
|
825
827
|
end
|
@@ -829,16 +831,16 @@ describe "Parameter type mapping /" do
|
|
829
831
|
end
|
830
832
|
|
831
833
|
it "should return record return value and output record parameter value" do
|
832
|
-
expect(plsql.test_employee_record2(@p_employee, @p_employee2)).to eq([@p_employee, {:
|
834
|
+
expect(plsql.test_employee_record2(@p_employee, @p_employee2)).to eq([@p_employee, { x_employee: @p_employee }])
|
833
835
|
end
|
834
836
|
|
835
837
|
it "should execute package function with parameter with record type defined in package" do
|
836
|
-
expect(plsql.test_record.test_full_name(@p_employee)).to eq(
|
838
|
+
expect(plsql.test_record.test_full_name(@p_employee)).to eq("First Last")
|
837
839
|
end
|
838
840
|
|
839
841
|
context "functions with record parameters having boolean attributes" do
|
840
842
|
def new_candidate(status)
|
841
|
-
{:
|
843
|
+
{ candidate_id: 1, is_approved: status }
|
842
844
|
end
|
843
845
|
|
844
846
|
[true, false, nil].each do |status|
|
@@ -899,15 +901,15 @@ describe "Parameter type mapping /" do
|
|
899
901
|
end
|
900
902
|
|
901
903
|
it "should accept true value and assign true value to output parameter" do
|
902
|
-
expect(plsql.test_boolean2(true, nil)).to eq(
|
904
|
+
expect(plsql.test_boolean2(true, nil)).to eq(x_boolean: true)
|
903
905
|
end
|
904
906
|
|
905
907
|
it "should accept false value and assign false value to output parameter" do
|
906
|
-
expect(plsql.test_boolean2(false, nil)).to eq(
|
908
|
+
expect(plsql.test_boolean2(false, nil)).to eq(x_boolean: false)
|
907
909
|
end
|
908
910
|
|
909
911
|
it "should accept nil value and assign nil value to output parameter" do
|
910
|
-
expect(plsql.test_boolean2(nil, nil)).to eq(
|
912
|
+
expect(plsql.test_boolean2(nil, nil)).to eq(x_boolean: nil)
|
911
913
|
end
|
912
914
|
|
913
915
|
end
|
@@ -969,12 +971,12 @@ describe "Parameter type mapping /" do
|
|
969
971
|
END;
|
970
972
|
SQL
|
971
973
|
@p_employee = {
|
972
|
-
:
|
973
|
-
:
|
974
|
-
:
|
975
|
-
:
|
976
|
-
:
|
977
|
-
:
|
974
|
+
employee_id: 1,
|
975
|
+
first_name: "First",
|
976
|
+
last_name: "Last",
|
977
|
+
hire_date: Time.local(2000, 01, 31),
|
978
|
+
address: { street: "Main street 1", city: "Riga", country: "Latvia" },
|
979
|
+
phones: [{ type: "mobile", phone_number: "123456" }, { type: "home", phone_number: "654321" }]
|
978
980
|
}
|
979
981
|
end
|
980
982
|
|
@@ -994,16 +996,16 @@ describe "Parameter type mapping /" do
|
|
994
996
|
end
|
995
997
|
|
996
998
|
it "should execute function with named parameter and return correct value" do
|
997
|
-
expect(plsql.test_full_name(:
|
999
|
+
expect(plsql.test_full_name(p_employee: @p_employee)).to eq("First Last")
|
998
1000
|
end
|
999
1001
|
|
1000
1002
|
it "should execute function with sequential parameter and return correct value" do
|
1001
|
-
expect(plsql.test_full_name(@p_employee)).to eq(
|
1003
|
+
expect(plsql.test_full_name(@p_employee)).to eq("First Last")
|
1002
1004
|
end
|
1003
1005
|
|
1004
1006
|
it "should raise error if wrong field name is passed for record parameter" do
|
1005
1007
|
expect do
|
1006
|
-
plsql.test_full_name(@p_employee.merge :
|
1008
|
+
plsql.test_full_name(@p_employee.merge xxx: "xxx")
|
1007
1009
|
end.to raise_error(ArgumentError)
|
1008
1010
|
end
|
1009
1011
|
|
@@ -1012,7 +1014,7 @@ describe "Parameter type mapping /" do
|
|
1012
1014
|
end
|
1013
1015
|
|
1014
1016
|
it "should return object type return value and output object type parameter value" do
|
1015
|
-
expect(plsql.test_employee_object2(@p_employee, nil)).to eq([@p_employee, {:
|
1017
|
+
expect(plsql.test_employee_object2(@p_employee, nil)).to eq([@p_employee, { x_employee: @p_employee }])
|
1016
1018
|
end
|
1017
1019
|
|
1018
1020
|
it "should accept NULL as input parameter" do
|
@@ -1021,7 +1023,6 @@ describe "Parameter type mapping /" do
|
|
1021
1023
|
|
1022
1024
|
end
|
1023
1025
|
|
1024
|
-
|
1025
1026
|
describe "Function with table parameter" do
|
1026
1027
|
before(:all) do
|
1027
1028
|
plsql.connect! CONNECTION_PARAMS
|
@@ -1047,7 +1048,7 @@ describe "Parameter type mapping /" do
|
|
1047
1048
|
END IF;
|
1048
1049
|
END;
|
1049
1050
|
SQL
|
1050
|
-
|
1051
|
+
|
1051
1052
|
plsql.execute <<-SQL
|
1052
1053
|
CREATE OR REPLACE FUNCTION test_increment(p_numbers IN t_numbers, p_increment_by IN NUMBER DEFAULT 1)
|
1053
1054
|
RETURN t_numbers
|
@@ -1203,20 +1204,20 @@ describe "Parameter type mapping /" do
|
|
1203
1204
|
SQL
|
1204
1205
|
@employees = (1..10).map do |i|
|
1205
1206
|
{
|
1206
|
-
:
|
1207
|
-
:
|
1208
|
-
:
|
1209
|
-
:
|
1207
|
+
employee_id: i,
|
1208
|
+
first_name: "First #{i}",
|
1209
|
+
last_name: "Last #{i}",
|
1210
|
+
hire_date: Time.local(2000, 01, i),
|
1210
1211
|
}
|
1211
1212
|
end
|
1212
1213
|
@nstrings = (1..5).map do |i|
|
1213
1214
|
{
|
1214
|
-
:
|
1215
|
-
:
|
1216
|
-
:
|
1217
|
-
:
|
1218
|
-
:
|
1219
|
-
:
|
1215
|
+
ch_10bytes: "Ch #{i}B ",
|
1216
|
+
ch_10chars: "Ch #{i}C ",
|
1217
|
+
nch_10chars: "NCh #{i} ",
|
1218
|
+
str_10bytes: "Str #{i}C",
|
1219
|
+
str_10chars: "Str #{i}B",
|
1220
|
+
nstr_10chars: "NStr #{i}",
|
1220
1221
|
}
|
1221
1222
|
end
|
1222
1223
|
|
@@ -1260,78 +1261,78 @@ describe "Parameter type mapping /" do
|
|
1260
1261
|
end
|
1261
1262
|
|
1262
1263
|
it "should execute function with number array parameter" do
|
1263
|
-
expect(plsql.test_sum([1,2,3,4])).to eq(10)
|
1264
|
+
expect(plsql.test_sum([1, 2, 3, 4])).to eq(10)
|
1264
1265
|
end
|
1265
|
-
|
1266
|
+
|
1266
1267
|
it "should return number array return value" do
|
1267
|
-
expect(plsql.test_increment([1,2,3,4], 1)).to eq([2,3,4,5])
|
1268
|
+
expect(plsql.test_increment([1, 2, 3, 4], 1)).to eq([2, 3, 4, 5])
|
1268
1269
|
end
|
1269
1270
|
|
1270
1271
|
it "should execute function with string array and return string array output parameter" do
|
1271
|
-
strings = [
|
1272
|
-
expect(plsql.test_copy_strings(strings)).to eq([strings, {:
|
1272
|
+
strings = ["1", "2", "3", "4"]
|
1273
|
+
expect(plsql.test_copy_strings(strings)).to eq([strings, { x_strings: strings }])
|
1273
1274
|
end
|
1274
1275
|
|
1275
1276
|
it "should execute function with table of numbers type (defined inside package) parameter" do
|
1276
|
-
expect(plsql.test_collections.test_sum([1,2,3,4])).to eq(10)
|
1277
|
+
expect(plsql.test_collections.test_sum([1, 2, 3, 4])).to eq(10)
|
1277
1278
|
end
|
1278
1279
|
|
1279
1280
|
it "should clear temporary tables after executing function with table of numbers type even if an error occurs in the package" do
|
1280
1281
|
# this should work fine
|
1281
|
-
expect(plsql.test_collections.test_function_failure([1,2,3,4],
|
1282
|
+
expect(plsql.test_collections.test_function_failure([1, 2, 3, 4], "N")).to eq(4)
|
1282
1283
|
# we will force a package error here to see if things get cleaned up before the next call
|
1283
|
-
expect { plsql.test_collections.test_function_failure([1,2,3,4],
|
1284
|
+
expect { plsql.test_collections.test_function_failure([1, 2, 3, 4], "Y") }.to raise_error(/Simulate business error to test clearing of temp table/)
|
1284
1285
|
# after the error in the first call temporary tables should be cleared
|
1285
|
-
expect(plsql.test_collections.test_function_failure([5,6,7],
|
1286
|
+
expect(plsql.test_collections.test_function_failure([5, 6, 7], "N")).to eq(3)
|
1286
1287
|
end
|
1287
1288
|
|
1288
1289
|
it "should return table of numbers type (defined inside package)" do
|
1289
|
-
expect(plsql.test_collections.test_numbers([1,2,3,4])).to eq([[1,2,3,4], {:
|
1290
|
+
expect(plsql.test_collections.test_numbers([1, 2, 3, 4])).to eq([[1, 2, 3, 4], { x_numbers: [1, 2, 3, 4] }])
|
1290
1291
|
end
|
1291
1292
|
|
1292
1293
|
it "should clear temporary tables after executing function with table of numbers type (defined inside package) parameter" do
|
1293
|
-
expect(plsql.test_collections.test_numbers([1,2,3,4])).to eq([[1,2,3,4], {:
|
1294
|
+
expect(plsql.test_collections.test_numbers([1, 2, 3, 4])).to eq([[1, 2, 3, 4], { x_numbers: [1, 2, 3, 4] }])
|
1294
1295
|
# after first call temporary tables should be cleared
|
1295
|
-
expect(plsql.test_collections.test_numbers([1,2,3,4])).to eq([[1,2,3,4], {:
|
1296
|
+
expect(plsql.test_collections.test_numbers([1, 2, 3, 4])).to eq([[1, 2, 3, 4], { x_numbers: [1, 2, 3, 4] }])
|
1296
1297
|
end
|
1297
1298
|
|
1298
1299
|
it "should clear temporary tables when autocommit with table of numbers type (defined inside package) parameter" do
|
1299
1300
|
old_autocommit = plsql.connection.autocommit?
|
1300
1301
|
plsql.connection.autocommit = true
|
1301
1302
|
numbers_array = (1..400).to_a
|
1302
|
-
expect(plsql.test_collections.test_numbers(numbers_array)).to eq([numbers_array, {:
|
1303
|
+
expect(plsql.test_collections.test_numbers(numbers_array)).to eq([numbers_array, { x_numbers: numbers_array }])
|
1303
1304
|
# after first call temporary tables should be cleared
|
1304
|
-
expect(plsql.test_collections.test_numbers(numbers_array)).to eq([numbers_array, {:
|
1305
|
+
expect(plsql.test_collections.test_numbers(numbers_array)).to eq([numbers_array, { x_numbers: numbers_array }])
|
1305
1306
|
plsql.connection.autocommit = old_autocommit
|
1306
1307
|
end
|
1307
1308
|
|
1308
1309
|
it "should execute function with table of records type (defined inside package) parameter" do
|
1309
|
-
expect(plsql.test_collections.test_employees(@employees)).to eq([@employees, {:
|
1310
|
+
expect(plsql.test_collections.test_employees(@employees)).to eq([@employees, { p_employees: @employees }])
|
1310
1311
|
end
|
1311
1312
|
|
1312
1313
|
it "should execute function with table of records type (defined inside package and includes NVARCHAR columns) parameter" do
|
1313
|
-
expect(plsql.test_collections.test_nstring(@nstrings)).to eq([(1..5).map{|i| "NCh #{i}NStr #{i},"}.join, {:
|
1314
|
+
expect(plsql.test_collections.test_nstring(@nstrings)).to eq([(1..5).map { |i| "NCh #{i}NStr #{i}," }.join, { p_out: @nstrings }])
|
1314
1315
|
end
|
1315
1316
|
|
1316
1317
|
it "should execute function with object array and return object array output parameter" do
|
1317
|
-
phones = [{:
|
1318
|
-
expect(plsql.test_copy_objects(phones)).to eq([phones, {:
|
1318
|
+
phones = [{ type: "mobile", phone_number: "123456" }, { type: "home", phone_number: "654321" }]
|
1319
|
+
expect(plsql.test_copy_objects(phones)).to eq([phones, { x_phones: phones }])
|
1319
1320
|
end
|
1320
1321
|
|
1321
1322
|
it "should execute function with empty object array" do
|
1322
1323
|
phones = []
|
1323
|
-
expect(plsql.test_copy_objects(phones)).to eq([phones, {:
|
1324
|
+
expect(plsql.test_copy_objects(phones)).to eq([phones, { x_phones: phones }])
|
1324
1325
|
end
|
1325
1326
|
|
1326
1327
|
it "should raise error with record parameter that has table as element" do
|
1327
1328
|
expect {
|
1328
|
-
expect(plsql.test_collections.test_employee2(@employees[0])).to eq([@employees[0], {:
|
1329
|
+
expect(plsql.test_collections.test_employee2(@employees[0])).to eq([@employees[0], { p_employee: @employees[0] }])
|
1329
1330
|
}.to raise_error(ArgumentError, /TEST_COLLECTIONS\.T_NUMBERS definition inside package is not supported/)
|
1330
1331
|
end
|
1331
1332
|
|
1332
1333
|
it "should raise error with table of records parameter when record has table as element" do
|
1333
1334
|
expect {
|
1334
|
-
expect(plsql.test_collections.test_employees2(@employees)).to eq([@employees, {:
|
1335
|
+
expect(plsql.test_collections.test_employees2(@employees)).to eq([@employees, { p_employees: @employees }])
|
1335
1336
|
}.to raise_error(ArgumentError, /TEST_COLLECTIONS\.T_NUMBERS definition inside package is not supported/)
|
1336
1337
|
end
|
1337
1338
|
|
@@ -1440,15 +1441,15 @@ describe "Parameter type mapping /" do
|
|
1440
1441
|
END;
|
1441
1442
|
SQL
|
1442
1443
|
# test with negative PL/SQL table indexes
|
1443
|
-
@numbers = Hash[*(1..4).map{|i|[-i,i]}.flatten]
|
1444
|
-
@numbers2 = Hash[*(5..7).map{|i|[-i,i]}.flatten]
|
1444
|
+
@numbers = Hash[*(1..4).map { |i|[-i, i] }.flatten]
|
1445
|
+
@numbers2 = Hash[*(5..7).map { |i|[-i, i] }.flatten]
|
1445
1446
|
# test with reversed PL/SQL table indexes
|
1446
1447
|
@employees = Hash[*(1..10).map do |i|
|
1447
|
-
[11-i, {
|
1448
|
-
:
|
1449
|
-
:
|
1450
|
-
:
|
1451
|
-
:
|
1448
|
+
[11 - i, {
|
1449
|
+
employee_id: i,
|
1450
|
+
first_name: "First #{i}",
|
1451
|
+
last_name: "Last #{i}",
|
1452
|
+
hire_date: Time.local(2000, 01, i)
|
1452
1453
|
}]
|
1453
1454
|
end.flatten]
|
1454
1455
|
end
|
@@ -1462,11 +1463,11 @@ describe "Parameter type mapping /" do
|
|
1462
1463
|
|
1463
1464
|
it "should clear temporary tables after executing function with index-by table of numbers type even if an error occurs in the package" do
|
1464
1465
|
# this should work fine
|
1465
|
-
expect(plsql.test_collections.test_function_failure(@numbers,
|
1466
|
+
expect(plsql.test_collections.test_function_failure(@numbers, "N")).to eq(10)
|
1466
1467
|
# we will force a package error here to see if things get cleaned up before the next call
|
1467
|
-
expect { plsql.test_collections.test_function_failure(@numbers,
|
1468
|
+
expect { plsql.test_collections.test_function_failure(@numbers, "Y") }.to raise_error(/Simulate business error to test clearing of temp table/)
|
1468
1469
|
# after the error in the first call temporary tables should be cleared
|
1469
|
-
expect(plsql.test_collections.test_function_failure(@numbers2,
|
1470
|
+
expect(plsql.test_collections.test_function_failure(@numbers2, "N")).to eq(18)
|
1470
1471
|
end
|
1471
1472
|
|
1472
1473
|
it "should execute function with index-by table of numbers type (defined inside package) parameter" do
|
@@ -1474,25 +1475,25 @@ describe "Parameter type mapping /" do
|
|
1474
1475
|
end
|
1475
1476
|
|
1476
1477
|
it "should return index-by table of numbers type (defined inside package)" do
|
1477
|
-
expect(plsql.test_collections.test_numbers(@numbers)).to eq([@numbers, {:
|
1478
|
+
expect(plsql.test_collections.test_numbers(@numbers)).to eq([@numbers, { x_numbers: @numbers }])
|
1478
1479
|
end
|
1479
1480
|
|
1480
1481
|
it "should clear temporary tables when autocommit with index-by table of numbers type (defined inside package) parameter" do
|
1481
1482
|
old_autocommit = plsql.connection.autocommit?
|
1482
1483
|
plsql.connection.autocommit = true
|
1483
|
-
numbers_hash = Hash[*(1..400).map{|i|[i,i]}.flatten]
|
1484
|
-
expect(plsql.test_collections.test_numbers(numbers_hash)).to eq([numbers_hash, {:
|
1484
|
+
numbers_hash = Hash[*(1..400).map { |i|[i, i] }.flatten]
|
1485
|
+
expect(plsql.test_collections.test_numbers(numbers_hash)).to eq([numbers_hash, { x_numbers: numbers_hash }])
|
1485
1486
|
# after first call temporary tables should be cleared
|
1486
|
-
expect(plsql.test_collections.test_numbers(numbers_hash)).to eq([numbers_hash, {:
|
1487
|
+
expect(plsql.test_collections.test_numbers(numbers_hash)).to eq([numbers_hash, { x_numbers: numbers_hash }])
|
1487
1488
|
plsql.connection.autocommit = old_autocommit
|
1488
1489
|
end
|
1489
1490
|
|
1490
1491
|
it "should execute function with index-by table of records type (defined inside package) parameter" do
|
1491
|
-
expect(plsql.test_collections.test_employees(@employees)).to eq([@employees, {:
|
1492
|
+
expect(plsql.test_collections.test_employees(@employees)).to eq([@employees, { p_employees: @employees }])
|
1492
1493
|
end
|
1493
1494
|
|
1494
1495
|
it "should execute procedure with index-by table of records type (defined inside package) parameter" do
|
1495
|
-
expect(plsql.test_collections.test_employees_prc(@employees)).to eq(
|
1496
|
+
expect(plsql.test_collections.test_employees_prc(@employees)).to eq(p_employees: @employees)
|
1496
1497
|
end
|
1497
1498
|
|
1498
1499
|
it "should create temporary tables in autonomous transaction" do
|
@@ -1500,7 +1501,7 @@ describe "Parameter type mapping /" do
|
|
1500
1501
|
plsql.connection.autocommit = false
|
1501
1502
|
plsql.test_employees.insert @employees[1]
|
1502
1503
|
# procedure call should not commit initial insert
|
1503
|
-
plsql.test_collections.insert_employees(2
|
1504
|
+
plsql.test_collections.insert_employees(2 => @employees[2], 3 => @employees[3])
|
1504
1505
|
plsql.rollback
|
1505
1506
|
expect(plsql.test_employees.all).to be_empty
|
1506
1507
|
plsql.connection.autocommit = old_autocommit
|
@@ -1518,14 +1519,13 @@ describe "Parameter type mapping /" do
|
|
1518
1519
|
end
|
1519
1520
|
|
1520
1521
|
it "should create temporary tables when using Oracle 9.2" do
|
1521
|
-
expect(plsql(:oracle_9).test_collections.test_numbers(@numbers)).to eq([@numbers, {:
|
1522
|
+
expect(plsql(:oracle_9).test_collections.test_numbers(@numbers)).to eq([@numbers, { x_numbers: @numbers }])
|
1522
1523
|
end
|
1523
1524
|
|
1524
1525
|
end
|
1525
1526
|
|
1526
1527
|
end
|
1527
1528
|
|
1528
|
-
|
1529
1529
|
describe "Function with VARRAY parameter" do
|
1530
1530
|
before(:all) do
|
1531
1531
|
plsql.connect! CONNECTION_PARAMS
|
@@ -1621,26 +1621,26 @@ describe "Parameter type mapping /" do
|
|
1621
1621
|
end
|
1622
1622
|
|
1623
1623
|
it "should execute function with number array parameter" do
|
1624
|
-
expect(plsql.test_sum([1,2,3,4])).to eq(10)
|
1624
|
+
expect(plsql.test_sum([1, 2, 3, 4])).to eq(10)
|
1625
1625
|
end
|
1626
1626
|
|
1627
1627
|
it "should return number array return value" do
|
1628
|
-
expect(plsql.test_increment([1,2,3,4], 1)).to eq([2,3,4,5])
|
1628
|
+
expect(plsql.test_increment([1, 2, 3, 4], 1)).to eq([2, 3, 4, 5])
|
1629
1629
|
end
|
1630
1630
|
|
1631
1631
|
it "should execute function with string array and return string array output parameter" do
|
1632
|
-
strings = [
|
1633
|
-
expect(plsql.test_copy_strings(strings)).to eq([strings, {:
|
1632
|
+
strings = ["1", "2", "3", "4"]
|
1633
|
+
expect(plsql.test_copy_strings(strings)).to eq([strings, { x_strings: strings }])
|
1634
1634
|
end
|
1635
1635
|
|
1636
1636
|
it "should execute function with object array and return object array output parameter" do
|
1637
|
-
phones = [{:
|
1638
|
-
expect(plsql.test_copy_objects(phones)).to eq([phones, {:
|
1637
|
+
phones = [{ type: "mobile", phone_number: "123456" }, { type: "home", phone_number: "654321" }]
|
1638
|
+
expect(plsql.test_copy_objects(phones)).to eq([phones, { x_phones: phones }])
|
1639
1639
|
end
|
1640
1640
|
|
1641
1641
|
it "should execute function with empty object array" do
|
1642
1642
|
phones = []
|
1643
|
-
expect(plsql.test_copy_objects(phones)).to eq([phones, {:
|
1643
|
+
expect(plsql.test_copy_objects(phones)).to eq([phones, { x_phones: phones }])
|
1644
1644
|
end
|
1645
1645
|
|
1646
1646
|
end
|
@@ -1750,30 +1750,30 @@ describe "Parameter type mapping /" do
|
|
1750
1750
|
end
|
1751
1751
|
|
1752
1752
|
it "should execute function with number array parameter" do
|
1753
|
-
expect(plsql.test_collections.test_sum([1,2,3,4])).to eq(10)
|
1753
|
+
expect(plsql.test_collections.test_sum([1, 2, 3, 4])).to eq(10)
|
1754
1754
|
end
|
1755
1755
|
|
1756
1756
|
it "should clear temporary tables after executing function with varray of numbers type even if an error occurs in the package" do
|
1757
1757
|
# this should work fine
|
1758
|
-
expect(plsql.test_collections.test_function_failure([1,2,3,4],
|
1758
|
+
expect(plsql.test_collections.test_function_failure([1, 2, 3, 4], "N")).to eq(10)
|
1759
1759
|
# we will force a package error here to see if things get cleaned up before the next call
|
1760
|
-
expect { plsql.test_collections.test_function_failure([5,6,7],
|
1760
|
+
expect { plsql.test_collections.test_function_failure([5, 6, 7], "Y") }.to raise_error(/Simulate business error to test clearing of temp table/)
|
1761
1761
|
# after the error in the first call temporary tables should be cleared
|
1762
|
-
expect(plsql.test_collections.test_function_failure([3,4,5,6],
|
1762
|
+
expect(plsql.test_collections.test_function_failure([3, 4, 5, 6], "N")).to eq(18)
|
1763
1763
|
end
|
1764
1764
|
|
1765
1765
|
it "should return number array return value" do
|
1766
|
-
expect(plsql.test_collections.test_increment([1,2,3,4], 1)).to eq([2,3,4,5])
|
1766
|
+
expect(plsql.test_collections.test_increment([1, 2, 3, 4], 1)).to eq([2, 3, 4, 5])
|
1767
1767
|
end
|
1768
1768
|
|
1769
1769
|
it "should execute function with string array and return string array output parameter" do
|
1770
|
-
strings = [
|
1771
|
-
expect(plsql.test_collections.test_copy_strings(strings)).to eq([strings, {:
|
1770
|
+
strings = ["1", "2", "3", "4"]
|
1771
|
+
expect(plsql.test_collections.test_copy_strings(strings)).to eq([strings, { x_strings: strings }])
|
1772
1772
|
end
|
1773
1773
|
|
1774
1774
|
it "should execute function with object array and return object array output parameter" do
|
1775
|
-
phones = [{:
|
1776
|
-
expect(plsql.test_collections.test_copy_objects(phones)).to eq([phones, {:
|
1775
|
+
phones = [{ type: "mobile", phone_number: "123456" }, { type: "home", phone_number: "654321" }]
|
1776
|
+
expect(plsql.test_collections.test_copy_objects(phones)).to eq([phones, { x_phones: phones }])
|
1777
1777
|
end
|
1778
1778
|
|
1779
1779
|
# This test fails without wcmatthysen's "Procedure-call Fix." pull request.
|
@@ -1836,10 +1836,10 @@ describe "Parameter type mapping /" do
|
|
1836
1836
|
@fields = [:employee_id, :first_name, :last_name, :hire_date]
|
1837
1837
|
@employees = (1..10).map do |i|
|
1838
1838
|
{
|
1839
|
-
:
|
1840
|
-
:
|
1841
|
-
:
|
1842
|
-
:
|
1839
|
+
employee_id: i,
|
1840
|
+
first_name: "First #{i}",
|
1841
|
+
last_name: "Last #{i}",
|
1842
|
+
hire_date: Time.local(2000, 01, i)
|
1843
1843
|
}
|
1844
1844
|
end
|
1845
1845
|
@employees.each do |e|
|
@@ -1863,7 +1863,7 @@ describe "Parameter type mapping /" do
|
|
1863
1863
|
|
1864
1864
|
it "should return cursor and fetch first row" do
|
1865
1865
|
expect(plsql.test_cursor do |cursor|
|
1866
|
-
expect(cursor.fetch).to eq(@fields.map{|f| @employees[0][f]})
|
1866
|
+
expect(cursor.fetch).to eq(@fields.map { |f| @employees[0][f] })
|
1867
1867
|
end).to be_nil
|
1868
1868
|
end
|
1869
1869
|
|
@@ -1891,7 +1891,7 @@ describe "Parameter type mapping /" do
|
|
1891
1891
|
|
1892
1892
|
it "should fetch all rows from returned cursor" do
|
1893
1893
|
plsql.test_cursor do |cursor|
|
1894
|
-
expect(cursor.fetch_all).to eq(@employees.map{|e| @fields.map{|f| e[f]}})
|
1894
|
+
expect(cursor.fetch_all).to eq(@employees.map { |e| @fields.map { |f| e[f] } })
|
1895
1895
|
end
|
1896
1896
|
end
|
1897
1897
|
|
@@ -1909,7 +1909,7 @@ describe "Parameter type mapping /" do
|
|
1909
1909
|
|
1910
1910
|
it "should return output parameter with cursor and fetch first row" do
|
1911
1911
|
expect(plsql.test_cursor_out do |result|
|
1912
|
-
expect(result[:x_cursor].fetch).to eq(@fields.map{|f| @employees[0][f]})
|
1912
|
+
expect(result[:x_cursor].fetch).to eq(@fields.map { |f| @employees[0][f] })
|
1913
1913
|
end).to be_nil
|
1914
1914
|
end
|
1915
1915
|
|
@@ -1959,7 +1959,7 @@ describe "Parameter type mapping /" do
|
|
1959
1959
|
SQL
|
1960
1960
|
|
1961
1961
|
@fields = [:col1, :col2 ]
|
1962
|
-
@rows = (1..3).map{|i| ["row #{i}", i]}
|
1962
|
+
@rows = (1..3).map { |i| ["row #{i}", i] }
|
1963
1963
|
plsql.typed_ref_cursor_table.insert_values *@rows
|
1964
1964
|
plsql.commit
|
1965
1965
|
|
@@ -2003,7 +2003,7 @@ describe "Synonyms /" do
|
|
2003
2003
|
end
|
2004
2004
|
|
2005
2005
|
describe "Local synonym to function" do
|
2006
|
-
|
2006
|
+
|
2007
2007
|
before(:all) do
|
2008
2008
|
plsql.execute <<-SQL
|
2009
2009
|
CREATE OR REPLACE FUNCTION hr.test_uppercase
|
@@ -2016,24 +2016,24 @@ describe "Synonyms /" do
|
|
2016
2016
|
SQL
|
2017
2017
|
plsql.execute "CREATE SYNONYM test_synonym FOR hr.test_uppercase"
|
2018
2018
|
end
|
2019
|
-
|
2019
|
+
|
2020
2020
|
after(:all) do
|
2021
2021
|
plsql.execute "DROP SYNONYM test_synonym"
|
2022
2022
|
plsql.execute "DROP FUNCTION hr.test_uppercase"
|
2023
2023
|
end
|
2024
|
-
|
2024
|
+
|
2025
2025
|
it "should find synonym to function" do
|
2026
2026
|
expect(PLSQL::Procedure.find(plsql, :test_synonym)).not_to be_nil
|
2027
2027
|
end
|
2028
2028
|
|
2029
2029
|
it "should execute function using synonym and return correct value" do
|
2030
|
-
expect(plsql.test_synonym(
|
2030
|
+
expect(plsql.test_synonym("xxx")).to eq("XXX")
|
2031
2031
|
end
|
2032
2032
|
|
2033
2033
|
end
|
2034
2034
|
|
2035
2035
|
describe "Public synonym to function" do
|
2036
|
-
|
2036
|
+
|
2037
2037
|
before(:all) do
|
2038
2038
|
plsql.execute <<-SQL
|
2039
2039
|
CREATE OR REPLACE FUNCTION hr.test_ora_login_user
|
@@ -2044,17 +2044,17 @@ describe "Synonyms /" do
|
|
2044
2044
|
END test_ora_login_user;
|
2045
2045
|
SQL
|
2046
2046
|
end
|
2047
|
-
|
2047
|
+
|
2048
2048
|
after(:all) do
|
2049
2049
|
plsql.execute "DROP FUNCTION hr.test_ora_login_user"
|
2050
2050
|
end
|
2051
|
-
|
2051
|
+
|
2052
2052
|
it "should find public synonym to function" do
|
2053
2053
|
expect(PLSQL::Procedure.find(plsql, :ora_login_user)).not_to be_nil
|
2054
2054
|
end
|
2055
2055
|
|
2056
2056
|
it "should execute function using public synonym and return correct value" do
|
2057
|
-
expect(plsql.ora_login_user).to eq(
|
2057
|
+
expect(plsql.ora_login_user).to eq("HR")
|
2058
2058
|
end
|
2059
2059
|
|
2060
2060
|
it "should not find public synonym if schema prefix is used" do
|
@@ -2066,10 +2066,10 @@ describe "Synonyms /" do
|
|
2066
2066
|
plsql.connection = get_connection
|
2067
2067
|
plsql.execute "DROP SYNONYM ora_login_user" rescue nil
|
2068
2068
|
plsql.execute "CREATE SYNONYM ora_login_user FOR hr.test_ora_login_user"
|
2069
|
-
expect(plsql.ora_login_user).to eq(
|
2069
|
+
expect(plsql.ora_login_user).to eq("XXX")
|
2070
2070
|
plsql.execute "DROP SYNONYM ora_login_user"
|
2071
2071
|
plsql.connection = get_connection
|
2072
|
-
expect(plsql.ora_login_user).to eq(
|
2072
|
+
expect(plsql.ora_login_user).to eq("HR")
|
2073
2073
|
end
|
2074
2074
|
|
2075
2075
|
end
|
@@ -2107,14 +2107,67 @@ describe "Synonyms /" do
|
|
2107
2107
|
|
2108
2108
|
it "should raise error when invalid function is called" do
|
2109
2109
|
expect {
|
2110
|
-
plsql.test_invalid_function(
|
2110
|
+
plsql.test_invalid_function("test")
|
2111
2111
|
}.to raise_error(ArgumentError, /is not in valid status/)
|
2112
2112
|
end
|
2113
2113
|
|
2114
2114
|
it "should raise error when function from invalid package body is called" do
|
2115
2115
|
expect {
|
2116
|
-
plsql.test_invalid_package.test_invalid_function(
|
2117
|
-
}.to raise_error(
|
2116
|
+
plsql.test_invalid_package.test_invalid_function("test")
|
2117
|
+
}.to raise_error(oracle_error_class, /ORA-04063/)
|
2118
|
+
end
|
2119
|
+
end
|
2120
|
+
|
2121
|
+
describe "invalid objects that can be automatically recompiled" do
|
2122
|
+
before(:all) do
|
2123
|
+
plsql.execute "DROP TABLE test_recompilable_table" rescue nil
|
2124
|
+
plsql.execute "CREATE TABLE test_recompilable_table (dummy VARCHAR2(10))"
|
2125
|
+
plsql.execute <<-SQL
|
2126
|
+
CREATE OR REPLACE FUNCTION test_recompilable_function(p_dummy VARCHAR2) RETURN VARCHAR2 IS
|
2127
|
+
l_dummy test_recompilable_table.dummy%TYPE;
|
2128
|
+
BEGIN
|
2129
|
+
RETURN p_dummy;
|
2130
|
+
END;
|
2131
|
+
SQL
|
2132
|
+
plsql.execute <<-SQL
|
2133
|
+
CREATE OR REPLACE PACKAGE test_recompilable_package IS
|
2134
|
+
FUNCTION test_recompilable_function(p_dummy VARCHAR2) RETURN VARCHAR2;
|
2135
|
+
END;
|
2136
|
+
SQL
|
2137
|
+
plsql.execute <<-SQL
|
2138
|
+
CREATE OR REPLACE PACKAGE BODY test_recompilable_package IS
|
2139
|
+
FUNCTION test_recompilable_function(p_dummy VARCHAR2) RETURN VARCHAR2 IS
|
2140
|
+
l_dummy test_recompilable_table.dummy%TYPE;
|
2141
|
+
BEGIN
|
2142
|
+
RETURN p_dummy;
|
2143
|
+
END;
|
2144
|
+
END;
|
2145
|
+
SQL
|
2146
|
+
end
|
2147
|
+
|
2148
|
+
before(:each) do
|
2149
|
+
# Cause the dependent function and package to go into INVALID status
|
2150
|
+
plsql.execute "ALTER TABLE test_recompilable_table MODIFY (dummy VARCHAR2(10))"
|
2151
|
+
end
|
2152
|
+
|
2153
|
+
after(:all) do
|
2154
|
+
plsql.execute "DROP TABLE test_recompilable_table"
|
2155
|
+
plsql.execute "DROP FUNCTION test_recompilable_function"
|
2156
|
+
plsql.execute "DROP PACKAGE test_recompilable_package"
|
2157
|
+
end
|
2158
|
+
|
2159
|
+
it "should successfully call invalid function that can be recompiled" do
|
2160
|
+
expect {
|
2161
|
+
result = plsql.test_recompilable_function("test")
|
2162
|
+
expect(result).to eq("test")
|
2163
|
+
}.not_to raise_error
|
2164
|
+
end
|
2165
|
+
|
2166
|
+
it "should successfully call invalid package body that can be recompiled" do
|
2167
|
+
expect {
|
2168
|
+
result = plsql.test_recompilable_package.test_recompilable_function("test")
|
2169
|
+
expect(result).to eq("test")
|
2170
|
+
}.not_to raise_error
|
2118
2171
|
end
|
2119
2172
|
end
|
2120
2173
|
|
@@ -2131,7 +2184,7 @@ describe "SYS.STANDARD procedures /" do
|
|
2131
2184
|
end
|
2132
2185
|
|
2133
2186
|
it "should execute function from SYS.STANDARD package" do
|
2134
|
-
expect(plsql.upper(
|
2187
|
+
expect(plsql.upper("abc")).to eq("ABC")
|
2135
2188
|
end
|
2136
2189
|
|
2137
2190
|
it "should find function overload based on types of sequential arguments" do
|
@@ -2139,14 +2192,14 @@ describe "SYS.STANDARD procedures /" do
|
|
2139
2192
|
expect(plsql.nvl(nil, 2)).to eq(2)
|
2140
2193
|
expect(plsql.nvl(1.1, 2.2)).to eq(1.1)
|
2141
2194
|
expect(plsql.nvl(nil, 2.2)).to eq(2.2)
|
2142
|
-
expect(plsql.nvl(BigDecimal(
|
2143
|
-
expect(plsql.nvl(nil, BigDecimal(
|
2144
|
-
expect(plsql.nvl(
|
2145
|
-
expect(plsql.nvl(nil,
|
2146
|
-
expect(plsql.nvl(Date.new(2010,1,13), Date.new(2010,1,19))).to eq(Time.local(2010,1,13))
|
2147
|
-
expect(plsql.nvl(nil, Date.new(2010,1,19))).to eq(Time.local(2010,1,19))
|
2148
|
-
expect(plsql.nvl(Time.local(2010,1,13), Time.local(2010,1,19))).to eq(Time.local(2010,1,13))
|
2149
|
-
expect(plsql.nvl(nil, Time.local(2010,1,19))).to eq(Time.local(2010,1,19))
|
2195
|
+
expect(plsql.nvl(BigDecimal("1.1"), BigDecimal("2.2"))).to eq(BigDecimal("1.1"))
|
2196
|
+
expect(plsql.nvl(nil, BigDecimal("2.2"))).to eq(BigDecimal("2.2"))
|
2197
|
+
expect(plsql.nvl("a", "b")).to eq("a")
|
2198
|
+
expect(plsql.nvl(nil, "b")).to eq("b")
|
2199
|
+
expect(plsql.nvl(Date.new(2010, 1, 13), Date.new(2010, 1, 19))).to eq(Time.local(2010, 1, 13))
|
2200
|
+
expect(plsql.nvl(nil, Date.new(2010, 1, 19))).to eq(Time.local(2010, 1, 19))
|
2201
|
+
expect(plsql.nvl(Time.local(2010, 1, 13), Time.local(2010, 1, 19))).to eq(Time.local(2010, 1, 13))
|
2202
|
+
expect(plsql.nvl(nil, Time.local(2010, 1, 19))).to eq(Time.local(2010, 1, 19))
|
2150
2203
|
expect(plsql.nvl(true, false)).to eq(true)
|
2151
2204
|
expect(plsql.nvl(nil, false)).to eq(false)
|
2152
2205
|
end
|
@@ -2218,41 +2271,41 @@ describe "PLS_INTEGER/SIMPLE_INTEGER should be nullable" do
|
|
2218
2271
|
plsql.logoff
|
2219
2272
|
end
|
2220
2273
|
|
2221
|
-
it
|
2274
|
+
it "should return null for a function call with NULL PLS_INTEGER param" do
|
2222
2275
|
expect(plsql.test_pls_f(nil)).to be_nil
|
2223
2276
|
end
|
2224
2277
|
|
2225
|
-
it
|
2278
|
+
it "should return null for a function call with NULL BINARY_INTEGER param" do
|
2226
2279
|
expect(plsql.test_bin_f(nil)).to be_nil
|
2227
2280
|
end
|
2228
2281
|
|
2229
|
-
it
|
2282
|
+
it "should return null for a function call with NULL INTEGER param" do
|
2230
2283
|
expect(plsql.test_int_f(nil)).to be_nil
|
2231
2284
|
end
|
2232
2285
|
|
2233
|
-
it
|
2286
|
+
it "should return null for a procedure call with NULL PLS_INTEGER param" do
|
2234
2287
|
expect(plsql.test_pls_p(nil)[:p_num]).to be_nil
|
2235
2288
|
end
|
2236
2289
|
|
2237
|
-
it
|
2290
|
+
it "should return null for a procedure call with NULL BINARY_INTEGER param" do
|
2238
2291
|
expect(plsql.test_bin_p(nil)[:p_num]).to be_nil
|
2239
2292
|
end
|
2240
2293
|
|
2241
|
-
it
|
2294
|
+
it "should return null for a procedure call with NULL INTEGER param" do
|
2242
2295
|
expect(plsql.test_int_p(nil)[:p_num]).to be_nil
|
2243
2296
|
end
|
2244
2297
|
|
2245
|
-
it
|
2298
|
+
it "should return null for a procedure call with NULL BINARY_FLOAT param" do
|
2246
2299
|
expect(plsql.test_flt_p(nil)[:p_num]).to be_nil
|
2247
2300
|
end
|
2248
2301
|
|
2249
|
-
it
|
2302
|
+
it "should return null for a procedure call with NULL BINARY_DOUBLE param" do
|
2250
2303
|
expect(plsql.test_dbl_p(nil)[:p_num]).to be_nil
|
2251
2304
|
end
|
2252
2305
|
|
2253
2306
|
end
|
2254
2307
|
|
2255
|
-
describe
|
2308
|
+
describe "#get_argument_metadata" do
|
2256
2309
|
before(:all) do
|
2257
2310
|
plsql.connect! CONNECTION_PARAMS
|
2258
2311
|
end
|
@@ -2276,26 +2329,26 @@ describe '#get_argument_metadata' do
|
|
2276
2329
|
plsql.execute "DROP FUNCTION magic_number"
|
2277
2330
|
end
|
2278
2331
|
|
2279
|
-
context
|
2280
|
-
let(:defaulted_clause) {
|
2332
|
+
context "on procedure with defaulted field" do
|
2333
|
+
let(:defaulted_clause) { "DEFAULT 21" }
|
2281
2334
|
|
2282
2335
|
it 'field\'s metadata attribute "defaulted" is Y' do
|
2283
2336
|
procedure = PLSQL::Procedure.find(plsql, :magic_number)
|
2284
|
-
expect(procedure.arguments[0][:p_num][:defaulted]).to eq(
|
2337
|
+
expect(procedure.arguments[0][:p_num][:defaulted]).to eq("Y")
|
2285
2338
|
end
|
2286
2339
|
end
|
2287
2340
|
|
2288
|
-
context
|
2289
|
-
let(:defaulted_clause) {
|
2341
|
+
context "procedure without defaulted field" do
|
2342
|
+
let(:defaulted_clause) { "" }
|
2290
2343
|
|
2291
2344
|
it 'field\'s metadata attribute "defaulted" is N' do
|
2292
2345
|
procedure = PLSQL::Procedure.find(plsql, :magic_number)
|
2293
|
-
expect(procedure.arguments[0][:p_num][:defaulted]).to eq(
|
2346
|
+
expect(procedure.arguments[0][:p_num][:defaulted]).to eq("N")
|
2294
2347
|
end
|
2295
2348
|
end
|
2296
2349
|
|
2297
|
-
context
|
2298
|
-
let(:defaulted_clause) {
|
2350
|
+
context "oracle <= 10g without defaulted functionality" do
|
2351
|
+
let(:defaulted_clause) { "" }
|
2299
2352
|
|
2300
2353
|
it 'field\'s metadata attribute "defaulted" is nil' do
|
2301
2354
|
allow(plsql.connection).to receive(:database_version).and_return([10, 2, 0, 2])
|