ruby-plsql 0.4.1 → 0.4.2
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.
- data/History.txt +18 -0
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/lib/plsql/connection.rb +60 -10
- data/lib/plsql/jdbc_connection.rb +14 -2
- data/lib/plsql/oci_connection.rb +11 -1
- data/lib/plsql/procedure.rb +120 -25
- data/lib/plsql/procedure_call.rb +349 -165
- data/lib/plsql/schema.rb +59 -8
- data/lib/plsql/sql_statements.rb +21 -0
- data/lib/plsql/table.rb +10 -4
- data/lib/plsql/type.rb +194 -6
- data/lib/plsql/variable.rb +3 -3
- data/spec/plsql/connection_spec.rb +76 -1
- data/spec/plsql/procedure_spec.rb +336 -12
- data/spec/plsql/schema_spec.rb +80 -9
- data/spec/plsql/table_spec.rb +48 -28
- data/spec/plsql/type_spec.rb +173 -2
- data/spec/plsql/variable_spec.rb +21 -0
- data/spec/plsql/view_spec.rb +16 -11
- data/spec/spec_helper.rb +19 -5
- metadata +22 -2
@@ -344,13 +344,12 @@ describe "Parameter type mapping /" do
|
|
344
344
|
end
|
345
345
|
|
346
346
|
it "should raise exception if procedure cannot be found based on number of arguments" do
|
347
|
-
lambda { plsql.test_package2.test_procedure() }.should raise_error(
|
347
|
+
lambda { plsql.test_package2.test_procedure() }.should raise_error(/wrong number or types of arguments/i)
|
348
348
|
end
|
349
349
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
# end
|
350
|
+
it "should find procedure based on types of arguments" do
|
351
|
+
plsql.test_package2.test_procedure(111, nil).should == {:p_result => '111'}
|
352
|
+
end
|
354
353
|
|
355
354
|
it "should find procedure based on names of named arguments" do
|
356
355
|
plsql.test_package2.test_procedure(:p_number => 111, :p_result => nil).should == {:p_result => '111'}
|
@@ -559,6 +558,28 @@ describe "Parameter type mapping /" do
|
|
559
558
|
RETURN p_employee.first_name || ' ' || p_employee.last_name;
|
560
559
|
END test_full_name;
|
561
560
|
SQL
|
561
|
+
plsql.execute <<-SQL
|
562
|
+
CREATE OR REPLACE PACKAGE test_record IS
|
563
|
+
TYPE t_employee IS RECORD(
|
564
|
+
employee_id NUMBER(15),
|
565
|
+
first_name VARCHAR2(50),
|
566
|
+
last_name VARCHAR2(50),
|
567
|
+
hire_date DATE
|
568
|
+
);
|
569
|
+
FUNCTION test_full_name (p_employee t_employee)
|
570
|
+
RETURN VARCHAR2;
|
571
|
+
END;
|
572
|
+
SQL
|
573
|
+
plsql.execute <<-SQL
|
574
|
+
CREATE OR REPLACE PACKAGE BODY test_record IS
|
575
|
+
FUNCTION test_full_name (p_employee t_employee)
|
576
|
+
RETURN VARCHAR2
|
577
|
+
IS
|
578
|
+
BEGIN
|
579
|
+
RETURN p_employee.first_name || ' ' || p_employee.last_name;
|
580
|
+
END;
|
581
|
+
END;
|
582
|
+
SQL
|
562
583
|
plsql.execute <<-SQL
|
563
584
|
CREATE OR REPLACE FUNCTION test_employee_record (p_employee test_employees%ROWTYPE)
|
564
585
|
RETURN test_employees%ROWTYPE
|
@@ -568,7 +589,7 @@ describe "Parameter type mapping /" do
|
|
568
589
|
END test_employee_record;
|
569
590
|
SQL
|
570
591
|
plsql.execute <<-SQL
|
571
|
-
CREATE OR REPLACE FUNCTION test_employee_record2 (p_employee test_employees%ROWTYPE, x_employee OUT test_employees%ROWTYPE)
|
592
|
+
CREATE OR REPLACE FUNCTION test_employee_record2 (p_employee test_employees%ROWTYPE, x_employee IN OUT test_employees%ROWTYPE)
|
572
593
|
RETURN test_employees%ROWTYPE
|
573
594
|
IS
|
574
595
|
BEGIN
|
@@ -595,6 +616,7 @@ describe "Parameter type mapping /" do
|
|
595
616
|
|
596
617
|
after(:all) do
|
597
618
|
plsql.execute "DROP FUNCTION test_full_name"
|
619
|
+
plsql.execute "DROP PACKAGE test_record"
|
598
620
|
plsql.execute "DROP FUNCTION test_employee_record"
|
599
621
|
plsql.execute "DROP FUNCTION test_employee_record2"
|
600
622
|
plsql.execute "DROP TABLE test_employees"
|
@@ -627,7 +649,11 @@ describe "Parameter type mapping /" do
|
|
627
649
|
end
|
628
650
|
|
629
651
|
it "should return record return value and output record parameter value" do
|
630
|
-
plsql.test_employee_record2(@p_employee,
|
652
|
+
plsql.test_employee_record2(@p_employee, @p_employee2).should == [@p_employee, {:x_employee => @p_employee}]
|
653
|
+
end
|
654
|
+
|
655
|
+
it "should execute package function with parameter with record type defined in package" do
|
656
|
+
plsql.test_record.test_full_name(@p_employee).should == 'First Last'
|
631
657
|
end
|
632
658
|
|
633
659
|
end
|
@@ -852,12 +878,36 @@ describe "Parameter type mapping /" do
|
|
852
878
|
END;
|
853
879
|
SQL
|
854
880
|
|
855
|
-
#
|
881
|
+
# Type definition inside package
|
856
882
|
plsql.execute <<-SQL
|
857
883
|
CREATE OR REPLACE PACKAGE test_collections IS
|
858
884
|
TYPE t_numbers IS TABLE OF NUMBER(15);
|
859
885
|
FUNCTION test_sum (p_numbers IN t_numbers)
|
860
886
|
RETURN NUMBER;
|
887
|
+
FUNCTION test_numbers (p_numbers IN t_numbers, x_numbers OUT t_numbers)
|
888
|
+
RETURN t_numbers;
|
889
|
+
TYPE t_employee IS RECORD(
|
890
|
+
employee_id NUMBER(15),
|
891
|
+
first_name VARCHAR2(50),
|
892
|
+
last_name VARCHAR2(50),
|
893
|
+
hire_date DATE
|
894
|
+
);
|
895
|
+
TYPE t_employees IS TABLE OF t_employee;
|
896
|
+
FUNCTION test_employees (p_employees IN OUT t_employees)
|
897
|
+
RETURN t_employees;
|
898
|
+
-- these types with tables in lower level are not yet supported
|
899
|
+
TYPE t_employee2 IS RECORD(
|
900
|
+
employee_id NUMBER(15),
|
901
|
+
first_name VARCHAR2(50),
|
902
|
+
last_name VARCHAR2(50),
|
903
|
+
hire_date DATE,
|
904
|
+
numbers t_numbers
|
905
|
+
);
|
906
|
+
FUNCTION test_employee2 (p_employee IN OUT t_employee2)
|
907
|
+
RETURN t_employee2;
|
908
|
+
TYPE t_employees2 IS TABLE OF t_employee2;
|
909
|
+
FUNCTION test_employees2 (p_employees IN OUT t_employees2)
|
910
|
+
RETURN t_employees2;
|
861
911
|
END;
|
862
912
|
SQL
|
863
913
|
plsql.execute <<-SQL
|
@@ -878,8 +928,41 @@ describe "Parameter type mapping /" do
|
|
878
928
|
RETURN NULL;
|
879
929
|
END IF;
|
880
930
|
END;
|
931
|
+
FUNCTION test_numbers (p_numbers IN t_numbers, x_numbers OUT t_numbers)
|
932
|
+
RETURN t_numbers
|
933
|
+
IS
|
934
|
+
BEGIN
|
935
|
+
x_numbers := p_numbers;
|
936
|
+
RETURN p_numbers;
|
937
|
+
END;
|
938
|
+
FUNCTION test_employees (p_employees IN OUT t_employees)
|
939
|
+
RETURN t_employees
|
940
|
+
IS
|
941
|
+
BEGIN
|
942
|
+
RETURN p_employees;
|
943
|
+
END;
|
944
|
+
FUNCTION test_employee2 (p_employee IN OUT t_employee2)
|
945
|
+
RETURN t_employee2
|
946
|
+
IS
|
947
|
+
BEGIN
|
948
|
+
RETURN p_employee;
|
949
|
+
END;
|
950
|
+
FUNCTION test_employees2 (p_employees IN OUT t_employees2)
|
951
|
+
RETURN t_employees2
|
952
|
+
IS
|
953
|
+
BEGIN
|
954
|
+
RETURN p_employees;
|
955
|
+
END;
|
881
956
|
END;
|
882
957
|
SQL
|
958
|
+
@employees = (1..10).map do |i|
|
959
|
+
{
|
960
|
+
:employee_id => i,
|
961
|
+
:first_name => "First #{i}",
|
962
|
+
:last_name => "Last #{i}",
|
963
|
+
:hire_date => Time.local(2000,01,i),
|
964
|
+
}
|
965
|
+
end
|
883
966
|
|
884
967
|
# Array of objects
|
885
968
|
plsql.execute <<-SQL
|
@@ -912,6 +995,7 @@ describe "Parameter type mapping /" do
|
|
912
995
|
plsql.execute "DROP TYPE t_strings"
|
913
996
|
plsql.execute "DROP TYPE t_phones"
|
914
997
|
plsql.execute "DROP TYPE t_phone"
|
998
|
+
plsql.connection.drop_session_ruby_temporary_tables
|
915
999
|
end
|
916
1000
|
|
917
1001
|
it "should find existing function" do
|
@@ -931,10 +1015,32 @@ describe "Parameter type mapping /" do
|
|
931
1015
|
plsql.test_copy_strings(strings).should == [strings, {:x_strings => strings}]
|
932
1016
|
end
|
933
1017
|
|
934
|
-
it "should
|
935
|
-
|
936
|
-
|
937
|
-
|
1018
|
+
it "should execute function with table of numbers type (defined inside package) parameter" do
|
1019
|
+
plsql.test_collections.test_sum([1,2,3,4]).should == 10
|
1020
|
+
end
|
1021
|
+
|
1022
|
+
it "should return table of numbers type (defined inside package)" do
|
1023
|
+
plsql.test_collections.test_numbers([1,2,3,4]).should == [[1,2,3,4], {:x_numbers => [1,2,3,4]}]
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
it "should clear temporary tables after executing function with table of numbers type (defined inside package) parameter" do
|
1027
|
+
plsql.test_collections.test_numbers([1,2,3,4]).should == [[1,2,3,4], {:x_numbers => [1,2,3,4]}]
|
1028
|
+
# after first call temporary tables should be cleared
|
1029
|
+
plsql.test_collections.test_numbers([1,2,3,4]).should == [[1,2,3,4], {:x_numbers => [1,2,3,4]}]
|
1030
|
+
end
|
1031
|
+
|
1032
|
+
it "should clear temporary tables when autocommit with table of numbers type (defined inside package) parameter" do
|
1033
|
+
old_autocommit = plsql.connection.autocommit?
|
1034
|
+
plsql.connection.autocommit = true
|
1035
|
+
numbers_array = (1..400).to_a
|
1036
|
+
plsql.test_collections.test_numbers(numbers_array).should == [numbers_array, {:x_numbers => numbers_array}]
|
1037
|
+
# after first call temporary tables should be cleared
|
1038
|
+
plsql.test_collections.test_numbers(numbers_array).should == [numbers_array, {:x_numbers => numbers_array}]
|
1039
|
+
plsql.connection.autocommit = old_autocommit
|
1040
|
+
end
|
1041
|
+
|
1042
|
+
it "should execute function with table of records type (defined inside package) parameter" do
|
1043
|
+
plsql.test_collections.test_employees(@employees).should == [@employees, {:p_employees => @employees}]
|
938
1044
|
end
|
939
1045
|
|
940
1046
|
it "should execute function with object array and return object array output parameter" do
|
@@ -947,8 +1053,165 @@ describe "Parameter type mapping /" do
|
|
947
1053
|
plsql.test_copy_objects(phones).should == [phones, {:x_phones => phones}]
|
948
1054
|
end
|
949
1055
|
|
1056
|
+
it "should raise error with record parameter that has table as element" do
|
1057
|
+
lambda {
|
1058
|
+
plsql.test_collections.test_employee2(@employees[0]).should == [@employees[0], {:p_employee => @employees[0]}]
|
1059
|
+
}.should raise_error(ArgumentError, /TEST_COLLECTIONS\.T_NUMBERS definition inside package is not supported/)
|
1060
|
+
end
|
1061
|
+
|
1062
|
+
it "should raise error with table of records parameter when record has table as element" do
|
1063
|
+
lambda {
|
1064
|
+
plsql.test_collections.test_employees2(@employees).should == [@employees, {:p_employees => @employees}]
|
1065
|
+
}.should raise_error(ArgumentError, /TEST_COLLECTIONS\.T_NUMBERS definition inside package is not supported/)
|
1066
|
+
end
|
1067
|
+
|
950
1068
|
end
|
951
1069
|
|
1070
|
+
describe "Function with table indexed by bynary integer parameter" do
|
1071
|
+
|
1072
|
+
before(:all) do
|
1073
|
+
plsql.execute <<-SQL
|
1074
|
+
CREATE TABLE test_employees (
|
1075
|
+
employee_id NUMBER(15),
|
1076
|
+
first_name VARCHAR2(50),
|
1077
|
+
last_name VARCHAR2(50),
|
1078
|
+
hire_date DATE
|
1079
|
+
)
|
1080
|
+
SQL
|
1081
|
+
# Type definition inside package
|
1082
|
+
plsql.execute <<-SQL
|
1083
|
+
CREATE OR REPLACE PACKAGE test_collections IS
|
1084
|
+
TYPE t_numbers IS TABLE OF NUMBER(15)
|
1085
|
+
INDEX BY BINARY_INTEGER;
|
1086
|
+
FUNCTION test_sum (p_numbers IN t_numbers)
|
1087
|
+
RETURN NUMBER;
|
1088
|
+
FUNCTION test_numbers (p_numbers IN t_numbers, x_numbers OUT t_numbers)
|
1089
|
+
RETURN t_numbers;
|
1090
|
+
TYPE t_employee IS RECORD(
|
1091
|
+
employee_id NUMBER(15),
|
1092
|
+
first_name VARCHAR2(50),
|
1093
|
+
last_name VARCHAR2(50),
|
1094
|
+
hire_date DATE
|
1095
|
+
);
|
1096
|
+
TYPE t_employees IS TABLE OF t_employee
|
1097
|
+
INDEX BY BINARY_INTEGER;
|
1098
|
+
FUNCTION test_employees (p_employees IN OUT t_employees)
|
1099
|
+
RETURN t_employees;
|
1100
|
+
PROCEDURE insert_employees(p_employees IN t_employees);
|
1101
|
+
END;
|
1102
|
+
SQL
|
1103
|
+
plsql.execute <<-SQL
|
1104
|
+
CREATE OR REPLACE PACKAGE BODY test_collections IS
|
1105
|
+
FUNCTION test_sum (p_numbers IN t_numbers)
|
1106
|
+
RETURN NUMBER
|
1107
|
+
IS
|
1108
|
+
l_sum NUMBER(15) := 0;
|
1109
|
+
i BINARY_INTEGER;
|
1110
|
+
BEGIN
|
1111
|
+
IF p_numbers.COUNT > 0 THEN
|
1112
|
+
i := p_numbers.FIRST;
|
1113
|
+
LOOP
|
1114
|
+
EXIT WHEN i IS NULL;
|
1115
|
+
l_sum := l_sum + p_numbers(i);
|
1116
|
+
i := p_numbers.NEXT(i);
|
1117
|
+
END LOOP;
|
1118
|
+
RETURN l_sum;
|
1119
|
+
ELSE
|
1120
|
+
RETURN NULL;
|
1121
|
+
END IF;
|
1122
|
+
END;
|
1123
|
+
FUNCTION test_numbers (p_numbers IN t_numbers, x_numbers OUT t_numbers)
|
1124
|
+
RETURN t_numbers
|
1125
|
+
IS
|
1126
|
+
BEGIN
|
1127
|
+
x_numbers := p_numbers;
|
1128
|
+
RETURN p_numbers;
|
1129
|
+
END;
|
1130
|
+
FUNCTION test_employees (p_employees IN OUT t_employees)
|
1131
|
+
RETURN t_employees
|
1132
|
+
IS
|
1133
|
+
BEGIN
|
1134
|
+
RETURN p_employees;
|
1135
|
+
END;
|
1136
|
+
PROCEDURE insert_employees(p_employees IN t_employees) IS
|
1137
|
+
BEGIN
|
1138
|
+
FORALL i IN p_employees.FIRST..p_employees.LAST
|
1139
|
+
INSERT INTO test_employees VALUES p_employees(i);
|
1140
|
+
END;
|
1141
|
+
END;
|
1142
|
+
SQL
|
1143
|
+
# test with negative PL/SQL table indexes
|
1144
|
+
@numbers = Hash[*(1..4).map{|i|[-i,i]}.flatten]
|
1145
|
+
# test with reversed PL/SQL table indexes
|
1146
|
+
@employees = Hash[*(1..10).map do |i|
|
1147
|
+
[11-i, {
|
1148
|
+
:employee_id => i,
|
1149
|
+
:first_name => "First #{i}",
|
1150
|
+
:last_name => "Last #{i}",
|
1151
|
+
:hire_date => Time.local(2000,01,i)
|
1152
|
+
}]
|
1153
|
+
end.flatten]
|
1154
|
+
end
|
1155
|
+
|
1156
|
+
after(:all) do
|
1157
|
+
plsql.execute "DROP PACKAGE test_collections"
|
1158
|
+
plsql.execute "DROP TABLE test_employees"
|
1159
|
+
plsql.connection.drop_session_ruby_temporary_tables
|
1160
|
+
end
|
1161
|
+
|
1162
|
+
it "should execute function with index-by table of numbers type (defined inside package) parameter" do
|
1163
|
+
plsql.test_collections.test_sum(@numbers).should == 10
|
1164
|
+
end
|
1165
|
+
|
1166
|
+
it "should return index-by table of numbers type (defined inside package)" do
|
1167
|
+
plsql.test_collections.test_numbers(@numbers).should == [@numbers, {:x_numbers => @numbers}]
|
1168
|
+
end
|
1169
|
+
|
1170
|
+
it "should clear temporary tables when autocommit with index-by table of numbers type (defined inside package) parameter" do
|
1171
|
+
old_autocommit = plsql.connection.autocommit?
|
1172
|
+
plsql.connection.autocommit = true
|
1173
|
+
numbers_hash = Hash[*(1..400).map{|i|[i,i]}.flatten]
|
1174
|
+
plsql.test_collections.test_numbers(numbers_hash).should == [numbers_hash, {:x_numbers => numbers_hash}]
|
1175
|
+
# after first call temporary tables should be cleared
|
1176
|
+
plsql.test_collections.test_numbers(numbers_hash).should == [numbers_hash, {:x_numbers => numbers_hash}]
|
1177
|
+
plsql.connection.autocommit = old_autocommit
|
1178
|
+
end
|
1179
|
+
|
1180
|
+
it "should execute function with index-by table of records type (defined inside package) parameter" do
|
1181
|
+
plsql.test_collections.test_employees(@employees).should == [@employees, {:p_employees => @employees}]
|
1182
|
+
end
|
1183
|
+
|
1184
|
+
it "should create temporary tables in autonomous transaction" do
|
1185
|
+
old_autocommit = plsql.connection.autocommit?
|
1186
|
+
plsql.connection.autocommit = false
|
1187
|
+
plsql.test_employees.insert @employees[1]
|
1188
|
+
# procedure call should not commit initial insert
|
1189
|
+
plsql.test_collections.insert_employees(2=>@employees[2], 3=>@employees[3])
|
1190
|
+
plsql.rollback
|
1191
|
+
plsql.test_employees.all.should be_empty
|
1192
|
+
plsql.connection.autocommit = old_autocommit
|
1193
|
+
end
|
1194
|
+
|
1195
|
+
describe "using Oracle 9.2" do
|
1196
|
+
before(:all) do
|
1197
|
+
# simulate Oracle 9.2 connection
|
1198
|
+
plsql(:oracle_9).connection = get_connection
|
1199
|
+
plsql(:oracle_9).connection.stub!(:database_version).and_return([9, 2])
|
1200
|
+
end
|
1201
|
+
|
1202
|
+
after(:all) do
|
1203
|
+
plsql(:oracle_9).logoff
|
1204
|
+
end
|
1205
|
+
|
1206
|
+
it "should create temporary tables when using Oracle 9.2" do
|
1207
|
+
plsql(:oracle_9).test_collections.test_numbers(@numbers).should == [@numbers, {:x_numbers => @numbers}]
|
1208
|
+
end
|
1209
|
+
|
1210
|
+
end
|
1211
|
+
|
1212
|
+
end
|
1213
|
+
|
1214
|
+
|
952
1215
|
describe "Function with VARRAY parameter" do
|
953
1216
|
|
954
1217
|
before(:all) do
|
@@ -1293,6 +1556,50 @@ describe "Synonyms /" do
|
|
1293
1556
|
|
1294
1557
|
end
|
1295
1558
|
|
1559
|
+
describe "invalid objects" do
|
1560
|
+
before(:all) do
|
1561
|
+
plsql.execute <<-SQL
|
1562
|
+
CREATE OR REPLACE FUNCTION test_invalid_function(p_dummy VARCHAR2) RETURN VARCHAR2 IS
|
1563
|
+
l_dummy invalid_table.invalid_column%TYPE;
|
1564
|
+
BEGIN
|
1565
|
+
RETURN p_dummy;
|
1566
|
+
END;
|
1567
|
+
SQL
|
1568
|
+
plsql.execute <<-SQL
|
1569
|
+
CREATE OR REPLACE PACKAGE test_invalid_package IS
|
1570
|
+
FUNCTION test_invalid_function(p_dummy VARCHAR2) RETURN VARCHAR2;
|
1571
|
+
END;
|
1572
|
+
SQL
|
1573
|
+
plsql.execute <<-SQL
|
1574
|
+
CREATE OR REPLACE PACKAGE BODY test_invalid_package IS
|
1575
|
+
FUNCTION test_invalid_function(p_dummy VARCHAR2) RETURN VARCHAR2 IS
|
1576
|
+
l_dummy1 invalid_table.invalid_column%TYPE;
|
1577
|
+
l_dummy2 invalid_table.invalid_column%TYPE;
|
1578
|
+
BEGIN
|
1579
|
+
RETURN p_dummy;
|
1580
|
+
END;
|
1581
|
+
END;
|
1582
|
+
SQL
|
1583
|
+
end
|
1584
|
+
|
1585
|
+
after(:all) do
|
1586
|
+
plsql.execute "DROP FUNCTION test_invalid_function"
|
1587
|
+
plsql.execute "DROP PACKAGE test_invalid_package"
|
1588
|
+
end
|
1589
|
+
|
1590
|
+
it "should raise error when invalid function is called" do
|
1591
|
+
lambda {
|
1592
|
+
plsql.test_invalid_function('test')
|
1593
|
+
}.should raise_error(ArgumentError, /is not in valid status/)
|
1594
|
+
end
|
1595
|
+
|
1596
|
+
it "should raise error when function from invalid package body is called" do
|
1597
|
+
lambda {
|
1598
|
+
plsql.test_invalid_package.test_invalid_function('test')
|
1599
|
+
}.should raise_error(ArgumentError, /body is not in valid status/)
|
1600
|
+
end
|
1601
|
+
end
|
1602
|
+
|
1296
1603
|
end
|
1297
1604
|
|
1298
1605
|
describe "SYS.STANDARD procedures /" do
|
@@ -1309,4 +1616,21 @@ describe "SYS.STANDARD procedures /" do
|
|
1309
1616
|
plsql.upper('abc').should == 'ABC'
|
1310
1617
|
end
|
1311
1618
|
|
1619
|
+
it "should find function overload based on types of sequential arguments" do
|
1620
|
+
plsql.nvl(1, 2).should == 1
|
1621
|
+
plsql.nvl(nil, 2).should == 2
|
1622
|
+
plsql.nvl(1.1, 2.2).should == 1.1
|
1623
|
+
plsql.nvl(nil, 2.2).should == 2.2
|
1624
|
+
plsql.nvl(BigDecimal('1.1'), BigDecimal('2.2')).should == BigDecimal('1.1')
|
1625
|
+
plsql.nvl(nil, BigDecimal('2.2')).should == BigDecimal('2.2')
|
1626
|
+
plsql.nvl('a', 'b').should == 'a'
|
1627
|
+
plsql.nvl(nil, 'b').should == 'b'
|
1628
|
+
plsql.nvl(Date.new(2010,1,13), Date.new(2010,1,19)).should == Time.local(2010,1,13)
|
1629
|
+
plsql.nvl(nil, Date.new(2010,1,19)).should == Time.local(2010,1,19)
|
1630
|
+
plsql.nvl(Time.local(2010,1,13), Time.local(2010,1,19)).should == Time.local(2010,1,13)
|
1631
|
+
plsql.nvl(nil, Time.local(2010,1,19)).should == Time.local(2010,1,19)
|
1632
|
+
plsql.nvl(true, false).should == true
|
1633
|
+
plsql.nvl(nil, false).should == false
|
1634
|
+
end
|
1635
|
+
|
1312
1636
|
end
|
data/spec/plsql/schema_spec.rb
CHANGED
@@ -50,6 +50,52 @@ describe "Schema connection" do
|
|
50
50
|
|
51
51
|
end
|
52
52
|
|
53
|
+
describe "Connection with connect!" do
|
54
|
+
|
55
|
+
before(:all) do
|
56
|
+
@username, @password = DATABASE_USERS_AND_PASSWORDS[0]
|
57
|
+
@database = DATABASE_NAME
|
58
|
+
@host = DATABASE_HOST
|
59
|
+
@port = DATABASE_PORT
|
60
|
+
end
|
61
|
+
|
62
|
+
after(:each) do
|
63
|
+
plsql.logoff if plsql.connection
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should connect with username, password and database alias" do
|
67
|
+
plsql.connect! @username, @password, @database
|
68
|
+
plsql.connection.should_not be_nil
|
69
|
+
plsql.schema_name.should == @username.upcase
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should connect with username, password, host, port and database name" do
|
73
|
+
plsql.connect! @username, @password, :host => @host, :port => @port, :database => @database
|
74
|
+
plsql.connection.should_not be_nil
|
75
|
+
plsql.schema_name.should == @username.upcase
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should connect with username, password, host, database name and default port" do
|
79
|
+
pending "Non-default port used for test database" unless @port == 1521
|
80
|
+
plsql.connect! @username, @password, :host => @host, :database => @database
|
81
|
+
plsql.connection.should_not be_nil
|
82
|
+
plsql.schema_name.should == @username.upcase
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should not connect with wrong port number" do
|
86
|
+
lambda {
|
87
|
+
plsql.connect! @username, @password, :host => @host, :port => 9999, :database => @database
|
88
|
+
}.should raise_error(/no listener|could not establish the connection/)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should connect with one Hash parameter" do
|
92
|
+
plsql.connect! :username => @username, :password => @password, :database => @database
|
93
|
+
plsql.connection.should_not be_nil
|
94
|
+
plsql.schema_name.should == @username.upcase
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
53
99
|
describe "Named Schema" do
|
54
100
|
before(:all) do
|
55
101
|
plsql.connection = @conn = get_connection
|
@@ -80,30 +126,54 @@ end
|
|
80
126
|
describe "Schema commit and rollback" do
|
81
127
|
before(:all) do
|
82
128
|
plsql.connection = @conn = get_connection
|
129
|
+
plsql.connection.autocommit = false
|
130
|
+
plsql.execute "CREATE TABLE test_commit (dummy VARCHAR2(100))"
|
131
|
+
@data = {:dummy => 'test'}
|
132
|
+
@data2 = {:dummy => 'test2'}
|
83
133
|
end
|
84
134
|
|
85
135
|
after(:all) do
|
86
|
-
plsql.
|
136
|
+
plsql.execute "DROP TABLE test_commit"
|
137
|
+
plsql.logoff
|
138
|
+
end
|
139
|
+
|
140
|
+
after(:each) do
|
141
|
+
plsql.test_commit.delete
|
142
|
+
plsql.commit
|
87
143
|
end
|
88
144
|
|
89
145
|
it "should do commit" do
|
146
|
+
plsql.test_commit.insert @data
|
90
147
|
plsql.commit
|
148
|
+
plsql.test_commit.first.should == @data
|
91
149
|
end
|
92
|
-
|
150
|
+
|
93
151
|
it "should do rollback" do
|
152
|
+
plsql.test_commit.insert @data
|
94
153
|
plsql.rollback
|
154
|
+
plsql.test_commit.first.should be_nil
|
95
155
|
end
|
156
|
+
|
157
|
+
it "should create savepoint and rollback to savepoint" do
|
158
|
+
plsql.test_commit.insert @data
|
159
|
+
plsql.savepoint 'test'
|
160
|
+
plsql.test_commit.insert @data2
|
161
|
+
plsql.test_commit.all.should == [@data, @data2]
|
162
|
+
plsql.rollback_to 'test'
|
163
|
+
plsql.test_commit.all.should == [@data]
|
164
|
+
end
|
165
|
+
|
96
166
|
end
|
97
167
|
|
98
168
|
describe "ActiveRecord connection" do
|
99
169
|
before(:all) do
|
100
170
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
101
171
|
end
|
102
|
-
|
172
|
+
|
103
173
|
before(:each) do
|
104
174
|
plsql.activerecord_class = ActiveRecord::Base
|
105
175
|
end
|
106
|
-
|
176
|
+
|
107
177
|
it "should connect to test database" do
|
108
178
|
unless defined?(JRUBY_VERSION)
|
109
179
|
plsql.connection.is_a?(PLSQL::OCIConnection).should be_true
|
@@ -111,20 +181,20 @@ describe "ActiveRecord connection" do
|
|
111
181
|
plsql.connection.is_a?(PLSQL::JDBCConnection).should be_true
|
112
182
|
end
|
113
183
|
end
|
114
|
-
|
184
|
+
|
115
185
|
it "should return schema name" do
|
116
186
|
plsql.schema_name.should == 'HR'
|
117
187
|
end
|
118
|
-
|
188
|
+
|
119
189
|
it "should use ActiveRecord::Base.default_timezone as default" do
|
120
190
|
ActiveRecord::Base.default_timezone = :utc
|
121
191
|
plsql.default_timezone.should == :utc
|
122
192
|
end
|
123
|
-
|
193
|
+
|
124
194
|
it "should have the same connection as default schema" do
|
125
195
|
plsql.hr.connection.should == plsql.connection
|
126
196
|
end
|
127
|
-
end
|
197
|
+
end if defined?(ActiveRecord)
|
128
198
|
|
129
199
|
describe "DBMS_OUTPUT logging" do
|
130
200
|
|
@@ -158,6 +228,7 @@ describe "DBMS_OUTPUT logging" do
|
|
158
228
|
after(:all) do
|
159
229
|
plsql.dbms_output_stream = nil
|
160
230
|
plsql.execute "DROP PROCEDURE test_dbms_output"
|
231
|
+
plsql.execute "DROP PROCEDURE test_dbms_output_large"
|
161
232
|
plsql.logoff
|
162
233
|
end
|
163
234
|
|
@@ -230,6 +301,6 @@ describe "DBMS_OUTPUT logging" do
|
|
230
301
|
@buffer.string.should == "DBMS_OUTPUT: after reconnection\n"
|
231
302
|
end
|
232
303
|
|
233
|
-
end
|
304
|
+
end if defined?(ActiveRecord)
|
234
305
|
|
235
306
|
end
|