ruby-oci8 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +569 -0
- data/Makefile +51 -0
- data/NEWS +322 -0
- data/README +415 -0
- data/VERSION +1 -0
- data/dist-files +70 -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/ext/oci8/MANIFEST +22 -0
- data/ext/oci8/attr.c +415 -0
- data/ext/oci8/bind.c +194 -0
- data/ext/oci8/const.c +165 -0
- data/ext/oci8/define.c +53 -0
- data/ext/oci8/describe.c +81 -0
- data/ext/oci8/descriptor.c +39 -0
- data/ext/oci8/env.c +276 -0
- data/ext/oci8/error.c +234 -0
- data/ext/oci8/extconf.rb +118 -0
- data/ext/oci8/handle.c +262 -0
- data/ext/oci8/lob.c +386 -0
- data/ext/oci8/oci8.c +137 -0
- data/ext/oci8/oci8.h +345 -0
- data/ext/oci8/ocinumber.c +117 -0
- data/ext/oci8/oraconf.rb +1026 -0
- data/ext/oci8/oradate.c +426 -0
- data/ext/oci8/oranumber.c +445 -0
- data/ext/oci8/param.c +37 -0
- data/ext/oci8/post-config.rb +5 -0
- data/ext/oci8/server.c +182 -0
- data/ext/oci8/session.c +99 -0
- data/ext/oci8/stmt.c +624 -0
- data/ext/oci8/svcctx.c +229 -0
- data/lib/DBD/OCI8/OCI8.rb +549 -0
- data/lib/oci8.rb.in +1605 -0
- data/metaconfig +142 -0
- data/pre-distclean.rb +7 -0
- data/ruby-oci8.gemspec +54 -0
- data/ruby-oci8.spec +62 -0
- data/setup.rb +1331 -0
- data/support/README +4 -0
- data/support/runit/assert.rb +281 -0
- data/support/runit/cui/testrunner.rb +101 -0
- data/support/runit/error.rb +4 -0
- data/support/runit/method_mappable.rb +20 -0
- data/support/runit/robserver.rb +25 -0
- data/support/runit/setuppable.rb +15 -0
- data/support/runit/teardownable.rb +16 -0
- data/support/runit/testcase.rb +113 -0
- data/support/runit/testfailure.rb +25 -0
- data/support/runit/testresult.rb +121 -0
- data/support/runit/testsuite.rb +43 -0
- data/support/runit/version.rb +3 -0
- data/test/README +4 -0
- data/test/config.rb +129 -0
- data/test/test_all.rb +43 -0
- data/test/test_bind_raw.rb +53 -0
- data/test/test_bind_time.rb +191 -0
- data/test/test_break.rb +81 -0
- data/test/test_clob.rb +101 -0
- data/test/test_connstr.rb +80 -0
- data/test/test_dbi.rb +317 -0
- data/test/test_dbi_clob.rb +56 -0
- data/test/test_describe.rb +137 -0
- data/test/test_metadata.rb +243 -0
- data/test/test_oci8.rb +273 -0
- data/test/test_oradate.rb +263 -0
- data/test/test_oranumber.rb +149 -0
- metadata +118 -0
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require 'runit/testcase'
|
3
|
+
require 'runit/cui/testrunner'
|
4
|
+
require File.dirname(__FILE__) + '/config'
|
5
|
+
|
6
|
+
class TestConnStr < RUNIT::TestCase
|
7
|
+
TEST_CASES =
|
8
|
+
[
|
9
|
+
# success cases:
|
10
|
+
# [ 'connect_string', expected result as an array]
|
11
|
+
# error cases:
|
12
|
+
# [ 'connect_string', ExceptionClass]
|
13
|
+
["hr/hr@host/service_name", ["hr", "hr", "host/service_name", nil]],
|
14
|
+
["sys/syspw@host/service_name AS SYSdba ", ["sys", "syspw", "host/service_name", :SYSDBA]],
|
15
|
+
["sys/syspw@host:1521/service_name as sysdba", ["sys", "syspw", "host:1521/service_name", :SYSDBA]],
|
16
|
+
# error cases
|
17
|
+
["service_name", ArgumentError],
|
18
|
+
["", ArgumentError],
|
19
|
+
["foo bar/baz", ArgumentError],
|
20
|
+
["foo@bar/baz", ArgumentError],
|
21
|
+
# raise error in connecting but no error in parse_connect_string.
|
22
|
+
["foo/bar as sysdbaaa", ["foo", "bar", nil, "sysdbaaa"]],
|
23
|
+
|
24
|
+
##
|
25
|
+
## following test cases are contributed by Shiwei Zhang.
|
26
|
+
##
|
27
|
+
#"username/password"
|
28
|
+
["username/password", ["username", "password", nil, nil]],
|
29
|
+
#"username/password@[//]host[:port][/service_name]"
|
30
|
+
["username/password@host", ["username", "password", "host", nil]],
|
31
|
+
["username/password@host/service_name", ["username", "password", "host/service_name", nil]],
|
32
|
+
["username/password@host:1521", ["username", "password", "host:1521", nil]],
|
33
|
+
["username/password@host:1521/service_name", ["username", "password", "host:1521/service_name", nil]],
|
34
|
+
["username/password@//host", ["username", "password", "//host", nil]],
|
35
|
+
["username/password@//host/service_name", ["username", "password", "//host/service_name", nil]],
|
36
|
+
["username/password@//host:1521", ["username", "password", "//host:1521", nil]],
|
37
|
+
["username/password@//host:1521/service_name", ["username", "password", "//host:1521/service_name", nil]],
|
38
|
+
#"username/password as{sysoper|sysdba}"
|
39
|
+
["username/password as sysoper", ["username", "password", nil, :SYSOPER]],
|
40
|
+
["username/password as sysdba", ["username", "password", nil, :SYSDBA]],
|
41
|
+
#"username/password@[//]host[:port][/service_name] as {sysoper|sysdba}"
|
42
|
+
["username/password@host as sysoper", ["username", "password", "host", :SYSOPER]],
|
43
|
+
["username/password@host as sysdba", ["username", "password", "host", :SYSDBA]],
|
44
|
+
["username/password@host/service_name as sysoper", ["username", "password", "host/service_name", :SYSOPER]],
|
45
|
+
["username/password@host/service_name as sysdba", ["username", "password", "host/service_name", :SYSDBA]],
|
46
|
+
["username/password@host:1521 as sysoper", ["username", "password", "host:1521", :SYSOPER]],
|
47
|
+
["username/password@host:1521 as sysdba", ["username", "password", "host:1521", :SYSDBA]],
|
48
|
+
["username/password@host:1521/service_name as sysoper", ["username", "password", "host:1521/service_name", :SYSOPER]],
|
49
|
+
["username/password@host:1521/service_name as sysdba", ["username", "password", "host:1521/service_name", :SYSDBA]],
|
50
|
+
["username/password@//host as sysoper", ["username", "password", "//host", :SYSOPER]],
|
51
|
+
["username/password@//host as sysdba", ["username", "password", "//host", :SYSDBA]],
|
52
|
+
["username/password@//host/service_name as sysoper", ["username", "password", "//host/service_name", :SYSOPER]],
|
53
|
+
["username/password@//host/service_name as sysdba", ["username", "password", "//host/service_name", :SYSDBA]],
|
54
|
+
["username/password@//host:1521 as sysoper", ["username", "password", "//host:1521", :SYSOPER]],
|
55
|
+
["username/password@//host:1521 as sysdba", ["username", "password", "//host:1521", :SYSDBA]],
|
56
|
+
["username/password@//host:1521/service_name as sysoper", ["username", "password", "//host:1521/service_name", :SYSOPER]],
|
57
|
+
["username/password@//host:1521/service_name as sysdba", ["username", "password", "//host:1521/service_name", :SYSDBA]],
|
58
|
+
["/passwd@192.168.19.19:1521/orcl as sysdba", ["", "passwd", "192.168.19.19:1521/orcl", :SYSDBA]],
|
59
|
+
["/", [nil, nil, nil, nil]],
|
60
|
+
["/ as sysdba", [nil, nil, nil, :SYSDBA]],
|
61
|
+
]
|
62
|
+
|
63
|
+
def test_connstr
|
64
|
+
obj = OCI8.allocate # create an uninitialized object.
|
65
|
+
TEST_CASES.each do |test_case|
|
66
|
+
case test_case[1]
|
67
|
+
when Array
|
68
|
+
# use instance_eval to call a private method parse_connect_string.
|
69
|
+
result = obj.instance_eval { parse_connect_string(test_case[0]) }
|
70
|
+
assert_equal(test_case[1], result, test_case[0])
|
71
|
+
when Class
|
72
|
+
assert_exception(test_case[1], test_case[0]) do
|
73
|
+
result = obj.instance_eval { parse_connect_string(test_case[0]) }
|
74
|
+
end
|
75
|
+
else
|
76
|
+
raise "unsupported testcase"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/test/test_dbi.rb
ADDED
@@ -0,0 +1,317 @@
|
|
1
|
+
require 'dbi'
|
2
|
+
require 'oci8'
|
3
|
+
require 'runit/testcase'
|
4
|
+
require 'runit/cui/testrunner'
|
5
|
+
require File.dirname(__FILE__) + '/config'
|
6
|
+
|
7
|
+
class TestDBI < RUNIT::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@dbh = get_dbi_connection()
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_select
|
14
|
+
drop_table('test_table')
|
15
|
+
sql = <<-EOS
|
16
|
+
CREATE TABLE test_table
|
17
|
+
(C CHAR(10) NOT NULL,
|
18
|
+
V VARCHAR2(20),
|
19
|
+
N NUMBER(10, 2),
|
20
|
+
D DATE)
|
21
|
+
STORAGE (
|
22
|
+
INITIAL 4k
|
23
|
+
NEXT 4k
|
24
|
+
MINEXTENTS 1
|
25
|
+
MAXEXTENTS UNLIMITED
|
26
|
+
PCTINCREASE 0)
|
27
|
+
EOS
|
28
|
+
@dbh.do(sql)
|
29
|
+
sth = @dbh.prepare("INSERT INTO test_table VALUES (?, ?, ?, ?)")
|
30
|
+
1.upto(10) do |i|
|
31
|
+
sth.execute(format("%10d", i * 10), i.to_s, i, nil)
|
32
|
+
end
|
33
|
+
sth = @dbh.execute("SELECT * FROM test_table ORDER BY c")
|
34
|
+
assert_equal(["C", "V", "N", "D"], sth.column_names)
|
35
|
+
1.upto(10) do |i|
|
36
|
+
rv = sth.fetch
|
37
|
+
assert_equal(format("%10d", i * 10), rv[0])
|
38
|
+
assert_equal(i.to_s, rv[1])
|
39
|
+
assert_equal(i, rv[2])
|
40
|
+
end
|
41
|
+
assert_nil(sth.fetch)
|
42
|
+
assert_equal(10, @dbh.select_one("SELECT COUNT(*) FROM test_table")[0])
|
43
|
+
@dbh.rollback()
|
44
|
+
assert_equal(0, @dbh.select_one("SELECT COUNT(*) FROM test_table")[0])
|
45
|
+
drop_table('test_table')
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_ref_cursor
|
49
|
+
drop_table('test_table')
|
50
|
+
sql = <<-EOS
|
51
|
+
CREATE TABLE test_table
|
52
|
+
(C CHAR(10) NOT NULL,
|
53
|
+
V VARCHAR2(20),
|
54
|
+
N NUMBER(10, 2),
|
55
|
+
D DATE)
|
56
|
+
STORAGE (
|
57
|
+
INITIAL 4k
|
58
|
+
NEXT 4k
|
59
|
+
MINEXTENTS 1
|
60
|
+
MAXEXTENTS UNLIMITED
|
61
|
+
PCTINCREASE 0)
|
62
|
+
EOS
|
63
|
+
@dbh.do(sql)
|
64
|
+
sth = @dbh.prepare("INSERT INTO test_table VALUES (?, ?, ?, ?)")
|
65
|
+
1.upto(10) do |i|
|
66
|
+
sth.execute(format("%10d", i * 10), i.to_s, i, nil)
|
67
|
+
end
|
68
|
+
# get a ref cursor
|
69
|
+
plsql = @dbh.execute("BEGIN OPEN ? FOR SELECT * FROM test_table ORDER BY c; END;", DBI::StatementHandle)
|
70
|
+
sth = plsql.func(:bind_value, 1)
|
71
|
+
assert_equal(["C", "V", "N", "D"], sth.column_names)
|
72
|
+
1.upto(10) do |i|
|
73
|
+
rv = sth.fetch
|
74
|
+
assert_equal(format("%10d", i * 10), rv[0])
|
75
|
+
assert_equal(i.to_s, rv[1])
|
76
|
+
assert_equal(i, rv[2])
|
77
|
+
end
|
78
|
+
@dbh.rollback()
|
79
|
+
drop_table('test_table')
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_define
|
83
|
+
drop_table('test_table')
|
84
|
+
sql = <<-EOS
|
85
|
+
CREATE TABLE test_table
|
86
|
+
(C CHAR(10) NOT NULL,
|
87
|
+
V VARCHAR2(20),
|
88
|
+
N NUMBER(10, 2),
|
89
|
+
D1 DATE, D2 DATE, D3 DATE, D4 DATE,
|
90
|
+
INT NUMBER(30), BIGNUM NUMBER(30))
|
91
|
+
STORAGE (
|
92
|
+
INITIAL 4k
|
93
|
+
NEXT 4k
|
94
|
+
MINEXTENTS 1
|
95
|
+
MAXEXTENTS UNLIMITED
|
96
|
+
PCTINCREASE 0)
|
97
|
+
EOS
|
98
|
+
@dbh.do(sql)
|
99
|
+
sth = @dbh.prepare("INSERT INTO test_table VALUES (:C, :V, :N, :D1, :D2, :D3, :D4, :INT, :BIGNUM)")
|
100
|
+
1.upto(10) do |i|
|
101
|
+
if i == 1
|
102
|
+
dt = nil
|
103
|
+
v = ''
|
104
|
+
else
|
105
|
+
dt = OraDate.new(2000 + i, 8, 3, 23, 59, 59)
|
106
|
+
v = i.to_s
|
107
|
+
end
|
108
|
+
sth.execute(format("%10d", i * 10), v, i, dt, dt, dt, dt, i, i)
|
109
|
+
end
|
110
|
+
sth.finish
|
111
|
+
sth = @dbh.prepare("SELECT * FROM test_table ORDER BY c")
|
112
|
+
sth.func(:define, 5, Time) # define 5th column as Time
|
113
|
+
sth.func(:define, 6, Date) # define 6th column as Date
|
114
|
+
sth.func(:define, 7, DateTime) if defined? DateTime # define 7th column as DateTime
|
115
|
+
sth.func(:define, 8, Integer) # define 8th column as Integer
|
116
|
+
sth.func(:define, 9, Bignum) # define 9th column as Bignum
|
117
|
+
sth.execute
|
118
|
+
assert_equal(["C", "V", "N", "D1", "D2", "D3", "D4", "INT", "BIGNUM"], sth.column_info.collect {|cl| cl.name})
|
119
|
+
1.upto(10) do |i|
|
120
|
+
rv = sth.fetch
|
121
|
+
assert_equal(format("%10d", i * 10), rv[0])
|
122
|
+
assert_equal(i, rv[2])
|
123
|
+
if i == 1
|
124
|
+
assert_nil(rv[1])
|
125
|
+
assert_nil(rv[3])
|
126
|
+
assert_nil(rv[4])
|
127
|
+
assert_nil(rv[5])
|
128
|
+
assert_nil(rv[6])
|
129
|
+
else
|
130
|
+
assert_equal(i.to_s, rv[1])
|
131
|
+
dt = OraDate.new(2000 + i, 8, 3, 23, 59, 59)
|
132
|
+
assert_equal(dt, rv[3])
|
133
|
+
assert_equal(dt.to_time, rv[4])
|
134
|
+
assert_equal(dt.to_date, rv[5])
|
135
|
+
assert_equal(dt.to_datetime, rv[6]) if defined? DateTime
|
136
|
+
assert_instance_of(Time, rv[4])
|
137
|
+
assert_instance_of(Date, rv[5])
|
138
|
+
assert_instance_of(DateTime, rv[6]) if defined? DateTime
|
139
|
+
end
|
140
|
+
assert_equal(i, rv[7])
|
141
|
+
assert_equal(i, rv[8])
|
142
|
+
end
|
143
|
+
assert_nil(sth.fetch)
|
144
|
+
sth.finish
|
145
|
+
drop_table('test_table')
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_bind_dbi_data_type
|
149
|
+
inval = DBI::Date.new(2004, 3, 20)
|
150
|
+
sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Date, inval)
|
151
|
+
outval = sth.func(:bind_value, 1)
|
152
|
+
assert_instance_of(DBI::Date, outval)
|
153
|
+
assert_equal(inval.to_time, outval.to_time)
|
154
|
+
|
155
|
+
inval = DBI::Timestamp.new(2004, 3, 20, 18, 26, 33)
|
156
|
+
sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Timestamp, inval)
|
157
|
+
outval = sth.func(:bind_value, 1)
|
158
|
+
assert_instance_of(DBI::Timestamp, outval)
|
159
|
+
assert_equal(inval.to_time, outval.to_time)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_column_info
|
163
|
+
# data_size factor for nchar charset_form.
|
164
|
+
sth = @dbh.execute("select CAST('1' AS NCHAR(1)) from dual")
|
165
|
+
cfrm = sth.column_info[0]['precision']
|
166
|
+
if $oracle_version >= 900
|
167
|
+
# data_size factor for char semantics.
|
168
|
+
sth = @dbh.execute("select CAST('1' AS CHAR(1 char)) from dual")
|
169
|
+
csem = sth.column_info[0]['precision']
|
170
|
+
end
|
171
|
+
|
172
|
+
coldef =
|
173
|
+
[
|
174
|
+
# oracle_version, definition, sql_type, type_name, nullable, precision,scale,indexed,primary,unique,default
|
175
|
+
[800, "CHAR(10) NOT NULL", DBI::SQL_CHAR, 'CHAR', false, 10, nil, true, true, true, nil],
|
176
|
+
[900, "CHAR(10 CHAR)", DBI::SQL_CHAR, 'CHAR', true, 10 * csem, nil, false,false,false,nil],
|
177
|
+
[800, "NCHAR(10)", DBI::SQL_CHAR, 'NCHAR', true, 10 * cfrm, nil, true, false,true, nil],
|
178
|
+
[800, "VARCHAR2(10) DEFAULT 'a''b'", DBI::SQL_VARCHAR, 'VARCHAR2', true, 10, nil, true, false,false, "a'b"],
|
179
|
+
[900, "VARCHAR2(10 CHAR)", DBI::SQL_VARCHAR, 'VARCHAR2', true, 10 * csem, nil, false,false,false,nil],
|
180
|
+
[800, "NVARCHAR2(10)", DBI::SQL_VARCHAR, 'NVARCHAR2',true, 10 * cfrm, nil, false,false,false,nil],
|
181
|
+
[800, "RAW(10)", DBI::SQL_VARBINARY, 'RAW', true, 10, nil, false,false,false,nil],
|
182
|
+
[800, "CLOB", DBI::SQL_CLOB, 'CLOB', true, 4000, nil, false,false,false,nil],
|
183
|
+
[800, "NCLOB", DBI::SQL_CLOB, 'NCLOB', true, 4000, nil, false,false,false,nil],
|
184
|
+
[800, "BLOB", DBI::SQL_BLOB, 'BLOB', true, 4000, nil, false,false,false,nil],
|
185
|
+
[800, "BFILE", DBI::SQL_BLOB, 'BFILE', true, 4000, nil, false,false,false,nil],
|
186
|
+
[800, "NUMBER", DBI::SQL_NUMERIC, 'NUMBER', true, 38, nil, false,false,false,nil],
|
187
|
+
[800, "NUMBER(10)", DBI::SQL_NUMERIC, 'NUMBER', true, 10, 0, false,false,false,nil],
|
188
|
+
[800, "NUMBER(10,2)", DBI::SQL_NUMERIC, 'NUMBER', true, 10, 2, false,false,false,nil],
|
189
|
+
[800, "FLOAT", DBI::SQL_FLOAT, 'FLOAT', true, (126 * 0.30103).ceil, nil, false,false,false,nil],
|
190
|
+
[800, "FLOAT(10)", DBI::SQL_FLOAT, 'FLOAT', true, (10 * 0.30103).ceil, nil, false,false,false,nil],
|
191
|
+
[1000,"BINARY_FLOAT", DBI::SQL_FLOAT, 'BINARY_FLOAT', true, 7, nil, false,false,false,nil],
|
192
|
+
[1000,"BINARY_DOUBLE", DBI::SQL_DOUBLE, 'BINARY_DOUBLE', true, 16, nil, false,false,false,nil],
|
193
|
+
[800, "DATE", DBI::SQL_DATE, 'DATE', true, 19, nil, false,false,false,nil],
|
194
|
+
[900, "TIMESTAMP", DBI::SQL_TIMESTAMP, 'TIMESTAMP', true, 20 + 6, nil, false,false,false,nil],
|
195
|
+
[900, "TIMESTAMP(9)", DBI::SQL_TIMESTAMP, 'TIMESTAMP', true, 20 + 9, nil, false,false,false,nil],
|
196
|
+
[900, "TIMESTAMP WITH TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH TIME ZONE', true, 27 + 6, nil, false,false,false,nil],
|
197
|
+
[900, "TIMESTAMP(9) WITH TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH TIME ZONE', true, 27 + 9, nil, false,false,false,nil],
|
198
|
+
[900, "TIMESTAMP WITH LOCAL TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH LOCAL TIME ZONE', true, 20 + 6, nil, false,false,false,nil],
|
199
|
+
[900, "TIMESTAMP(9) WITH LOCAL TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH LOCAL TIME ZONE', true, 20 + 9, nil, false,false,false,nil],
|
200
|
+
[900, "INTERVAL YEAR TO MONTH", DBI::SQL_OTHER, 'INTERVAL YEAR TO MONTH', true, 2 + 3, nil, false,false,false,nil],
|
201
|
+
[900, "INTERVAL YEAR(4) TO MONTH", DBI::SQL_OTHER, 'INTERVAL YEAR TO MONTH', true, 4 + 3, nil, false,false,false,nil],
|
202
|
+
[900, "INTERVAL DAY TO SECOND", DBI::SQL_OTHER, 'INTERVAL DAY TO SECOND', true, 2 + 10 + 6, nil, false,false,false,nil],
|
203
|
+
[900, "INTERVAL DAY(4) TO SECOND(9)",DBI::SQL_OTHER, 'INTERVAL DAY TO SECOND', true, 4 + 10 + 9, nil, false,false,false,nil],
|
204
|
+
]
|
205
|
+
|
206
|
+
coldef.reject! do |c| c[0] > $oracle_version end
|
207
|
+
|
208
|
+
drop_table('test_table')
|
209
|
+
@dbh.execute(<<-EOS)
|
210
|
+
CREATE TABLE test_table (#{i = 0; coldef.collect do |c| i += 1; "C#{i} " + c[1] + (c[8] ? ' PRIMARY KEY' : ''); end.join(',')})
|
211
|
+
STORAGE (
|
212
|
+
INITIAL 100k
|
213
|
+
NEXT 100k
|
214
|
+
MINEXTENTS 1
|
215
|
+
MAXEXTENTS UNLIMITED
|
216
|
+
PCTINCREASE 0)
|
217
|
+
EOS
|
218
|
+
coldef.each_with_index do |col, idx|
|
219
|
+
next if col[8] # primary
|
220
|
+
if col[7] # indexed
|
221
|
+
@dbh.execute(<<-EOS)
|
222
|
+
CREATE #{col[9] ? 'UNIQUE' : ''} INDEX test_table_idx#{idx + 1} ON test_table(C#{idx + 1})
|
223
|
+
STORAGE (
|
224
|
+
INITIAL 100k
|
225
|
+
NEXT 100k
|
226
|
+
MINEXTENTS 1
|
227
|
+
MAXEXTENTS UNLIMITED
|
228
|
+
PCTINCREASE 0)
|
229
|
+
EOS
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
@dbh.columns('test_table').each_with_index do |ci, i|
|
234
|
+
assert_equal("C#{i + 1}", ci['name'], "'#{coldef[i][1]}': name")
|
235
|
+
assert_equal(coldef[i][2], ci['sql_type'], "'#{coldef[i][1]}': sql_type")
|
236
|
+
assert_equal(coldef[i][3], ci['type_name'], "'#{coldef[i][1]}': type_name")
|
237
|
+
assert_equal(coldef[i][4], ci['nullable'], "'#{coldef[i][1]}': nullable")
|
238
|
+
assert_equal(coldef[i][5], ci['precision'], "'#{coldef[i][1]}': precision")
|
239
|
+
assert_equal(coldef[i][6], ci['scale'], "'#{coldef[i][1]}': scale")
|
240
|
+
assert_equal(coldef[i][7], ci['indexed'], "'#{coldef[i][1]}': indexed")
|
241
|
+
assert_equal(coldef[i][8], ci['primary'], "'#{coldef[i][1]}': primary")
|
242
|
+
assert_equal(coldef[i][9], ci['unique'], "'#{coldef[i][1]}': unique")
|
243
|
+
assert_equal(coldef[i][10],ci['default'], "'#{coldef[i][1]}': default")
|
244
|
+
end
|
245
|
+
|
246
|
+
# temporarily change OCI8::BindType::Mapping.
|
247
|
+
saved_mapping = {}
|
248
|
+
[OCI8::SQLT_TIMESTAMP_TZ,
|
249
|
+
OCI8::SQLT_TIMESTAMP_LTZ,
|
250
|
+
OCI8::SQLT_INTERVAL_YM,
|
251
|
+
OCI8::SQLT_INTERVAL_DS].each do |sqlt_type|
|
252
|
+
saved_mapping[sqlt_type] = OCI8::BindType::Mapping[sqlt_type]
|
253
|
+
OCI8::BindType::Mapping[sqlt_type] = OCI8::BindType::String
|
254
|
+
end
|
255
|
+
begin
|
256
|
+
sth = @dbh.execute("SELECT * FROM test_table")
|
257
|
+
ensure
|
258
|
+
saved_mapping.each do |key, val|
|
259
|
+
OCI8::BindType::Mapping[key] = val
|
260
|
+
end
|
261
|
+
end
|
262
|
+
sth.column_info.each_with_index do |ci, i|
|
263
|
+
assert_equal("C#{i + 1}", ci['name'], "'#{coldef[i][1]}': name")
|
264
|
+
assert_equal(coldef[i][2], ci['sql_type'], "'#{coldef[i][1]}': sql_type")
|
265
|
+
assert_equal(coldef[i][3], ci['type_name'], "'#{coldef[i][1]}': type_name")
|
266
|
+
assert_equal(coldef[i][4], ci['nullable'], "'#{coldef[i][1]}': nullable")
|
267
|
+
assert_equal(coldef[i][5], ci['precision'], "'#{coldef[i][1]}': precision")
|
268
|
+
assert_equal(coldef[i][6], ci['scale'], "'#{coldef[i][1]}': scale")
|
269
|
+
assert_equal(nil, ci['indexed'], "'#{coldef[i][1]}': indexed")
|
270
|
+
assert_equal(nil, ci['primary'], "'#{coldef[i][1]}': primary")
|
271
|
+
assert_equal(nil, ci['unique'], "'#{coldef[i][1]}': unique")
|
272
|
+
assert_equal(nil, ci['default'], "'#{coldef[i][1]}': default")
|
273
|
+
end
|
274
|
+
|
275
|
+
drop_table('test_table')
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_column_info_of_tab
|
279
|
+
coldef =
|
280
|
+
[
|
281
|
+
# name, sql_type, type_name, nullable,precision,scale,indexed,primary,unique,default
|
282
|
+
["TNAME", DBI::SQL_VARCHAR,'VARCHAR2',false, 30, nil, false, false, false, nil],
|
283
|
+
["TABTYPE", DBI::SQL_VARCHAR,'VARCHAR2',true, 7, nil, false, false, false, nil],
|
284
|
+
["CLUSTERID",DBI::SQL_NUMERIC,'NUMBER', true, 38, nil, false, false, false, nil],
|
285
|
+
]
|
286
|
+
@dbh.columns('tab').each_with_index do |ci, i|
|
287
|
+
assert_equal(coldef[i][0], ci['name'], "'#{coldef[i][0]}': name")
|
288
|
+
assert_equal(coldef[i][1], ci['sql_type'], "'#{coldef[i][0]}': sql_type")
|
289
|
+
assert_equal(coldef[i][2], ci['type_name'], "'#{coldef[i][0]}': type_name")
|
290
|
+
assert_equal(coldef[i][3], ci['nullable'], "'#{coldef[i][0]}': nullable")
|
291
|
+
assert_equal(coldef[i][4], ci['precision'], "'#{coldef[i][0]}': precision")
|
292
|
+
assert_equal(coldef[i][5], ci['scale'], "'#{coldef[i][0]}': scale")
|
293
|
+
assert_equal(coldef[i][6], ci['indexed'], "'#{coldef[i][0]}': indexed")
|
294
|
+
assert_equal(coldef[i][7], ci['primary'], "'#{coldef[i][0]}': primary")
|
295
|
+
assert_equal(coldef[i][8], ci['unique'], "'#{coldef[i][0]}': unique")
|
296
|
+
assert_equal(coldef[i][9], ci['default'], "'#{coldef[i][0]}': default")
|
297
|
+
end
|
298
|
+
|
299
|
+
@dbh.execute("SELECT * FROM tab").column_info.each_with_index do |ci, i|
|
300
|
+
assert_equal(coldef[i][0], ci['name'], "'#{coldef[i][0]}': name")
|
301
|
+
assert_equal(coldef[i][1], ci['sql_type'], "'#{coldef[i][0]}': sql_type")
|
302
|
+
assert_equal(coldef[i][2], ci['type_name'], "'#{coldef[i][0]}': type_name")
|
303
|
+
assert_equal(coldef[i][3], ci['nullable'], "'#{coldef[i][0]}': nullable")
|
304
|
+
assert_equal(coldef[i][4], ci['precision'], "'#{coldef[i][0]}': precision")
|
305
|
+
assert_equal(coldef[i][5], ci['scale'], "'#{coldef[i][0]}': scale")
|
306
|
+
assert_equal(nil, ci['indexed'], "'#{coldef[i][0]}': indexed")
|
307
|
+
assert_equal(nil, ci['primary'], "'#{coldef[i][0]}': primary")
|
308
|
+
assert_equal(nil, ci['unique'], "'#{coldef[i][0]}': unique")
|
309
|
+
assert_equal(nil, ci['default'], "'#{coldef[i][0]}': default")
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
end # TestDBI
|
314
|
+
|
315
|
+
if $0 == __FILE__
|
316
|
+
RUNIT::CUI::TestRunner.run(TestDBI.suite())
|
317
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'dbi'
|
2
|
+
require 'oci8'
|
3
|
+
require 'runit/testcase'
|
4
|
+
require 'runit/cui/testrunner'
|
5
|
+
require File.dirname(__FILE__) + '/config'
|
6
|
+
|
7
|
+
class TestDbiCLob < RUNIT::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@dbh = get_dbi_connection()
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_insert
|
14
|
+
@dbh.do("DELETE FROM test_clob WHERE filename = :1", $lobfile)
|
15
|
+
|
16
|
+
# insert an empty clob and get the rowid.
|
17
|
+
rowid = @dbh.execute("INSERT INTO test_clob(filename, content) VALUES (:1, EMPTY_CLOB())", $lobfile) do |sth|
|
18
|
+
sth.func(:rowid)
|
19
|
+
end
|
20
|
+
lob = @dbh.select_one("SELECT content FROM test_clob WHERE filename = :1 FOR UPDATE", $lobfile)[0]
|
21
|
+
begin
|
22
|
+
open($lobfile) do |f|
|
23
|
+
while f.gets()
|
24
|
+
lob.write($_)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
ensure
|
28
|
+
lob.close()
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_read
|
33
|
+
test_insert() # first insert data.
|
34
|
+
lob = @dbh.select_one("SELECT content FROM test_clob WHERE filename = :1 FOR UPDATE", $lobfile)[0]
|
35
|
+
begin
|
36
|
+
open($lobfile) do |f|
|
37
|
+
while buf = lob.read($lobreadnum)
|
38
|
+
fbuf = f.read(buf.size)
|
39
|
+
assert_equal(fbuf, buf)
|
40
|
+
end
|
41
|
+
assert_equal(nil, buf)
|
42
|
+
assert_equal(true, f.eof?)
|
43
|
+
end
|
44
|
+
ensure
|
45
|
+
lob.close()
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def teardown
|
50
|
+
@dbh.disconnect()
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
if $0 == __FILE__
|
55
|
+
RUNIT::CUI::TestRunner.run(TestCLob.suite())
|
56
|
+
end
|