ruby-plsql 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +35 -0
- data/.travis/oracle/LICENSE +5 -0
- data/.travis/oracle/README.md +64 -0
- data/.travis/oracle/download.js +100 -0
- data/.travis/oracle/download.sh +16 -0
- data/.travis/oracle/install.sh +32 -0
- data/.travis/setup_accounts.sh +9 -0
- data/Gemfile +4 -3
- data/History.txt +22 -0
- data/README.md +20 -1
- data/VERSION +1 -1
- data/Vagrantfile +2 -2
- data/lib/plsql/connection.rb +2 -3
- data/lib/plsql/jdbc_connection.rb +6 -7
- data/lib/plsql/oci_connection.rb +11 -8
- data/lib/plsql/package.rb +60 -42
- data/lib/plsql/procedure.rb +8 -5
- data/lib/plsql/procedure_call.rb +52 -9
- data/lib/plsql/schema.rb +1 -1
- data/lib/plsql/variable.rb +5 -4
- data/ruby-plsql.gemspec +24 -11
- data/spec/plsql/connection_spec.rb +9 -3
- data/spec/plsql/package_spec.rb +50 -1
- data/spec/plsql/procedure_spec.rb +320 -61
- data/spec/plsql/schema_spec.rb +21 -4
- data/spec/plsql/sql_statements_spec.rb +1 -1
- data/spec/plsql/table_spec.rb +2 -2
- data/spec/plsql/type_spec.rb +1 -1
- data/spec/plsql/variable_spec.rb +37 -45
- data/spec/spec_helper.rb +0 -5
- data/spec/support/create_arunit_user.sql +2 -0
- data/spec/support/custom_config.rb.sample +14 -0
- data/spec/support/unlock_and_setup_hr_user.sql +2 -0
- metadata +31 -7
data/spec/plsql/package_spec.rb
CHANGED
@@ -20,7 +20,6 @@ describe "Package" do
|
|
20
20
|
END test_procedure;
|
21
21
|
END;
|
22
22
|
SQL
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
25
|
after(:all) do
|
@@ -55,6 +54,56 @@ describe "Package" do
|
|
55
54
|
expect(plsql.test_package.procedure_defined?(:inexistent_procedure)).to be_falsey
|
56
55
|
end
|
57
56
|
|
57
|
+
it "should search objects via []" do
|
58
|
+
package = PLSQL::Package.find(plsql, :test_package)
|
59
|
+
|
60
|
+
[:Test_Procedure, :test_procedure, 'test_procedure', 'TEST_PROCEDURE'].each do |name_variant|
|
61
|
+
expect(package[name_variant]).to be_a PLSQL::Procedure
|
62
|
+
end
|
63
|
+
|
64
|
+
[:Test_Variable, :test_variable, 'test_variable', 'TEST_VARIABLE'].each do |name_variant|
|
65
|
+
expect(package[name_variant]).to be_a PLSQL::Variable
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with a user with execute privilege who is not the package owner" do
|
70
|
+
before(:all) do
|
71
|
+
plsql.execute("grant execute on TEST_PACKAGE to #{DATABASE_USERS_AND_PASSWORDS[1][0]}")
|
72
|
+
@original_connection = plsql.connection
|
73
|
+
@conn = get_connection(1)
|
74
|
+
end
|
75
|
+
|
76
|
+
before(:each) do
|
77
|
+
# resetting connection clears cached package objects and schema name
|
78
|
+
plsql.connection = @conn
|
79
|
+
end
|
80
|
+
|
81
|
+
after(:all) do
|
82
|
+
plsql.logoff
|
83
|
+
plsql.connection = @original_connection
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should not find existing package" do
|
87
|
+
expect(PLSQL::Package.find(plsql, :test_package)).to be_nil
|
88
|
+
end
|
89
|
+
|
90
|
+
context "who sets current_schema to match the package owner" do
|
91
|
+
before(:all) do
|
92
|
+
plsql.execute "ALTER SESSION set current_schema=#{DATABASE_USERS_AND_PASSWORDS[0][0]}"
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should find existing package" do
|
96
|
+
expect(PLSQL::Package.find(plsql, :test_package)).not_to be_nil
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should report an existing procedure as existing" do
|
100
|
+
expect(plsql.test_package.procedure_defined?(:test_procedure)).to be_truthy
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
58
107
|
describe "variables" do
|
59
108
|
it "should set and get package variable value" do
|
60
109
|
plsql.test_package.test_variable = 1
|
@@ -3,13 +3,14 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe "Parameter type mapping /" do
|
6
|
-
|
6
|
+
|
7
|
+
shared_examples "Function with string parameters" do |datatype|
|
7
8
|
before(:all) do
|
8
9
|
plsql.connect! CONNECTION_PARAMS
|
9
10
|
plsql.execute <<-SQL
|
10
11
|
CREATE OR REPLACE FUNCTION test_uppercase
|
11
|
-
( p_string
|
12
|
-
RETURN
|
12
|
+
( p_string #{datatype} )
|
13
|
+
RETURN #{datatype}
|
13
14
|
IS
|
14
15
|
BEGIN
|
15
16
|
RETURN UPPER(p_string);
|
@@ -56,83 +57,85 @@ describe "Parameter type mapping /" do
|
|
56
57
|
|
57
58
|
end
|
58
59
|
|
59
|
-
|
60
|
+
['VARCHAR', 'VARCHAR2'].each do |datatype|
|
61
|
+
describe "Function with #{datatype} parameters" do
|
62
|
+
it_should_behave_like "Function with string parameters", datatype
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
shared_examples "Function with numeric" do |ora_data_type, class_, num1, num2, expected, mandatory|
|
60
67
|
before(:all) do
|
61
68
|
plsql.connect! CONNECTION_PARAMS
|
62
69
|
plsql.execute <<-SQL
|
63
70
|
CREATE OR REPLACE FUNCTION test_sum
|
64
|
-
( p_num1
|
65
|
-
RETURN
|
71
|
+
( p_num1 #{ora_data_type}, p_num2 #{ora_data_type} )
|
72
|
+
RETURN #{ora_data_type}
|
66
73
|
IS
|
67
74
|
BEGIN
|
68
75
|
RETURN p_num1 + p_num2;
|
69
76
|
END test_sum;
|
70
77
|
SQL
|
71
|
-
plsql.execute <<-SQL
|
72
|
-
CREATE OR REPLACE FUNCTION test_number_1
|
73
|
-
( p_num NUMBER )
|
74
|
-
RETURN VARCHAR2
|
75
|
-
IS
|
76
|
-
BEGIN
|
77
|
-
IF p_num = 1 THEN
|
78
|
-
RETURN 'Y';
|
79
|
-
ELSIF p_num = 0 THEN
|
80
|
-
RETURN 'N';
|
81
|
-
ELSIF p_num IS NULL THEN
|
82
|
-
RETURN NULL;
|
83
|
-
ELSE
|
84
|
-
RETURN 'UNKNOWN';
|
85
|
-
END IF;
|
86
|
-
END test_number_1;
|
87
|
-
SQL
|
88
|
-
plsql.execute <<-SQL
|
89
|
-
CREATE OR REPLACE PROCEDURE test_integers
|
90
|
-
( p_pls_int PLS_INTEGER, p_bin_int BINARY_INTEGER, x_pls_int OUT PLS_INTEGER, x_bin_int OUT BINARY_INTEGER )
|
91
|
-
IS
|
92
|
-
BEGIN
|
93
|
-
x_pls_int := p_pls_int;
|
94
|
-
x_bin_int := p_bin_int;
|
95
|
-
END;
|
96
|
-
SQL
|
97
78
|
end
|
98
79
|
|
99
80
|
after(:all) do
|
100
81
|
plsql.execute "DROP FUNCTION test_sum"
|
101
|
-
plsql.execute "DROP FUNCTION test_number_1"
|
102
|
-
plsql.execute "DROP PROCEDURE test_integers"
|
103
82
|
plsql.logoff
|
104
83
|
end
|
105
84
|
|
106
|
-
it "should
|
107
|
-
expect(plsql.test_sum(
|
85
|
+
it "should get #{ora_data_type} variable type mapped to #{class_.to_s}" do
|
86
|
+
expect(plsql.test_sum(num1, num2)).to be_a class_
|
108
87
|
end
|
109
|
-
|
110
|
-
|
111
|
-
expect(plsql.test_sum(123123123123,456456456456)).to eq(579579579579)
|
88
|
+
it "should process input parameters and return correct result" do
|
89
|
+
expect(plsql.test_sum(num1, num2)).to eq(expected)
|
112
90
|
end
|
113
91
|
|
114
|
-
it "should process
|
115
|
-
expect(plsql.test_sum(
|
116
|
-
end
|
92
|
+
it "should process nil parameter as NULL" do
|
93
|
+
expect(plsql.test_sum(num1, nil)).to be_nil
|
94
|
+
end unless mandatory
|
117
95
|
|
118
|
-
|
119
|
-
|
96
|
+
end
|
97
|
+
|
98
|
+
@big_number = ('1234567890' * 3).to_i
|
99
|
+
[
|
100
|
+
{:ora_data_type => 'INTEGER', :class => Bignum, :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 => Fixnum, :num1 => 123456789, :num2 => 123456789, :expected => 246913578 },
|
103
|
+
{:ora_data_type => 'BINARY_INTEGER',:class => Fixnum, :num1 => 123456789, :num2 => 123456789, :expected => 246913578 },
|
104
|
+
{:ora_data_type => 'SIMPLE_INTEGER',:class => Fixnum, :num1 => 123456789, :num2 => 123456789, :expected => 246913578, :mandatory => true },
|
105
|
+
{:ora_data_type => 'NATURAL', :class => Fixnum, :num1 => 123456789, :num2 => 123456789, :expected => 246913578 },
|
106
|
+
{:ora_data_type => 'NATURALN', :class => Fixnum, :num1 => 123456789, :num2 => 123456789, :expected => 246913578, :mandatory => true },
|
107
|
+
{:ora_data_type => 'POSITIVE', :class => Fixnum, :num1 => 123456789, :num2 => 123456789, :expected => 246913578 },
|
108
|
+
{:ora_data_type => 'POSITIVEN', :class => Fixnum, :num1 => 123456789, :num2 => 123456789, :expected => 246913578, :mandatory => true },
|
109
|
+
{:ora_data_type => 'SIGNTYPE', :class => Fixnum, :num1 => 1, :num2 => -1, :expected => 0 },
|
110
|
+
].each do |row|
|
111
|
+
ora_data_type, class_, num1, num2, expected, mandatory = row.values
|
112
|
+
describe ora_data_type do
|
113
|
+
include_examples "Function with numeric", ora_data_type, class_, num1, num2, expected, mandatory
|
120
114
|
end
|
115
|
+
end
|
121
116
|
|
122
|
-
|
123
|
-
|
117
|
+
describe "Boolean to NUMBER conversion" do
|
118
|
+
before(:all) do
|
119
|
+
plsql.connect! CONNECTION_PARAMS
|
120
|
+
plsql.execute <<-SQL
|
121
|
+
CREATE OR REPLACE FUNCTION test_num ( p_num NUMBER) RETURN NUMBER
|
122
|
+
IS
|
123
|
+
BEGIN
|
124
|
+
RETURN p_num;
|
125
|
+
END test_num;
|
126
|
+
SQL
|
124
127
|
end
|
125
128
|
|
129
|
+
after(:all) do
|
130
|
+
plsql.execute "DROP FUNCTION test_num"
|
131
|
+
plsql.logoff
|
132
|
+
end
|
126
133
|
it "should convert true value to 1 for NUMBER parameter" do
|
127
|
-
expect(plsql.
|
134
|
+
expect(plsql.test_num(true)).to eq(1)
|
128
135
|
end
|
129
136
|
|
130
137
|
it "should convert false value to 0 for NUMBER parameter" do
|
131
|
-
expect(plsql.
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should process binary integer parameters" do
|
135
|
-
expect(plsql.test_integers(123, 456)).to eq({:x_pls_int => 123, :x_bin_int => 456})
|
138
|
+
expect(plsql.test_num(false)).to eq(0)
|
136
139
|
end
|
137
140
|
end
|
138
141
|
|
@@ -232,6 +235,53 @@ describe "Parameter type mapping /" do
|
|
232
235
|
|
233
236
|
end
|
234
237
|
|
238
|
+
describe "Function or procedure with XMLType parameters" do
|
239
|
+
before(:all) do
|
240
|
+
plsql.connect! CONNECTION_PARAMS
|
241
|
+
plsql.execute <<-SQL
|
242
|
+
CREATE OR REPLACE FUNCTION test_xmltype
|
243
|
+
( p_xml XMLTYPE )
|
244
|
+
RETURN XMLTYPE
|
245
|
+
IS
|
246
|
+
BEGIN
|
247
|
+
RETURN p_xml;
|
248
|
+
END test_xmltype;
|
249
|
+
SQL
|
250
|
+
plsql.execute <<-SQL
|
251
|
+
CREATE OR REPLACE PROCEDURE test_xmltype2
|
252
|
+
( p_xml XMLTYPE, po_xml OUT XMLTYPE )
|
253
|
+
IS
|
254
|
+
BEGIN
|
255
|
+
po_xml := p_xml;
|
256
|
+
END test_xmltype2;
|
257
|
+
SQL
|
258
|
+
end
|
259
|
+
|
260
|
+
after(:all) do
|
261
|
+
plsql.execute "DROP FUNCTION test_xmltype"
|
262
|
+
plsql.execute "DROP PROCEDURE test_xmltype2"
|
263
|
+
plsql.logoff
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should process XMLType parameters" do
|
267
|
+
xml = '<DUMMY>value</DUMMY>'
|
268
|
+
result = plsql.test_xmltype(xml)
|
269
|
+
expect(result).to eq('<DUMMY>value</DUMMY>')
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should work when passing a NULL value" do
|
273
|
+
result = plsql.test_xmltype(nil)
|
274
|
+
expect(result).to be_nil
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should assign input parameter to putput parameter" do
|
278
|
+
xml = '<DUMMY>value</DUMMY>'
|
279
|
+
result = plsql.test_xmltype2(xml)
|
280
|
+
expect(result[:po_xml]).to eq('<DUMMY>value</DUMMY>')
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
|
235
285
|
describe "Procedure with output parameters" do
|
236
286
|
before(:all) do
|
237
287
|
plsql.connect! CONNECTION_PARAMS
|
@@ -609,7 +659,7 @@ describe "Parameter type mapping /" do
|
|
609
659
|
CREATE TABLE test_employees (
|
610
660
|
employee_id NUMBER(15),
|
611
661
|
first_name VARCHAR2(50),
|
612
|
-
last_name
|
662
|
+
last_name VARCHAR(50),
|
613
663
|
hire_date DATE
|
614
664
|
)
|
615
665
|
SQL
|
@@ -626,10 +676,15 @@ describe "Parameter type mapping /" do
|
|
626
676
|
TYPE t_employee IS RECORD(
|
627
677
|
employee_id NUMBER(15),
|
628
678
|
first_name VARCHAR2(50),
|
629
|
-
last_name
|
679
|
+
last_name VARCHAR(50),
|
630
680
|
hire_date DATE
|
631
681
|
);
|
632
682
|
|
683
|
+
TYPE t_candidate IS RECORD(
|
684
|
+
candidate_id NUMBER(5),
|
685
|
+
is_approved BOOLEAN
|
686
|
+
);
|
687
|
+
|
633
688
|
TYPE table_of_records IS TABLE OF t_employee;
|
634
689
|
|
635
690
|
FUNCTION test_full_name(p_employee t_employee)
|
@@ -637,6 +692,14 @@ describe "Parameter type mapping /" do
|
|
637
692
|
|
638
693
|
FUNCTION test_empty_records
|
639
694
|
RETURN table_of_records;
|
695
|
+
|
696
|
+
FUNCTION is_approved(p_candidate t_candidate)
|
697
|
+
RETURN BOOLEAN;
|
698
|
+
|
699
|
+
FUNCTION f_set_candidate_status(p_candidate t_candidate, p_status boolean)
|
700
|
+
RETURN t_candidate;
|
701
|
+
|
702
|
+
PROCEDURE p_set_candidate_status(p_candidate t_candidate, p_status boolean, p_result OUT t_candidate);
|
640
703
|
END;
|
641
704
|
SQL
|
642
705
|
plsql.execute <<-SQL
|
@@ -667,6 +730,29 @@ describe "Parameter type mapping /" do
|
|
667
730
|
CLOSE employees_cur;
|
668
731
|
RETURN employees_tab;
|
669
732
|
END;
|
733
|
+
|
734
|
+
FUNCTION is_approved(p_candidate t_candidate)
|
735
|
+
RETURN BOOLEAN
|
736
|
+
IS
|
737
|
+
BEGIN
|
738
|
+
RETURN p_candidate.is_approved;
|
739
|
+
END;
|
740
|
+
|
741
|
+
FUNCTION f_set_candidate_status(p_candidate t_candidate, p_status boolean)
|
742
|
+
RETURN t_candidate
|
743
|
+
IS
|
744
|
+
result t_candidate := p_candidate;
|
745
|
+
BEGIN
|
746
|
+
result.is_approved := p_status;
|
747
|
+
return result;
|
748
|
+
END;
|
749
|
+
|
750
|
+
PROCEDURE p_set_candidate_status(p_candidate t_candidate, p_status boolean, p_result OUT t_candidate)
|
751
|
+
IS
|
752
|
+
BEGIN
|
753
|
+
p_result := p_candidate;
|
754
|
+
p_result.is_approved := p_status;
|
755
|
+
END;
|
670
756
|
END;
|
671
757
|
SQL
|
672
758
|
plsql.execute <<-SQL
|
@@ -750,6 +836,26 @@ describe "Parameter type mapping /" do
|
|
750
836
|
expect(plsql.test_record.test_full_name(@p_employee)).to eq('First Last')
|
751
837
|
end
|
752
838
|
|
839
|
+
context "functions with record parameters having boolean attributes" do
|
840
|
+
def new_candidate(status)
|
841
|
+
{:candidate_id => 1, :is_approved => status}
|
842
|
+
end
|
843
|
+
|
844
|
+
[true, false, nil].each do |status|
|
845
|
+
it "should execute function with record having boolean attribute (#{status})" do
|
846
|
+
expect(plsql.test_record.is_approved(new_candidate(status))).to eq status
|
847
|
+
end
|
848
|
+
|
849
|
+
it "procedure should return record with boolean attribute as output parameter (#{status})" do
|
850
|
+
expect(plsql.test_record.p_set_candidate_status(new_candidate(nil), status)[:p_result]).to eq new_candidate(status)
|
851
|
+
end
|
852
|
+
|
853
|
+
it "function should return record with boolean attribute (#{status})" do
|
854
|
+
expect(plsql.test_record.f_set_candidate_status(new_candidate(nil), status)).to eq new_candidate(status)
|
855
|
+
end
|
856
|
+
end
|
857
|
+
end
|
858
|
+
|
753
859
|
end
|
754
860
|
|
755
861
|
describe "Function with boolean parameters" do
|
@@ -831,7 +937,7 @@ describe "Parameter type mapping /" do
|
|
831
937
|
CREATE OR REPLACE TYPE t_employee AS OBJECT (
|
832
938
|
employee_id NUMBER(15),
|
833
939
|
first_name VARCHAR2(50),
|
834
|
-
last_name
|
940
|
+
last_name VARCHAR(50),
|
835
941
|
hire_date DATE,
|
836
942
|
address t_address,
|
837
943
|
phones t_phones
|
@@ -991,7 +1097,7 @@ describe "Parameter type mapping /" do
|
|
991
1097
|
TYPE t_employee IS RECORD(
|
992
1098
|
employee_id NUMBER(15),
|
993
1099
|
first_name VARCHAR2(50),
|
994
|
-
last_name
|
1100
|
+
last_name VARCHAR(50),
|
995
1101
|
hire_date DATE
|
996
1102
|
);
|
997
1103
|
TYPE t_employees IS TABLE OF t_employee;
|
@@ -1001,7 +1107,7 @@ describe "Parameter type mapping /" do
|
|
1001
1107
|
TYPE t_employee2 IS RECORD(
|
1002
1108
|
employee_id NUMBER(15),
|
1003
1109
|
first_name VARCHAR2(50),
|
1004
|
-
last_name
|
1110
|
+
last_name VARCHAR(50),
|
1005
1111
|
hire_date DATE,
|
1006
1112
|
numbers t_numbers
|
1007
1113
|
);
|
@@ -1238,7 +1344,7 @@ describe "Parameter type mapping /" do
|
|
1238
1344
|
CREATE TABLE test_employees (
|
1239
1345
|
employee_id NUMBER(15),
|
1240
1346
|
first_name VARCHAR2(50),
|
1241
|
-
last_name
|
1347
|
+
last_name VARCHAR(50),
|
1242
1348
|
hire_date DATE
|
1243
1349
|
)
|
1244
1350
|
SQL
|
@@ -1256,7 +1362,7 @@ describe "Parameter type mapping /" do
|
|
1256
1362
|
TYPE t_employee IS RECORD(
|
1257
1363
|
employee_id NUMBER(15),
|
1258
1364
|
first_name VARCHAR2(50),
|
1259
|
-
last_name
|
1365
|
+
last_name VARCHAR(50),
|
1260
1366
|
hire_date DATE
|
1261
1367
|
);
|
1262
1368
|
TYPE t_employees IS TABLE OF t_employee
|
@@ -1686,7 +1792,7 @@ describe "Parameter type mapping /" do
|
|
1686
1792
|
CREATE TABLE test_employees (
|
1687
1793
|
employee_id NUMBER(15),
|
1688
1794
|
first_name VARCHAR2(50),
|
1689
|
-
last_name
|
1795
|
+
last_name VARCHAR(50),
|
1690
1796
|
hire_date DATE
|
1691
1797
|
)
|
1692
1798
|
SQL
|
@@ -1766,7 +1872,7 @@ describe "Parameter type mapping /" do
|
|
1766
1872
|
expect(plsql.test_cursor do |cursor|
|
1767
1873
|
cursor2 = cursor
|
1768
1874
|
end).to be_nil
|
1769
|
-
expect { cursor2.fetch }.to raise_error
|
1875
|
+
expect { cursor2.fetch }.to raise_error(/Cursor was already closed|Closed Statement/)
|
1770
1876
|
end
|
1771
1877
|
|
1772
1878
|
it "should not raise error if cursor is closed inside block" do
|
@@ -2046,3 +2152,156 @@ describe "SYS.STANDARD procedures /" do
|
|
2046
2152
|
end
|
2047
2153
|
|
2048
2154
|
end
|
2155
|
+
|
2156
|
+
describe "PLS_INTEGER/SIMPLE_INTEGER should be nullable" do
|
2157
|
+
|
2158
|
+
before(:all) do
|
2159
|
+
plsql.connect! CONNECTION_PARAMS
|
2160
|
+
plsql.execute <<-SQL
|
2161
|
+
CREATE OR REPLACE FUNCTION test_pls_f ( p_num PLS_INTEGER ) RETURN PLS_INTEGER IS
|
2162
|
+
BEGIN
|
2163
|
+
RETURN p_num;
|
2164
|
+
END;
|
2165
|
+
SQL
|
2166
|
+
plsql.execute <<-SQL
|
2167
|
+
CREATE OR REPLACE FUNCTION test_bin_f ( p_num BINARY_INTEGER ) RETURN BINARY_INTEGER IS
|
2168
|
+
BEGIN
|
2169
|
+
RETURN p_num;
|
2170
|
+
END;
|
2171
|
+
SQL
|
2172
|
+
plsql.execute <<-SQL
|
2173
|
+
CREATE OR REPLACE FUNCTION test_int_f ( p_num INTEGER ) RETURN INTEGER IS
|
2174
|
+
BEGIN
|
2175
|
+
RETURN p_num;
|
2176
|
+
END;
|
2177
|
+
SQL
|
2178
|
+
plsql.execute <<-SQL
|
2179
|
+
CREATE OR REPLACE PROCEDURE test_pls_p ( p_num IN OUT PLS_INTEGER ) IS
|
2180
|
+
BEGIN
|
2181
|
+
NULL;
|
2182
|
+
END;
|
2183
|
+
SQL
|
2184
|
+
plsql.execute <<-SQL
|
2185
|
+
CREATE OR REPLACE PROCEDURE test_bin_p ( p_num IN OUT BINARY_INTEGER ) IS
|
2186
|
+
BEGIN
|
2187
|
+
NULL;
|
2188
|
+
END;
|
2189
|
+
SQL
|
2190
|
+
plsql.execute <<-SQL
|
2191
|
+
CREATE OR REPLACE PROCEDURE test_int_p ( p_num IN OUT INTEGER ) IS
|
2192
|
+
BEGIN
|
2193
|
+
NULL;
|
2194
|
+
END;
|
2195
|
+
SQL
|
2196
|
+
plsql.execute <<-SQL
|
2197
|
+
CREATE OR REPLACE PROCEDURE test_flt_p ( p_num IN OUT BINARY_FLOAT ) IS
|
2198
|
+
BEGIN
|
2199
|
+
NULL;
|
2200
|
+
END;
|
2201
|
+
SQL
|
2202
|
+
plsql.execute <<-SQL
|
2203
|
+
CREATE OR REPLACE PROCEDURE test_dbl_p ( p_num IN OUT BINARY_DOUBLE ) IS
|
2204
|
+
BEGIN
|
2205
|
+
NULL;
|
2206
|
+
END;
|
2207
|
+
SQL
|
2208
|
+
end
|
2209
|
+
|
2210
|
+
after(:all) do
|
2211
|
+
plsql.execute "DROP FUNCTION test_pls_f"
|
2212
|
+
plsql.execute "DROP FUNCTION test_bin_f"
|
2213
|
+
plsql.execute "DROP FUNCTION test_int_f"
|
2214
|
+
plsql.execute "DROP PROCEDURE test_pls_p"
|
2215
|
+
plsql.execute "DROP PROCEDURE test_int_p"
|
2216
|
+
plsql.execute "DROP PROCEDURE test_flt_p"
|
2217
|
+
plsql.execute "DROP PROCEDURE test_dbl_p"
|
2218
|
+
plsql.logoff
|
2219
|
+
end
|
2220
|
+
|
2221
|
+
it 'should return null for a function call with NULL PLS_INTEGER param' do
|
2222
|
+
expect(plsql.test_pls_f(nil)).to be_nil
|
2223
|
+
end
|
2224
|
+
|
2225
|
+
it 'should return null for a function call with NULL BINARY_INTEGER param' do
|
2226
|
+
expect(plsql.test_bin_f(nil)).to be_nil
|
2227
|
+
end
|
2228
|
+
|
2229
|
+
it 'should return null for a function call with NULL INTEGER param' do
|
2230
|
+
expect(plsql.test_int_f(nil)).to be_nil
|
2231
|
+
end
|
2232
|
+
|
2233
|
+
it 'should return null for a procedure call with NULL PLS_INTEGER param' do
|
2234
|
+
expect(plsql.test_pls_p(nil)[:p_num]).to be_nil
|
2235
|
+
end
|
2236
|
+
|
2237
|
+
it 'should return null for a procedure call with NULL BINARY_INTEGER param' do
|
2238
|
+
expect(plsql.test_bin_p(nil)[:p_num]).to be_nil
|
2239
|
+
end
|
2240
|
+
|
2241
|
+
it 'should return null for a procedure call with NULL INTEGER param' do
|
2242
|
+
expect(plsql.test_int_p(nil)[:p_num]).to be_nil
|
2243
|
+
end
|
2244
|
+
|
2245
|
+
it 'should return null for a procedure call with NULL BINARY_FLOAT param' do
|
2246
|
+
expect(plsql.test_flt_p(nil)[:p_num]).to be_nil
|
2247
|
+
end
|
2248
|
+
|
2249
|
+
it 'should return null for a procedure call with NULL BINARY_DOUBLE param' do
|
2250
|
+
expect(plsql.test_dbl_p(nil)[:p_num]).to be_nil
|
2251
|
+
end
|
2252
|
+
|
2253
|
+
end
|
2254
|
+
|
2255
|
+
describe '#get_argument_metadata' do
|
2256
|
+
before(:all) do
|
2257
|
+
plsql.connect! CONNECTION_PARAMS
|
2258
|
+
end
|
2259
|
+
|
2260
|
+
after(:all) do
|
2261
|
+
plsql.logoff
|
2262
|
+
end
|
2263
|
+
|
2264
|
+
before(:each) do
|
2265
|
+
plsql.execute <<-SQL
|
2266
|
+
CREATE OR REPLACE FUNCTION magic_number(p_num INTEGER #{defaulted_clause})
|
2267
|
+
RETURN INTEGER
|
2268
|
+
IS
|
2269
|
+
BEGIN
|
2270
|
+
RETURN p_num * 2;
|
2271
|
+
END magic_number;
|
2272
|
+
SQL
|
2273
|
+
end
|
2274
|
+
|
2275
|
+
after(:each) do
|
2276
|
+
plsql.execute "DROP FUNCTION magic_number"
|
2277
|
+
end
|
2278
|
+
|
2279
|
+
context 'on procedure with defaulted field' do
|
2280
|
+
let(:defaulted_clause) { 'DEFAULT 21' }
|
2281
|
+
|
2282
|
+
it 'field\'s metadata attribute "defaulted" is Y' do
|
2283
|
+
procedure = PLSQL::Procedure.find(plsql, :magic_number)
|
2284
|
+
expect(procedure.arguments[0][:p_num][:defaulted]).to eq('Y')
|
2285
|
+
end
|
2286
|
+
end
|
2287
|
+
|
2288
|
+
context 'procedure without defaulted field' do
|
2289
|
+
let(:defaulted_clause) { '' }
|
2290
|
+
|
2291
|
+
it 'field\'s metadata attribute "defaulted" is N' do
|
2292
|
+
procedure = PLSQL::Procedure.find(plsql, :magic_number)
|
2293
|
+
expect(procedure.arguments[0][:p_num][:defaulted]).to eq('N')
|
2294
|
+
end
|
2295
|
+
end
|
2296
|
+
|
2297
|
+
context 'oracle <= 10g without defaulted functionality' do
|
2298
|
+
let(:defaulted_clause) { '' }
|
2299
|
+
|
2300
|
+
it 'field\'s metadata attribute "defaulted" is nil' do
|
2301
|
+
allow(plsql.connection).to receive(:database_version).and_return([10, 2, 0, 2])
|
2302
|
+
|
2303
|
+
procedure = PLSQL::Procedure.find(plsql, :magic_number)
|
2304
|
+
expect(procedure.arguments[0][:p_num][:defaulted]).to be_nil
|
2305
|
+
end
|
2306
|
+
end
|
2307
|
+
end
|