ruby-oci8 2.0.4-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +1912 -0
- data/Makefile +96 -0
- data/NEWS +223 -0
- data/README +86 -0
- data/VERSION +1 -0
- data/dist-files +77 -0
- data/doc/api.en.html +527 -0
- data/doc/api.en.rd +554 -0
- data/doc/api.ja.html +525 -0
- data/doc/api.ja.rd +557 -0
- data/doc/manual.css +35 -0
- data/lib/.document +1 -0
- data/lib/dbd/OCI8.rb +591 -0
- data/lib/oci8.rb +82 -0
- data/lib/oci8.rb.in +82 -0
- data/lib/oci8/.document +5 -0
- data/lib/oci8/bindtype.rb +319 -0
- data/lib/oci8/compat.rb +113 -0
- data/lib/oci8/datetime.rb +619 -0
- data/lib/oci8/encoding-init.rb +40 -0
- data/lib/oci8/encoding.yml +537 -0
- data/lib/oci8/metadata.rb +2077 -0
- data/lib/oci8/object.rb +562 -0
- data/lib/oci8/oci8.rb +571 -0
- data/lib/oci8/oracle_version.rb +144 -0
- data/lib/oci8lib_18.so +0 -0
- data/lib/oci8lib_191.so +0 -0
- data/metaconfig +142 -0
- data/pre-distclean.rb +7 -0
- data/ruby-oci8.gemspec +63 -0
- data/setup.rb +1331 -0
- data/test/README +4 -0
- data/test/config.rb +109 -0
- data/test/test_all.rb +50 -0
- data/test/test_appinfo.rb +63 -0
- data/test/test_array_dml.rb +333 -0
- data/test/test_bind_raw.rb +46 -0
- data/test/test_bind_time.rb +178 -0
- data/test/test_break.rb +83 -0
- data/test/test_clob.rb +79 -0
- data/test/test_connstr.rb +81 -0
- data/test/test_datetime.rb +622 -0
- data/test/test_dbi.rb +366 -0
- data/test/test_dbi_clob.rb +53 -0
- data/test/test_encoding.rb +100 -0
- data/test/test_metadata.rb +257 -0
- data/test/test_oci8.rb +434 -0
- data/test/test_oracle_version.rb +70 -0
- data/test/test_oradate.rb +256 -0
- data/test/test_oranumber.rb +655 -0
- data/test/test_rowid.rb +33 -0
- metadata +108 -0
data/test/README
ADDED
data/test/config.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# $dbuser must have permission to run DBMS_LOCK.SLEEP
|
2
|
+
# connect as sys
|
3
|
+
# GRANT EXECUTE ON dbms_lock TO ruby;
|
4
|
+
$dbuser = "ruby"
|
5
|
+
$dbpass = "oci8"
|
6
|
+
$dbname = nil
|
7
|
+
|
8
|
+
# test_clob.rb
|
9
|
+
|
10
|
+
nls_lang = ENV['NLS_LANG']
|
11
|
+
nls_lang = nls_lang.split('.')[1] unless nls_lang.nil?
|
12
|
+
nls_lang = nls_lang.upcase unless nls_lang.nil?
|
13
|
+
case nls_lang
|
14
|
+
when 'JA16EUC'
|
15
|
+
$lobfile = File.dirname(__FILE__) + '/../doc/api.ja.rd' # EUC-JP file
|
16
|
+
else
|
17
|
+
$lobfile = File.dirname(__FILE__) + '/../doc/api.en.rd' # ASCII file
|
18
|
+
end
|
19
|
+
$lobreadnum = 256 # counts in charactors
|
20
|
+
|
21
|
+
# don't modify below.
|
22
|
+
|
23
|
+
# $oracle_server_version: database compatible level of the Oracle server.
|
24
|
+
# $oracle_client_version: Oracle client library version for which oci8 is compiled.
|
25
|
+
# $oracle_version: lower value of $oracle_server_version and $oracle_client_version.
|
26
|
+
conn = OCI8.new($dbuser, $dbpass, $dbname)
|
27
|
+
begin
|
28
|
+
conn.exec('select value from database_compatible_level') do |row|
|
29
|
+
$oracle_server_version = OCI8::OracleVersion.new(row[0])
|
30
|
+
end
|
31
|
+
rescue OCIError
|
32
|
+
raise if $!.code != 942 # ORA-00942: table or view does not exist
|
33
|
+
$oracle_server_version = OCI8::ORAVER_8_0
|
34
|
+
end
|
35
|
+
conn.logoff
|
36
|
+
|
37
|
+
if $oracle_server_version < OCI8.oracle_client_version
|
38
|
+
$oracle_version = $oracle_server_version
|
39
|
+
else
|
40
|
+
$oracle_version = OCI8.oracle_client_version
|
41
|
+
end
|
42
|
+
|
43
|
+
if $oracle_version < OCI8::ORAVER_8_1
|
44
|
+
$test_clob = false
|
45
|
+
else
|
46
|
+
$test_clob = true
|
47
|
+
end
|
48
|
+
|
49
|
+
module Test
|
50
|
+
module Unit
|
51
|
+
class TestCase
|
52
|
+
|
53
|
+
def get_oci8_connection()
|
54
|
+
OCI8.new($dbuser, $dbpass, $dbname)
|
55
|
+
rescue OCIError
|
56
|
+
raise if $!.code != 12516 && $!.code != 12520
|
57
|
+
# sleep a few second and try again if
|
58
|
+
# the error code is ORA-12516 or ORA-12520.
|
59
|
+
#
|
60
|
+
# ORA-12516 - TNS:listener could not find available handler with
|
61
|
+
# matching protocol stack
|
62
|
+
# ORA-12520 - TNS:listener could not find available handler for
|
63
|
+
# requested type of server
|
64
|
+
#
|
65
|
+
# Thanks to Christopher Jones.
|
66
|
+
#
|
67
|
+
# Ref: The Underground PHP and Oracle Manual (page 175 in vesion 1.4)
|
68
|
+
# http://www.oracle.com/technology/tech/php/pdf/underground-php-oracle-manual.pdf
|
69
|
+
#
|
70
|
+
sleep(5)
|
71
|
+
OCI8.new($dbuser, $dbpass, $dbname)
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_dbi_connection()
|
75
|
+
DBI.connect("dbi:OCI8:#{$dbname}", $dbuser, $dbpass, 'AutoCommit' => false)
|
76
|
+
rescue DBI::DatabaseError
|
77
|
+
raise if $!.err != 12516 && $!.err != 12520
|
78
|
+
# same as get_oci8_connection()
|
79
|
+
sleep(5)
|
80
|
+
DBI.connect("dbi:OCI8:#{$dbname}", $dbuser, $dbpass, 'AutoCommit' => false)
|
81
|
+
end
|
82
|
+
|
83
|
+
def drop_table(table_name)
|
84
|
+
if $oracle_server_version < OCI8::ORAVER_10_1
|
85
|
+
# Oracle 8 - 9i
|
86
|
+
sql = "DROP TABLE #{table_name}"
|
87
|
+
else
|
88
|
+
# Oracle 10g -
|
89
|
+
sql = "DROP TABLE #{table_name} PURGE"
|
90
|
+
end
|
91
|
+
|
92
|
+
if defined? @conn
|
93
|
+
begin
|
94
|
+
@conn.exec(sql)
|
95
|
+
rescue OCIError
|
96
|
+
raise if $!.code != 942 # table or view does not exist
|
97
|
+
end
|
98
|
+
elsif instance_variable_get(:@dbh)
|
99
|
+
begin
|
100
|
+
@dbh.do(sql)
|
101
|
+
rescue DBI::DatabaseError
|
102
|
+
raise if $!.err != 942 # table or view does not exist
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end # drop_table
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
data/test/test_all.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
srcdir = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'oci8'
|
4
|
+
require 'test/unit'
|
5
|
+
require "#{srcdir}/config"
|
6
|
+
|
7
|
+
require "#{srcdir}/test_oradate"
|
8
|
+
require "#{srcdir}/test_oranumber"
|
9
|
+
require "#{srcdir}/test_bind_time"
|
10
|
+
require "#{srcdir}/test_bind_raw"
|
11
|
+
if $test_clob
|
12
|
+
require "#{srcdir}/test_clob"
|
13
|
+
end
|
14
|
+
|
15
|
+
require "#{srcdir}/test_break"
|
16
|
+
require "#{srcdir}/test_oci8"
|
17
|
+
require "#{srcdir}/test_datetime"
|
18
|
+
require "#{srcdir}/test_connstr"
|
19
|
+
require "#{srcdir}/test_metadata"
|
20
|
+
require "#{srcdir}/test_array_dml"
|
21
|
+
require "#{srcdir}/test_rowid"
|
22
|
+
require "#{srcdir}/test_appinfo"
|
23
|
+
require "#{srcdir}/test_oracle_version"
|
24
|
+
|
25
|
+
if OCI8.respond_to? :encoding
|
26
|
+
require "#{srcdir}/test_encoding"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Ruby/DBI
|
30
|
+
begin
|
31
|
+
require 'dbi'
|
32
|
+
rescue LoadError
|
33
|
+
begin
|
34
|
+
require 'rubygems'
|
35
|
+
require 'dbi'
|
36
|
+
rescue LoadError
|
37
|
+
dbi_not_found = true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
unless dbi_not_found
|
41
|
+
require "#{srcdir}/test_dbi"
|
42
|
+
if $test_clob
|
43
|
+
require "#{srcdir}/test_dbi_clob"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
#Test::Unit::AutoRunner.run(true, true)
|
48
|
+
if defined? Test::Unit::AutoRunner
|
49
|
+
Test::Unit::AutoRunner.run()
|
50
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/config'
|
4
|
+
|
5
|
+
class TestAppInfo < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@conn = get_oci8_connection
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_set_client_identifier
|
12
|
+
# set client_id
|
13
|
+
client_id = "ruby-oci8:#{Process.pid()}"
|
14
|
+
@conn.client_identifier = client_id
|
15
|
+
assert_equal(client_id, @conn.select_one("SELECT SYS_CONTEXT('USERENV', 'CLIENT_IDENTIFIER') FROM DUAL")[0]);
|
16
|
+
# check the first character
|
17
|
+
assert_raise ArgumentError do
|
18
|
+
@conn.client_identifier = ':bad_identifier'
|
19
|
+
end
|
20
|
+
|
21
|
+
# clear client_id
|
22
|
+
@conn.client_identifier = nil
|
23
|
+
assert_nil(@conn.select_one("SELECT SYS_CONTEXT('USERENV', 'CLIENT_IDENTIFIER') FROM DUAL")[0]);
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_set_module
|
27
|
+
# FIXME: check again after upgrading Oracle 9.2 to 9.2.0.4.
|
28
|
+
return if @conn.oracle_server_version < OCI8::ORAVER_10_1
|
29
|
+
|
30
|
+
# set module
|
31
|
+
@conn.module = 'ruby-oci8'
|
32
|
+
assert_equal('ruby-oci8', @conn.select_one("SELECT SYS_CONTEXT('USERENV', 'MODULE') FROM DUAL")[0]);
|
33
|
+
# clear module
|
34
|
+
@conn.module = nil
|
35
|
+
assert_nil(@conn.select_one("SELECT SYS_CONTEXT('USERENV', 'MODULE') FROM DUAL")[0]);
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_set_action
|
39
|
+
# FIXME: check again after upgrading Oracle 9.2 to 9.2.0.4.
|
40
|
+
return if @conn.oracle_server_version < OCI8::ORAVER_10_1
|
41
|
+
|
42
|
+
# set action
|
43
|
+
@conn.action = 'test_set_action'
|
44
|
+
assert_equal('test_set_action', @conn.select_one("SELECT SYS_CONTEXT('USERENV', 'ACTION') FROM DUAL")[0]);
|
45
|
+
# clear action
|
46
|
+
@conn.action = nil
|
47
|
+
assert_nil(@conn.select_one("SELECT SYS_CONTEXT('USERENV', 'ACTION') FROM DUAL")[0]);
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_set_client_info
|
51
|
+
# set client_info
|
52
|
+
client_info = "ruby-oci8:#{Process.pid()}"
|
53
|
+
@conn.client_info = client_info
|
54
|
+
assert_equal(client_info, @conn.select_one("SELECT SYS_CONTEXT('USERENV', 'CLIENT_INFO') FROM DUAL")[0]);
|
55
|
+
# clear client_info
|
56
|
+
@conn.client_info = nil
|
57
|
+
assert_nil(@conn.select_one("SELECT SYS_CONTEXT('USERENV', 'CLIENT_INFO') FROM DUAL")[0]);
|
58
|
+
end
|
59
|
+
|
60
|
+
def teardown
|
61
|
+
@conn.logoff
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,333 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/config'
|
4
|
+
|
5
|
+
class TestArrayDML < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@conn = get_oci8_connection
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
@conn.logoff
|
12
|
+
end
|
13
|
+
|
14
|
+
# test inserting arrays with different data types
|
15
|
+
# including char, varchar2, number, date and so on
|
16
|
+
def test_array_insert1
|
17
|
+
drop_table('test_table')
|
18
|
+
sql = <<-EOS
|
19
|
+
CREATE TABLE test_table
|
20
|
+
(C CHAR(10) NOT NULL,
|
21
|
+
V VARCHAR2(20),
|
22
|
+
N NUMBER(10, 2),
|
23
|
+
D DATE,
|
24
|
+
INT NUMBER(30),
|
25
|
+
BIGNUM NUMBER(30),
|
26
|
+
T TIMESTAMP)
|
27
|
+
STORAGE (
|
28
|
+
INITIAL 4k
|
29
|
+
NEXT 4k
|
30
|
+
MINEXTENTS 1
|
31
|
+
MAXEXTENTS UNLIMITED
|
32
|
+
PCTINCREASE 0)
|
33
|
+
EOS
|
34
|
+
@conn.exec(sql)
|
35
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:C, :V, :N, :D, :INT, :BIGNUM, :T)")
|
36
|
+
max_array_size = 3
|
37
|
+
cursor.max_array_size= max_array_size
|
38
|
+
|
39
|
+
cursor.bind_param_array(1, nil, String)
|
40
|
+
cursor.bind_param_array(2, nil ,String)
|
41
|
+
cursor.bind_param_array(3, nil, Fixnum)
|
42
|
+
cursor.bind_param_array(4, nil, OraDate)
|
43
|
+
cursor.bind_param_array(5, nil, Integer)
|
44
|
+
cursor.bind_param_array(6, nil, Bignum)
|
45
|
+
cursor.bind_param_array(7, nil, DateTime)
|
46
|
+
|
47
|
+
c_arr = Array.new
|
48
|
+
v_arr = Array.new
|
49
|
+
n_arr = Array.new
|
50
|
+
d_arr = Array.new
|
51
|
+
int_arr = Array.new
|
52
|
+
bignum_arr = Array.new
|
53
|
+
t_arr = Array.new
|
54
|
+
|
55
|
+
1.upto(30) do |i|
|
56
|
+
c_arr << format("%10d", i * 10)
|
57
|
+
v_arr << i.to_s
|
58
|
+
n_arr << i
|
59
|
+
d_arr << OraDate.new(2000 + i, 12, 24, 23, 59, 59)
|
60
|
+
int_arr << i * 11111111111
|
61
|
+
bignum_arr << i * 10000000000
|
62
|
+
t_arr << DateTime.new(2000 + i, 12, 24, 23, 59, 59)
|
63
|
+
|
64
|
+
if i%max_array_size == 0
|
65
|
+
cursor[1] = c_arr
|
66
|
+
cursor[2] = v_arr
|
67
|
+
cursor[3] = n_arr
|
68
|
+
cursor[4] = d_arr
|
69
|
+
cursor[5] = int_arr
|
70
|
+
cursor[6] = bignum_arr
|
71
|
+
cursor[7] = t_arr
|
72
|
+
|
73
|
+
r = cursor.exec_array
|
74
|
+
assert_equal(max_array_size, r)
|
75
|
+
assert_equal(c_arr, cursor[1])
|
76
|
+
assert_equal(v_arr, cursor[2])
|
77
|
+
assert_equal(n_arr, cursor[3])
|
78
|
+
assert_equal(d_arr, cursor[4])
|
79
|
+
assert_equal(int_arr, cursor[5])
|
80
|
+
assert_equal(bignum_arr, cursor[6])
|
81
|
+
assert_equal(t_arr, cursor[7])
|
82
|
+
c_arr.clear
|
83
|
+
v_arr.clear
|
84
|
+
n_arr.clear
|
85
|
+
d_arr.clear
|
86
|
+
int_arr.clear
|
87
|
+
bignum_arr.clear
|
88
|
+
t_arr.clear
|
89
|
+
end
|
90
|
+
end
|
91
|
+
cursor.close
|
92
|
+
|
93
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY c")
|
94
|
+
cursor.define(5, Integer)
|
95
|
+
cursor.define(6, Bignum)
|
96
|
+
cursor.exec
|
97
|
+
assert_equal(["C","V","N","D","INT","BIGNUM","T"], cursor.get_col_names)
|
98
|
+
1.upto(30) do |i|
|
99
|
+
rv = cursor.fetch
|
100
|
+
assert_equal(format("%10d", i * 10), rv[0])
|
101
|
+
assert_equal(i.to_s, rv[1])
|
102
|
+
assert_equal(i, rv[2])
|
103
|
+
tm = Time.local(2000 + i, 12, 24, 23, 59, 59)
|
104
|
+
assert_equal(tm, rv[3])
|
105
|
+
assert_equal(i * 11111111111, rv[4])
|
106
|
+
assert_equal(i * 10000000000, rv[5])
|
107
|
+
assert_equal(tm, rv[6])
|
108
|
+
end
|
109
|
+
assert_nil(cursor.fetch)
|
110
|
+
drop_table('test_table')
|
111
|
+
end
|
112
|
+
|
113
|
+
# Raise error when binding arrays are not the same size
|
114
|
+
def test_array_insert2
|
115
|
+
drop_table('test_table')
|
116
|
+
sql = <<-EOS
|
117
|
+
CREATE TABLE test_table
|
118
|
+
(N NUMBER(10, 2) NOT NULL,
|
119
|
+
V VARCHAR(20))
|
120
|
+
EOS
|
121
|
+
@conn.exec(sql)
|
122
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
123
|
+
max_array_size = 10
|
124
|
+
cursor.max_array_size = max_array_size
|
125
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
126
|
+
cursor.bind_param_array(2, nil, String)
|
127
|
+
n_arr = Array.new
|
128
|
+
v_arr = Array.new
|
129
|
+
1.upto(max_array_size) do |i|
|
130
|
+
n_arr << i
|
131
|
+
v_arr << i.to_s if i != max_array_size
|
132
|
+
end
|
133
|
+
cursor[1] = n_arr
|
134
|
+
assert_raise(RuntimeError) { cursor[2] = v_arr }
|
135
|
+
cursor.close
|
136
|
+
|
137
|
+
drop_table('test_table')
|
138
|
+
end
|
139
|
+
|
140
|
+
# All binds are clear from cursor after calling "max_array_size=",
|
141
|
+
# in that case, you have to re-bind the array parameters
|
142
|
+
# otherwise, an error will be raised.
|
143
|
+
def test_array_insert3
|
144
|
+
drop_table('test_table')
|
145
|
+
sql = <<-EOS
|
146
|
+
CREATE TABLE test_table
|
147
|
+
(N NUMBER(10, 2) NOT NULL,
|
148
|
+
V VARCHAR(20),
|
149
|
+
T TIMESTAMP)
|
150
|
+
EOS
|
151
|
+
@conn.exec(sql)
|
152
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V, :T)")
|
153
|
+
cursor.max_array_size = 3
|
154
|
+
cursor.bind_param_array(1, [1, 2, 3])
|
155
|
+
cursor.bind_param_array(2, ['happy', 'new', 'year'])
|
156
|
+
cursor.bind_param_array(3, [Time.gm(1990,1,1), Time.gm(2000,1,1), Time.gm(2010,1,1)])
|
157
|
+
assert_nothing_raised() { cursor.exec_array }
|
158
|
+
cursor.max_array_size = 2
|
159
|
+
assert_raise(RuntimeError) { cursor.exec_array }
|
160
|
+
drop_table('test_table')
|
161
|
+
end
|
162
|
+
|
163
|
+
# The size of binding arrays are not required to be same as max_array_size. The
|
164
|
+
# only requirement is that they should be the same size, and the size will be
|
165
|
+
# used as execution count for OCIStmtExecute.
|
166
|
+
def test_array_insert4
|
167
|
+
drop_table('test_table')
|
168
|
+
sql = <<-EOS
|
169
|
+
CREATE TABLE test_table
|
170
|
+
(N NUMBER(10, 2) NOT NULL,
|
171
|
+
V VARCHAR(20))
|
172
|
+
EOS
|
173
|
+
@conn.exec(sql)
|
174
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
175
|
+
max_array_size = 4
|
176
|
+
cursor.max_array_size = max_array_size
|
177
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
178
|
+
cursor.bind_param_array(2, nil, String)
|
179
|
+
n_arr = Array.new
|
180
|
+
v_arr = Array.new
|
181
|
+
1.upto( max_array_size - 1 ) do |i|
|
182
|
+
n_arr << i
|
183
|
+
v_arr << i.to_s
|
184
|
+
end
|
185
|
+
cursor[1] = n_arr
|
186
|
+
cursor[2] = v_arr
|
187
|
+
assert_nothing_raised() { cursor.exec_array }
|
188
|
+
cursor.close
|
189
|
+
|
190
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY N")
|
191
|
+
cursor.exec
|
192
|
+
1.upto( max_array_size - 1 ) do |i|
|
193
|
+
rv = cursor.fetch
|
194
|
+
assert_equal(i, rv[0])
|
195
|
+
assert_equal(i.to_s, rv[1])
|
196
|
+
end
|
197
|
+
assert_nil(cursor.fetch)
|
198
|
+
cursor.close
|
199
|
+
drop_table('test_table')
|
200
|
+
end
|
201
|
+
|
202
|
+
# Inserting "nil" elements with array dml raises an error
|
203
|
+
def test_array_insert5
|
204
|
+
drop_table('test_table')
|
205
|
+
sql = <<-EOS
|
206
|
+
CREATE TABLE test_table
|
207
|
+
(N NUMBER(10, 2),
|
208
|
+
V VARCHAR(20))
|
209
|
+
EOS
|
210
|
+
@conn.exec(sql)
|
211
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
212
|
+
max_array_size = 3
|
213
|
+
cursor.max_array_size = max_array_size
|
214
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
215
|
+
cursor.bind_param_array(2, nil, String)
|
216
|
+
assert_raise(RuntimeError) { cursor.exec_array }
|
217
|
+
cursor.close
|
218
|
+
drop_table('test_table')
|
219
|
+
end
|
220
|
+
|
221
|
+
# delete with array bindings
|
222
|
+
def test_array_delete
|
223
|
+
drop_table('test_table')
|
224
|
+
sql = <<-EOS
|
225
|
+
CREATE TABLE test_table
|
226
|
+
(N NUMBER(10, 2),
|
227
|
+
V VARCHAR(20))
|
228
|
+
EOS
|
229
|
+
@conn.exec(sql)
|
230
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
231
|
+
max_array_size = 10
|
232
|
+
cursor.max_array_size = max_array_size
|
233
|
+
n_arr = Array.new
|
234
|
+
v_arr = Array.new
|
235
|
+
1.upto( max_array_size) do |i|
|
236
|
+
n_arr << i
|
237
|
+
v_arr << i.to_s
|
238
|
+
end
|
239
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
240
|
+
cursor.bind_param_array(2, nil, String)
|
241
|
+
cursor[1] = n_arr
|
242
|
+
cursor[2] = v_arr
|
243
|
+
cursor.exec_array
|
244
|
+
cursor.close
|
245
|
+
|
246
|
+
cursor = @conn.parse("DELETE FROM test_table WHERE N=:1")
|
247
|
+
cursor.max_array_size = max_array_size
|
248
|
+
delete_arr = Array.new
|
249
|
+
1.upto(max_array_size) do |i|
|
250
|
+
if i%2 == 0
|
251
|
+
delete_arr << i
|
252
|
+
end
|
253
|
+
end
|
254
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
255
|
+
cursor[1] = delete_arr
|
256
|
+
cursor.exec_array
|
257
|
+
cursor.close
|
258
|
+
|
259
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY N")
|
260
|
+
cursor.exec
|
261
|
+
1.upto( max_array_size ) do |i|
|
262
|
+
if i%2 != 0
|
263
|
+
rv = cursor.fetch
|
264
|
+
assert_equal(rv[0], i)
|
265
|
+
assert_equal(rv[1], i.to_s)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
assert_nil(cursor.fetch)
|
269
|
+
cursor.close
|
270
|
+
|
271
|
+
drop_table('test_table')
|
272
|
+
end
|
273
|
+
|
274
|
+
# update with array bindings
|
275
|
+
def test_array_update
|
276
|
+
drop_table('test_table')
|
277
|
+
sql = <<-EOS
|
278
|
+
CREATE TABLE test_table
|
279
|
+
(N NUMBER(10, 2),
|
280
|
+
V VARCHAR(20))
|
281
|
+
EOS
|
282
|
+
@conn.exec(sql)
|
283
|
+
cursor = @conn.parse("INSERT INTO test_table VALUES (:N, :V)")
|
284
|
+
max_array_size = 10
|
285
|
+
cursor.max_array_size = max_array_size
|
286
|
+
n_arr = Array.new
|
287
|
+
v_arr = Array.new
|
288
|
+
1.upto( max_array_size) do |i|
|
289
|
+
n_arr << i
|
290
|
+
v_arr << i.to_s
|
291
|
+
end
|
292
|
+
cursor.bind_param_array(1, nil, Fixnum)
|
293
|
+
cursor.bind_param_array(2, nil, String)
|
294
|
+
cursor[1] = n_arr
|
295
|
+
cursor[2] = v_arr
|
296
|
+
cursor.exec_array
|
297
|
+
cursor.close
|
298
|
+
|
299
|
+
cursor = @conn.parse("UPDATE test_table SET V=:1 WHERE N=:2")
|
300
|
+
cursor.max_array_size = max_array_size
|
301
|
+
update_arr = Array.new
|
302
|
+
update_v_arr = Array.new
|
303
|
+
1.upto(max_array_size) do |i|
|
304
|
+
if i%2 == 0
|
305
|
+
update_arr << i
|
306
|
+
update_v_arr << (i * 10).to_s
|
307
|
+
end
|
308
|
+
end
|
309
|
+
cursor.bind_param_array(1, nil, String)
|
310
|
+
cursor.bind_param_array(2, nil, Fixnum)
|
311
|
+
cursor[1] = update_v_arr
|
312
|
+
cursor[2] = update_arr
|
313
|
+
cursor.exec_array
|
314
|
+
cursor.close
|
315
|
+
|
316
|
+
cursor = @conn.parse("SELECT * FROM test_table ORDER BY N")
|
317
|
+
cursor.exec
|
318
|
+
1.upto( max_array_size ) do |i|
|
319
|
+
rv = cursor.fetch
|
320
|
+
if i%2 != 0
|
321
|
+
assert_equal(rv[0], i)
|
322
|
+
assert_equal(rv[1], i.to_s)
|
323
|
+
else
|
324
|
+
assert_equal(rv[0], i)
|
325
|
+
assert_equal(rv[1], (i * 10).to_s)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
assert_nil(cursor.fetch)
|
329
|
+
|
330
|
+
cursor.close
|
331
|
+
drop_table('test_table')
|
332
|
+
end
|
333
|
+
end
|