ruby-plsql 0.4.2 → 0.4.3
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 +10 -0
- data/VERSION +1 -1
- data/lib/plsql/jdbc_connection.rb +11 -1
- data/lib/plsql/oci_connection.rb +2 -1
- data/lib/plsql/procedure.rb +1 -1
- data/lib/plsql/procedure_call.rb +14 -7
- data/lib/plsql/table.rb +3 -1
- data/spec/plsql/connection_spec.rb +1 -1
- data/spec/plsql/procedure_spec.rb +32 -1
- data/spec/plsql/schema_spec.rb +1 -1
- data/spec/plsql/table_spec.rb +18 -2
- metadata +36 -17
data/History.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
== 0.4.3 2010-03-25
|
2
|
+
|
3
|
+
* Improvements
|
4
|
+
* plsql.connection.database_version will return also update and patch components of version number
|
5
|
+
* :column => :is_null and :column => :is_not_null conditions in table select operations
|
6
|
+
* Bug fixes
|
7
|
+
* Bugfix for calling procedure with table of records type (defined inside package) output parameter
|
8
|
+
* Use subprogram_id column in all_arguments view only if database version is >= 10.2.0.2
|
9
|
+
* Support partial list of named arguments for overloaded procedures (assuming that missing arguments will have default value)
|
10
|
+
|
1
11
|
== 0.4.2 2010-02-26
|
2
12
|
|
3
13
|
* New features
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
@@ -492,7 +492,17 @@ module PLSQL
|
|
492
492
|
end
|
493
493
|
|
494
494
|
def database_version
|
495
|
-
@database_version ||=
|
495
|
+
@database_version ||= if md = raw_connection.getMetaData
|
496
|
+
major = md.getDatabaseMajorVersion
|
497
|
+
minor = md.getDatabaseMinorVersion
|
498
|
+
if md.getDatabaseProductVersion =~ /#{major}\.#{minor}\.(\d+)\.(\d+)/
|
499
|
+
update = $1.to_i
|
500
|
+
patch = $2.to_i
|
501
|
+
else
|
502
|
+
update = patch = 0
|
503
|
+
end
|
504
|
+
[major, minor, update, patch]
|
505
|
+
end
|
496
506
|
end
|
497
507
|
|
498
508
|
private
|
data/lib/plsql/oci_connection.rb
CHANGED
@@ -282,7 +282,8 @@ module PLSQL
|
|
282
282
|
end
|
283
283
|
|
284
284
|
def database_version
|
285
|
-
@database_version ||= (version = raw_connection.oracle_server_version) &&
|
285
|
+
@database_version ||= (version = raw_connection.oracle_server_version) &&
|
286
|
+
[version.major, version.minor, version.update, version.patch]
|
286
287
|
end
|
287
288
|
|
288
289
|
private
|
data/lib/plsql/procedure.rb
CHANGED
@@ -82,7 +82,7 @@ module PLSQL
|
|
82
82
|
@tmp_tables_created = {}
|
83
83
|
|
84
84
|
# subprogram_id column is available just from version 10g
|
85
|
-
subprogram_id_column = (@schema.connection.database_version <=> [10, 2]) >= 0 ? 'subprogram_id' : 'NULL'
|
85
|
+
subprogram_id_column = (@schema.connection.database_version <=> [10, 2, 0, 2]) >= 0 ? 'subprogram_id' : 'NULL'
|
86
86
|
|
87
87
|
@schema.select_all(
|
88
88
|
"SELECT #{subprogram_id_column}, object_name, TO_NUMBER(overload), argument_name, position, data_level,
|
data/lib/plsql/procedure_call.rb
CHANGED
@@ -49,12 +49,19 @@ module PLSQL
|
|
49
49
|
args_keys = args[0].keys
|
50
50
|
# implicit SELF argument for object instance procedures
|
51
51
|
args_keys << :self if @self && !args_keys.include?(:self)
|
52
|
-
args_keys = args_keys.sort_by{|k| k.to_s}
|
53
52
|
number_of_args = args_keys.size
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
matching_overloads = [] # overloads with exact or smaller number of matching named arguments
|
54
|
+
overload_argument_list.keys.each do |ov|
|
55
|
+
# assume that missing arguments have default value
|
56
|
+
missing_arguments_count = overload_argument_list[ov].size - number_of_args
|
57
|
+
if missing_arguments_count >= 0 &&
|
58
|
+
args_keys.all?{|k| overload_argument_list[ov].include?(k)}
|
59
|
+
matching_overloads << [ov, missing_arguments_count]
|
60
|
+
end
|
57
61
|
end
|
62
|
+
# pick first matching overload with smallest missing arguments count
|
63
|
+
# (hoping that missing arguments will be defaulted - cannot find default value from all_arguments)
|
64
|
+
overload = matching_overloads.sort_by{|ov, score| score}[0][0]
|
58
65
|
# otherwise try matching by sequential arguments count and types
|
59
66
|
else
|
60
67
|
number_of_args = args.size
|
@@ -69,7 +76,7 @@ module PLSQL
|
|
69
76
|
matching_types << matching_oracle_types_for_ruby_value(arg)
|
70
77
|
end
|
71
78
|
exact_overloads = [] # overloads with exact number of matching arguments
|
72
|
-
smaller_overloads = [] # overloads with
|
79
|
+
smaller_overloads = [] # overloads with smaller number of matching arguments
|
73
80
|
# overload = overload_argument_list.keys.detect do |ov|
|
74
81
|
# overload_argument_list[ov].size == number_of_args
|
75
82
|
# end
|
@@ -399,7 +406,7 @@ module PLSQL
|
|
399
406
|
case argument_metadata[:element][:data_type]
|
400
407
|
when 'PL/SQL RECORD'
|
401
408
|
field_names = record_fields_sorted_by_position(argument_metadata[:element][:fields])
|
402
|
-
values_string = field_names.map{|f| "
|
409
|
+
values_string = field_names.map{|f| "l_#{argument}(i__).#{f}"}.join(', ')
|
403
410
|
@return_sql << "INSERT INTO #{argument_metadata[:tmp_table_name]} VALUES (#{values_string}, i__);\n"
|
404
411
|
return_fields_string = is_index_by_table ? '*' : field_names.join(', ')
|
405
412
|
else
|
@@ -534,7 +541,7 @@ module PLSQL
|
|
534
541
|
if @dbms_output_stream
|
535
542
|
dbms_output_enable_sql = "DBMS_OUTPUT.ENABLE(#{@schema.dbms_output_buffer_size});\n"
|
536
543
|
# if database version is at least 10.2 then use DBMS_OUTPUT.GET_LINES with SYS.DBMSOUTPUT_LINESARRAY
|
537
|
-
if (@schema.connection.database_version <=> [10, 2]) >= 0
|
544
|
+
if (@schema.connection.database_version <=> [10, 2, 0, 0]) >= 0
|
538
545
|
@declare_sql << "l_dbms_output_numlines INTEGER := #{Schema::DBMS_OUTPUT_MAX_LINES};\n"
|
539
546
|
dbms_output_get_sql = "DBMS_OUTPUT.GET_LINES(:dbms_output_lines, l_dbms_output_numlines);\n"
|
540
547
|
@bind_values[:dbms_output_lines] = nil
|
data/lib/plsql/table.rb
CHANGED
@@ -105,8 +105,10 @@ module PLSQL
|
|
105
105
|
sql_params.each do |k,v|
|
106
106
|
if k == :order_by
|
107
107
|
order_by_sql = " ORDER BY #{v} "
|
108
|
-
elsif v.nil?
|
108
|
+
elsif v.nil? || v == :is_null
|
109
109
|
where_sqls << "#{k} IS NULL"
|
110
|
+
elsif v == :is_not_null
|
111
|
+
where_sqls << "#{k} IS NOT NULL"
|
110
112
|
else
|
111
113
|
where_sqls << "#{k} = :#{k}"
|
112
114
|
bindvars << v
|
@@ -407,7 +407,7 @@ describe "Connection" do
|
|
407
407
|
describe "session information" do
|
408
408
|
it "should get database version" do
|
409
409
|
# using Oracle version 10.2.0.4 for unit tests
|
410
|
-
@conn.database_version.should == [10, 2]
|
410
|
+
@conn.database_version.should == [10, 2, 0, 4]
|
411
411
|
end
|
412
412
|
|
413
413
|
it "should get session ID" do
|
@@ -282,6 +282,10 @@ describe "Parameter type mapping /" do
|
|
282
282
|
;
|
283
283
|
FUNCTION test_procedure2 ( p_string VARCHAR2 )
|
284
284
|
RETURN VARCHAR2;
|
285
|
+
FUNCTION test_function ( p_string VARCHAR2, p_string2 VARCHAR2 DEFAULT ' ')
|
286
|
+
RETURN VARCHAR2;
|
287
|
+
FUNCTION test_function ( p_number NUMBER, p_number2 NUMBER DEFAULT 1 )
|
288
|
+
RETURN NUMBER;
|
285
289
|
END;
|
286
290
|
SQL
|
287
291
|
plsql.execute <<-SQL
|
@@ -308,6 +312,18 @@ describe "Parameter type mapping /" do
|
|
308
312
|
BEGIN
|
309
313
|
RETURN UPPER(p_string);
|
310
314
|
END test_procedure2;
|
315
|
+
FUNCTION test_function ( p_string VARCHAR2, p_string2 VARCHAR2)
|
316
|
+
RETURN VARCHAR2
|
317
|
+
IS
|
318
|
+
BEGIN
|
319
|
+
RETURN p_string||p_string2;
|
320
|
+
END;
|
321
|
+
FUNCTION test_function ( p_number NUMBER, p_number2 NUMBER)
|
322
|
+
RETURN NUMBER
|
323
|
+
IS
|
324
|
+
BEGIN
|
325
|
+
RETURN p_number + p_number2;
|
326
|
+
END;
|
311
327
|
END;
|
312
328
|
SQL
|
313
329
|
|
@@ -355,6 +371,11 @@ describe "Parameter type mapping /" do
|
|
355
371
|
plsql.test_package2.test_procedure(:p_number => 111, :p_result => nil).should == {:p_result => '111'}
|
356
372
|
end
|
357
373
|
|
374
|
+
it "should find matching procedure based on partial list of named arguments" do
|
375
|
+
plsql.test_package2.test_function(:p_string => 'xxx').should == 'xxx '
|
376
|
+
plsql.test_package2.test_function(:p_number => 1).should == 2
|
377
|
+
end
|
378
|
+
|
358
379
|
end
|
359
380
|
|
360
381
|
describe "Function with output parameters" do
|
@@ -1097,6 +1118,7 @@ describe "Parameter type mapping /" do
|
|
1097
1118
|
INDEX BY BINARY_INTEGER;
|
1098
1119
|
FUNCTION test_employees (p_employees IN OUT t_employees)
|
1099
1120
|
RETURN t_employees;
|
1121
|
+
PROCEDURE test_employees_prc (p_employees IN OUT t_employees);
|
1100
1122
|
PROCEDURE insert_employees(p_employees IN t_employees);
|
1101
1123
|
END;
|
1102
1124
|
SQL
|
@@ -1133,6 +1155,11 @@ describe "Parameter type mapping /" do
|
|
1133
1155
|
BEGIN
|
1134
1156
|
RETURN p_employees;
|
1135
1157
|
END;
|
1158
|
+
PROCEDURE test_employees_prc (p_employees IN OUT t_employees)
|
1159
|
+
IS
|
1160
|
+
BEGIN
|
1161
|
+
NULL;
|
1162
|
+
END;
|
1136
1163
|
PROCEDURE insert_employees(p_employees IN t_employees) IS
|
1137
1164
|
BEGIN
|
1138
1165
|
FORALL i IN p_employees.FIRST..p_employees.LAST
|
@@ -1181,6 +1208,10 @@ describe "Parameter type mapping /" do
|
|
1181
1208
|
plsql.test_collections.test_employees(@employees).should == [@employees, {:p_employees => @employees}]
|
1182
1209
|
end
|
1183
1210
|
|
1211
|
+
it "should execute procedure with index-by table of records type (defined inside package) parameter" do
|
1212
|
+
plsql.test_collections.test_employees_prc(@employees).should == {:p_employees => @employees}
|
1213
|
+
end
|
1214
|
+
|
1184
1215
|
it "should create temporary tables in autonomous transaction" do
|
1185
1216
|
old_autocommit = plsql.connection.autocommit?
|
1186
1217
|
plsql.connection.autocommit = false
|
@@ -1196,7 +1227,7 @@ describe "Parameter type mapping /" do
|
|
1196
1227
|
before(:all) do
|
1197
1228
|
# simulate Oracle 9.2 connection
|
1198
1229
|
plsql(:oracle_9).connection = get_connection
|
1199
|
-
plsql(:oracle_9).connection.stub!(:database_version).and_return([9, 2])
|
1230
|
+
plsql(:oracle_9).connection.stub!(:database_version).and_return([9, 2, 0, 0])
|
1200
1231
|
end
|
1201
1232
|
|
1202
1233
|
after(:all) do
|
data/spec/plsql/schema_spec.rb
CHANGED
@@ -269,7 +269,7 @@ describe "DBMS_OUTPUT logging" do
|
|
269
269
|
end
|
270
270
|
|
271
271
|
it "should log output when database version is less than 10.2" do
|
272
|
-
plsql.connection.stub!(:database_version).and_return([9, 2])
|
272
|
+
plsql.connection.stub!(:database_version).and_return([9, 2, 0, 0])
|
273
273
|
times = 2_000
|
274
274
|
plsql.test_dbms_output_large("1234567890", times)
|
275
275
|
@buffer.string.should == "DBMS_OUTPUT: 1234567890\n" * times
|
data/spec/plsql/table_spec.rb
CHANGED
@@ -272,12 +272,12 @@ describe "Table" do
|
|
272
272
|
plsql.test_employees.first(:employee_id => @employees.first[:employee_id]).should == @employees.first
|
273
273
|
end
|
274
274
|
|
275
|
-
it "should select records in table using WHERE condition and
|
275
|
+
it "should select records in table using WHERE condition and ORDER BY sorting" do
|
276
276
|
plsql.test_employees.all(:employee_id => @employees.first[:employee_id], :order_by => :employee_id).should == [@employees.first]
|
277
277
|
end
|
278
278
|
|
279
279
|
it "should select record in table using :column => nil condition" do
|
280
|
-
employee = @employees.last
|
280
|
+
employee = @employees.last.dup
|
281
281
|
employee[:employee_id] = employee[:employee_id] + 1
|
282
282
|
employee[:hire_date] = nil
|
283
283
|
plsql.test_employees.insert employee
|
@@ -285,6 +285,22 @@ describe "Table" do
|
|
285
285
|
plsql.test_employees.first(:hire_date => nil).should == employee
|
286
286
|
end
|
287
287
|
|
288
|
+
it "should select record in table using :column => :is_null condition" do
|
289
|
+
employee = @employees.last.dup
|
290
|
+
employee[:employee_id] = employee[:employee_id] + 1
|
291
|
+
employee[:hire_date] = nil
|
292
|
+
plsql.test_employees.insert employee
|
293
|
+
plsql.test_employees.first(:hire_date => :is_null).should == employee
|
294
|
+
end
|
295
|
+
|
296
|
+
it "should select record in table using :column => :is_not_null condition" do
|
297
|
+
employee = @employees.last.dup
|
298
|
+
employee[:employee_id] = employee[:employee_id] + 1
|
299
|
+
employee[:hire_date] = nil
|
300
|
+
plsql.test_employees.insert employee
|
301
|
+
plsql.test_employees.all(:hire_date => :is_not_null, :order_by => :employee_id).should == @employees
|
302
|
+
end
|
303
|
+
|
288
304
|
it "should count records in table" do
|
289
305
|
plsql.test_employees.select(:count).should == @employees.size
|
290
306
|
plsql.test_employees.count.should == @employees.size
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-plsql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 4
|
8
|
+
- 3
|
9
|
+
version: 0.4.3
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Raimonds Simanovskis
|
@@ -9,39 +14,51 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-25 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: rspec
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 9
|
23
31
|
version: 1.2.9
|
24
|
-
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: activerecord
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - "="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 3
|
44
|
+
- 5
|
33
45
|
version: 2.3.5
|
34
|
-
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
35
48
|
- !ruby/object:Gem::Dependency
|
36
49
|
name: activerecord-oracle_enhanced-adapter
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
52
|
requirements:
|
41
53
|
- - ">="
|
42
54
|
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 2
|
58
|
+
- 4
|
43
59
|
version: 1.2.4
|
44
|
-
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
45
62
|
description: |
|
46
63
|
ruby-plsql gem provides simple Ruby API for calling Oracle PL/SQL procedures.
|
47
64
|
It could be used both for accessing Oracle PL/SQL API procedures in legacy applications
|
@@ -105,18 +122,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
122
|
requirements:
|
106
123
|
- - ">="
|
107
124
|
- !ruby/object:Gem::Version
|
125
|
+
segments:
|
126
|
+
- 0
|
108
127
|
version: "0"
|
109
|
-
version:
|
110
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
129
|
requirements:
|
112
130
|
- - ">="
|
113
131
|
- !ruby/object:Gem::Version
|
132
|
+
segments:
|
133
|
+
- 0
|
114
134
|
version: "0"
|
115
|
-
version:
|
116
135
|
requirements: []
|
117
136
|
|
118
137
|
rubyforge_project:
|
119
|
-
rubygems_version: 1.3.
|
138
|
+
rubygems_version: 1.3.6
|
120
139
|
signing_key:
|
121
140
|
specification_version: 3
|
122
141
|
summary: Ruby API for calling Oracle PL/SQL procedures.
|