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/test_dbi.rb
ADDED
@@ -0,0 +1,366 @@
|
|
1
|
+
require 'dbi'
|
2
|
+
require 'oci8'
|
3
|
+
require 'test/unit'
|
4
|
+
require File.dirname(__FILE__) + '/config'
|
5
|
+
|
6
|
+
class TestDBI < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@dbh = get_dbi_connection()
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
@dbh.disconnect
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_select
|
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
|
+
STORAGE (
|
25
|
+
INITIAL 4k
|
26
|
+
NEXT 4k
|
27
|
+
MINEXTENTS 1
|
28
|
+
MAXEXTENTS UNLIMITED
|
29
|
+
PCTINCREASE 0)
|
30
|
+
EOS
|
31
|
+
@dbh.do(sql)
|
32
|
+
sth = @dbh.prepare("INSERT INTO test_table VALUES (?, ?, ?, ?)")
|
33
|
+
1.upto(10) do |i|
|
34
|
+
sth.execute(format("%10d", i * 10), i.to_s, i, nil)
|
35
|
+
end
|
36
|
+
sth = @dbh.execute("SELECT * FROM test_table ORDER BY c")
|
37
|
+
assert_equal(["C", "V", "N", "D"], sth.column_names)
|
38
|
+
1.upto(10) do |i|
|
39
|
+
rv = sth.fetch
|
40
|
+
assert_equal(format("%10d", i * 10), rv[0])
|
41
|
+
assert_equal(i.to_s, rv[1])
|
42
|
+
assert_equal(i, rv[2])
|
43
|
+
end
|
44
|
+
assert_nil(sth.fetch)
|
45
|
+
assert_equal(10, @dbh.select_one("SELECT COUNT(*) FROM test_table")[0])
|
46
|
+
@dbh.rollback()
|
47
|
+
assert_equal(0, @dbh.select_one("SELECT COUNT(*) FROM test_table")[0])
|
48
|
+
drop_table('test_table')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_ref_cursor
|
52
|
+
drop_table('test_table')
|
53
|
+
sql = <<-EOS
|
54
|
+
CREATE TABLE test_table
|
55
|
+
(C CHAR(10) NOT NULL,
|
56
|
+
V VARCHAR2(20),
|
57
|
+
N NUMBER(10, 2),
|
58
|
+
D DATE)
|
59
|
+
STORAGE (
|
60
|
+
INITIAL 4k
|
61
|
+
NEXT 4k
|
62
|
+
MINEXTENTS 1
|
63
|
+
MAXEXTENTS UNLIMITED
|
64
|
+
PCTINCREASE 0)
|
65
|
+
EOS
|
66
|
+
@dbh.do(sql)
|
67
|
+
sth = @dbh.prepare("INSERT INTO test_table VALUES (?, ?, ?, ?)")
|
68
|
+
1.upto(10) do |i|
|
69
|
+
sth.execute(format("%10d", i * 10), i.to_s, i, nil)
|
70
|
+
end
|
71
|
+
# get a ref cursor
|
72
|
+
plsql = @dbh.execute("BEGIN OPEN ? FOR SELECT * FROM test_table ORDER BY c; END;", DBI::StatementHandle)
|
73
|
+
sth = plsql.func(:bind_value, 1)
|
74
|
+
assert_equal(["C", "V", "N", "D"], sth.column_names)
|
75
|
+
1.upto(10) do |i|
|
76
|
+
rv = sth.fetch
|
77
|
+
assert_equal(format("%10d", i * 10), rv[0])
|
78
|
+
assert_equal(i.to_s, rv[1])
|
79
|
+
assert_equal(i, rv[2])
|
80
|
+
end
|
81
|
+
@dbh.rollback()
|
82
|
+
drop_table('test_table')
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_define
|
86
|
+
drop_table('test_table')
|
87
|
+
sql = <<-EOS
|
88
|
+
CREATE TABLE test_table
|
89
|
+
(C CHAR(10) NOT NULL,
|
90
|
+
V VARCHAR2(20),
|
91
|
+
N NUMBER(10, 2),
|
92
|
+
D1 DATE, D2 DATE, D3 DATE, D4 DATE,
|
93
|
+
INT NUMBER(30), BIGNUM NUMBER(30))
|
94
|
+
STORAGE (
|
95
|
+
INITIAL 4k
|
96
|
+
NEXT 4k
|
97
|
+
MINEXTENTS 1
|
98
|
+
MAXEXTENTS UNLIMITED
|
99
|
+
PCTINCREASE 0)
|
100
|
+
EOS
|
101
|
+
@dbh.do(sql)
|
102
|
+
sth = @dbh.prepare("INSERT INTO test_table VALUES (:C, :V, :N, :D1, :D2, :D3, :D4, :INT, :BIGNUM)")
|
103
|
+
1.upto(10) do |i|
|
104
|
+
if i == 1
|
105
|
+
if OCI8::oracle_client_version >= OCI8::ORAVER_9_0
|
106
|
+
dt = nil
|
107
|
+
v = ''
|
108
|
+
sth.execute(format("%10d", i * 10), v, i, dt, dt, dt, dt, i, i)
|
109
|
+
else
|
110
|
+
# explicitly bind nil with datatype to avoid ORA-01475 when using Oracle 8i.
|
111
|
+
sth.bind_param(1, format("%10d", i * 10))
|
112
|
+
sth.bind_param(2, '')
|
113
|
+
sth.bind_param(3, i)
|
114
|
+
sth.bind_param(4, nil, {'type' => OraDate})
|
115
|
+
sth.bind_param(5, nil, {'type' => OraDate})
|
116
|
+
sth.bind_param(6, nil, {'type' => OraDate})
|
117
|
+
sth.bind_param(7, nil, {'type' => OraDate})
|
118
|
+
sth.bind_param(8, i)
|
119
|
+
sth.bind_param(9, i)
|
120
|
+
sth.execute
|
121
|
+
end
|
122
|
+
else
|
123
|
+
dt = OraDate.new(2000 + i, 8, 3, 23, 59, 59)
|
124
|
+
v = i.to_s
|
125
|
+
sth.execute(format("%10d", i * 10), v, i, dt, dt, dt, dt, i, i)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
sth.finish
|
129
|
+
sth = @dbh.prepare("SELECT * FROM test_table ORDER BY c")
|
130
|
+
sth.func(:define, 5, Time) # define 5th column as Time
|
131
|
+
sth.func(:define, 6, Date) # define 6th column as Date
|
132
|
+
sth.func(:define, 7, DateTime) # define 7th column as DateTime
|
133
|
+
sth.func(:define, 8, Integer) # define 8th column as Integer
|
134
|
+
sth.func(:define, 9, Bignum) # define 9th column as Bignum
|
135
|
+
sth.execute
|
136
|
+
assert_equal(["C", "V", "N", "D1", "D2", "D3", "D4", "INT", "BIGNUM"], sth.column_info.collect {|cl| cl.name})
|
137
|
+
1.upto(10) do |i|
|
138
|
+
rv = sth.fetch
|
139
|
+
assert_equal(format("%10d", i * 10), rv[0])
|
140
|
+
assert_equal(i, rv[2])
|
141
|
+
if i == 1
|
142
|
+
assert_nil(rv[1])
|
143
|
+
assert_nil(rv[3])
|
144
|
+
assert_nil(rv[4])
|
145
|
+
assert_nil(rv[5])
|
146
|
+
assert_nil(rv[6])
|
147
|
+
else
|
148
|
+
assert_equal(i.to_s, rv[1])
|
149
|
+
tm = Time.local(2000 + i, 8, 3, 23, 59, 59)
|
150
|
+
dt = Date.civil(2000 + i, 8, 3)
|
151
|
+
dttm = DateTime.civil(2000 + i, 8, 3, 23, 59, 59, Time.now.utc_offset.to_r/86400)
|
152
|
+
assert_equal(tm, rv[3])
|
153
|
+
assert_equal(tm, rv[4])
|
154
|
+
assert_equal(dt, rv[5])
|
155
|
+
assert_equal(dttm, rv[6])
|
156
|
+
assert_instance_of(Time, rv[4])
|
157
|
+
assert_instance_of(Date, rv[5])
|
158
|
+
assert_instance_of(DateTime, rv[6])
|
159
|
+
end
|
160
|
+
assert_equal(i, rv[7])
|
161
|
+
assert_equal(i, rv[8])
|
162
|
+
end
|
163
|
+
assert_nil(sth.fetch)
|
164
|
+
sth.finish
|
165
|
+
drop_table('test_table')
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_bind_dbi_data_type
|
169
|
+
begin
|
170
|
+
if DBI::VERSION >= '0.4.0'
|
171
|
+
# suppress deprecated warnings while running this test.
|
172
|
+
saved_action = Deprecated.action
|
173
|
+
Deprecated.set_action(Proc.new {})
|
174
|
+
end
|
175
|
+
|
176
|
+
inval = DBI::Date.new(2004, 3, 20)
|
177
|
+
sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Date, inval)
|
178
|
+
outval = sth.func(:bind_value, 1)
|
179
|
+
assert_instance_of(DBI::Date, outval)
|
180
|
+
assert_equal(inval.to_time, outval.to_time)
|
181
|
+
|
182
|
+
inval = DBI::Timestamp.new(2004, 3, 20, 18, 26, 33)
|
183
|
+
sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Timestamp, inval)
|
184
|
+
outval = sth.func(:bind_value, 1)
|
185
|
+
assert_instance_of(DBI::Timestamp, outval)
|
186
|
+
assert_equal(inval.to_time, outval.to_time)
|
187
|
+
ensure
|
188
|
+
Deprecated.set_action(saved_action) if saved_action
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_column_info
|
193
|
+
if $oracle_version < OCI8::ORAVER_8_1
|
194
|
+
begin
|
195
|
+
@dbh.columns('tab')
|
196
|
+
rescue RuntimeError
|
197
|
+
assert_equal("This feature is unavailable on Oracle 8.0", $!.to_s)
|
198
|
+
end
|
199
|
+
return
|
200
|
+
end
|
201
|
+
|
202
|
+
# data_size factor for nchar charset_form.
|
203
|
+
sth = @dbh.execute("select N'1' from dual")
|
204
|
+
cfrm = sth.column_info[0]['precision']
|
205
|
+
if $oracle_version >= OCI8::ORAVER_9_0
|
206
|
+
# data_size factor for char semantics.
|
207
|
+
sth = @dbh.execute("select CAST('1' AS CHAR(1 char)) from dual")
|
208
|
+
csem = sth.column_info[0]['precision']
|
209
|
+
else
|
210
|
+
csem = 1
|
211
|
+
end
|
212
|
+
|
213
|
+
ora80 = OCI8::ORAVER_8_0
|
214
|
+
ora81 = OCI8::ORAVER_8_1
|
215
|
+
ora90 = OCI8::ORAVER_9_0
|
216
|
+
ora101 = OCI8::ORAVER_10_1
|
217
|
+
coldef =
|
218
|
+
[
|
219
|
+
# oracle_version, definition, sql_type, type_name, nullable, precision,scale,indexed,primary,unique,default
|
220
|
+
[ora80, "CHAR(10) NOT NULL", DBI::SQL_CHAR, 'CHAR', false, 10, nil, true, true, true, nil],
|
221
|
+
[ora90, "CHAR(10 CHAR)", DBI::SQL_CHAR, 'CHAR', true, 10 * csem, nil, false,false,false,nil],
|
222
|
+
[ora80, "NCHAR(10)", DBI::SQL_CHAR, 'NCHAR', true, 10 * cfrm, nil, true, false,true, nil],
|
223
|
+
[ora80, "VARCHAR2(10) DEFAULT 'a''b'", DBI::SQL_VARCHAR, 'VARCHAR2', true, 10, nil, true, false,false, "a'b"],
|
224
|
+
[ora90, "VARCHAR2(10 CHAR)", DBI::SQL_VARCHAR, 'VARCHAR2', true, 10 * csem, nil, false,false,false,nil],
|
225
|
+
[ora80, "NVARCHAR2(10)", DBI::SQL_VARCHAR, 'NVARCHAR2',true, 10 * cfrm, nil, false,false,false,nil],
|
226
|
+
[ora80, "RAW(10)", DBI::SQL_VARBINARY, 'RAW', true, 10, nil, false,false,false,nil],
|
227
|
+
[ora81, "CLOB", DBI::SQL_CLOB, 'CLOB', true, 4000, nil, false,false,false,nil],
|
228
|
+
[ora81, "NCLOB", DBI::SQL_CLOB, 'NCLOB', true, 4000, nil, false,false,false,nil],
|
229
|
+
[ora80, "BLOB", DBI::SQL_BLOB, 'BLOB', true, 4000, nil, false,false,false,nil],
|
230
|
+
[ora80, "BFILE", DBI::SQL_BLOB, 'BFILE', true, 4000, nil, false,false,false,nil],
|
231
|
+
[ora80, "NUMBER", DBI::SQL_NUMERIC, 'NUMBER', true, 38, nil, false,false,false,nil],
|
232
|
+
[ora80, "NUMBER(10)", DBI::SQL_NUMERIC, 'NUMBER', true, 10, 0, false,false,false,nil],
|
233
|
+
[ora80, "NUMBER(10,2)", DBI::SQL_NUMERIC, 'NUMBER', true, 10, 2, false,false,false,nil],
|
234
|
+
[ora80, "FLOAT", DBI::SQL_FLOAT, 'FLOAT', true, (126 * 0.30103).ceil, nil, false,false,false,nil],
|
235
|
+
[ora80, "FLOAT(10)", DBI::SQL_FLOAT, 'FLOAT', true, (10 * 0.30103).ceil, nil, false,false,false,nil],
|
236
|
+
[ora101,"BINARY_FLOAT", DBI::SQL_FLOAT, 'BINARY_FLOAT', true, 7, nil, false,false,false,nil],
|
237
|
+
[ora101,"BINARY_DOUBLE", DBI::SQL_DOUBLE, 'BINARY_DOUBLE', true, 16, nil, false,false,false,nil],
|
238
|
+
[ora80, "DATE", DBI::SQL_DATE, 'DATE', true, 19, nil, false,false,false,nil],
|
239
|
+
[ora90, "TIMESTAMP", DBI::SQL_TIMESTAMP, 'TIMESTAMP', true, 20 + 6, nil, false,false,false,nil],
|
240
|
+
[ora90, "TIMESTAMP(9)", DBI::SQL_TIMESTAMP, 'TIMESTAMP', true, 20 + 9, nil, false,false,false,nil],
|
241
|
+
[ora90, "TIMESTAMP WITH TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH TIME ZONE', true, 27 + 6, nil, false,false,false,nil],
|
242
|
+
[ora90, "TIMESTAMP(9) WITH TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH TIME ZONE', true, 27 + 9, nil, false,false,false,nil],
|
243
|
+
[ora90, "TIMESTAMP WITH LOCAL TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH LOCAL TIME ZONE', true, 20 + 6, nil, false,false,false,nil],
|
244
|
+
[ora90, "TIMESTAMP(9) WITH LOCAL TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH LOCAL TIME ZONE', true, 20 + 9, nil, false,false,false,nil],
|
245
|
+
[ora90, "INTERVAL YEAR TO MONTH", DBI::SQL_OTHER, 'INTERVAL YEAR TO MONTH', true, 2 + 3, nil, false,false,false,nil],
|
246
|
+
[ora90, "INTERVAL YEAR(4) TO MONTH", DBI::SQL_OTHER, 'INTERVAL YEAR TO MONTH', true, 4 + 3, nil, false,false,false,nil],
|
247
|
+
[ora90, "INTERVAL DAY TO SECOND", DBI::SQL_OTHER, 'INTERVAL DAY TO SECOND', true, 2 + 10 + 6, nil, false,false,false,nil],
|
248
|
+
[ora90, "INTERVAL DAY(4) TO SECOND(9)",DBI::SQL_OTHER, 'INTERVAL DAY TO SECOND', true, 4 + 10 + 9, nil, false,false,false,nil],
|
249
|
+
]
|
250
|
+
|
251
|
+
coldef.reject! do |c| c[0] > $oracle_version end
|
252
|
+
|
253
|
+
drop_table('test_table')
|
254
|
+
@dbh.execute(<<-EOS)
|
255
|
+
CREATE TABLE test_table (#{n = 0; coldef.collect do |c| n += 1; "C#{n} " + c[1] + (c[8] ? ' PRIMARY KEY' : ''); end.join(',')})
|
256
|
+
STORAGE (
|
257
|
+
INITIAL 100k
|
258
|
+
NEXT 100k
|
259
|
+
MINEXTENTS 1
|
260
|
+
MAXEXTENTS UNLIMITED
|
261
|
+
PCTINCREASE 0)
|
262
|
+
EOS
|
263
|
+
coldef.each_with_index do |col, idx|
|
264
|
+
next if col[8] # primary
|
265
|
+
if col[7] # indexed
|
266
|
+
@dbh.execute(<<-EOS)
|
267
|
+
CREATE #{col[9] ? 'UNIQUE' : ''} INDEX test_table_idx#{idx + 1} ON test_table(C#{idx + 1})
|
268
|
+
STORAGE (
|
269
|
+
INITIAL 100k
|
270
|
+
NEXT 100k
|
271
|
+
MINEXTENTS 1
|
272
|
+
MAXEXTENTS UNLIMITED
|
273
|
+
PCTINCREASE 0)
|
274
|
+
EOS
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
@dbh.columns('test_table').each_with_index do |ci, i|
|
279
|
+
assert_equal("C#{i + 1}", ci['name'], "'#{coldef[i][1]}': name")
|
280
|
+
assert_equal(coldef[i][2], ci['sql_type'], "'#{coldef[i][1]}': sql_type")
|
281
|
+
assert_equal(coldef[i][3], ci['type_name'], "'#{coldef[i][1]}': type_name")
|
282
|
+
assert_equal(coldef[i][4], ci['nullable'], "'#{coldef[i][1]}': nullable")
|
283
|
+
assert_equal(coldef[i][5], ci['precision'], "'#{coldef[i][1]}': precision")
|
284
|
+
assert_equal(coldef[i][6], ci['scale'], "'#{coldef[i][1]}': scale")
|
285
|
+
assert_equal(coldef[i][7], ci['indexed'], "'#{coldef[i][1]}': indexed")
|
286
|
+
assert_equal(coldef[i][8], ci['primary'], "'#{coldef[i][1]}': primary")
|
287
|
+
assert_equal(coldef[i][9], ci['unique'], "'#{coldef[i][1]}': unique")
|
288
|
+
assert_equal(coldef[i][10],ci['default'], "'#{coldef[i][1]}': default")
|
289
|
+
end
|
290
|
+
|
291
|
+
# temporarily change OCI8::BindType::Mapping.
|
292
|
+
saved_mapping = {}
|
293
|
+
[OCI8::SQLT_TIMESTAMP_TZ,
|
294
|
+
OCI8::SQLT_TIMESTAMP_LTZ,
|
295
|
+
OCI8::SQLT_INTERVAL_YM,
|
296
|
+
OCI8::SQLT_INTERVAL_DS].each do |sqlt_type|
|
297
|
+
saved_mapping[sqlt_type] = OCI8::BindType::Mapping[sqlt_type]
|
298
|
+
OCI8::BindType::Mapping[sqlt_type] = OCI8::BindType::String
|
299
|
+
end
|
300
|
+
begin
|
301
|
+
sth = @dbh.execute("SELECT * FROM test_table")
|
302
|
+
ensure
|
303
|
+
saved_mapping.each do |key, val|
|
304
|
+
OCI8::BindType::Mapping[key] = val
|
305
|
+
end
|
306
|
+
end
|
307
|
+
sth.column_info.each_with_index do |ci, i|
|
308
|
+
assert_equal("C#{i + 1}", ci['name'], "'#{coldef[i][1]}': name")
|
309
|
+
assert_equal(coldef[i][2], ci['sql_type'], "'#{coldef[i][1]}': sql_type")
|
310
|
+
assert_equal(coldef[i][3], ci['type_name'], "'#{coldef[i][1]}': type_name")
|
311
|
+
assert_equal(coldef[i][4], ci['nullable'], "'#{coldef[i][1]}': nullable")
|
312
|
+
assert_equal(coldef[i][5], ci['precision'], "'#{coldef[i][1]}': precision")
|
313
|
+
assert_equal(coldef[i][6], ci['scale'], "'#{coldef[i][1]}': scale")
|
314
|
+
assert_equal(nil, ci['indexed'], "'#{coldef[i][1]}': indexed")
|
315
|
+
assert_equal(nil, ci['primary'], "'#{coldef[i][1]}': primary")
|
316
|
+
assert_equal(nil, ci['unique'], "'#{coldef[i][1]}': unique")
|
317
|
+
assert_equal(nil, ci['default'], "'#{coldef[i][1]}': default")
|
318
|
+
end
|
319
|
+
|
320
|
+
drop_table('test_table')
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_column_info_of_tab
|
324
|
+
coldef =
|
325
|
+
[
|
326
|
+
# name, sql_type, type_name, nullable,precision,scale,indexed,primary,unique,default
|
327
|
+
["TNAME", DBI::SQL_VARCHAR,'VARCHAR2',false, 30, nil, false, false, false, nil],
|
328
|
+
["TABTYPE", DBI::SQL_VARCHAR,'VARCHAR2',true, 7, nil, false, false, false, nil],
|
329
|
+
["CLUSTERID",DBI::SQL_NUMERIC,'NUMBER', true, 38, nil, false, false, false, nil],
|
330
|
+
]
|
331
|
+
begin
|
332
|
+
@dbh.columns('tab').each_with_index do |ci, i|
|
333
|
+
assert_equal(coldef[i][0], ci['name'], "'#{coldef[i][0]}': name")
|
334
|
+
assert_equal(coldef[i][1], ci['sql_type'], "'#{coldef[i][0]}': sql_type")
|
335
|
+
assert_equal(coldef[i][2], ci['type_name'], "'#{coldef[i][0]}': type_name")
|
336
|
+
assert_equal(coldef[i][3], ci['nullable'], "'#{coldef[i][0]}': nullable")
|
337
|
+
assert_equal(coldef[i][4], ci['precision'], "'#{coldef[i][0]}': precision")
|
338
|
+
assert_equal(coldef[i][5], ci['scale'], "'#{coldef[i][0]}': scale")
|
339
|
+
assert_equal(coldef[i][6], ci['indexed'], "'#{coldef[i][0]}': indexed")
|
340
|
+
assert_equal(coldef[i][7], ci['primary'], "'#{coldef[i][0]}': primary")
|
341
|
+
assert_equal(coldef[i][8], ci['unique'], "'#{coldef[i][0]}': unique")
|
342
|
+
assert_equal(coldef[i][9], ci['default'], "'#{coldef[i][0]}': default")
|
343
|
+
end
|
344
|
+
rescue RuntimeError
|
345
|
+
if $oracle_version < OCI8::ORAVER_8_1
|
346
|
+
assert_equal("This feature is unavailable on Oracle 8.0", $!.to_s)
|
347
|
+
else
|
348
|
+
raise
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
@dbh.execute("SELECT * FROM tab").column_info.each_with_index do |ci, i|
|
353
|
+
assert_equal(coldef[i][0], ci['name'], "'#{coldef[i][0]}': name")
|
354
|
+
assert_equal(coldef[i][1], ci['sql_type'], "'#{coldef[i][0]}': sql_type")
|
355
|
+
assert_equal(coldef[i][2], ci['type_name'], "'#{coldef[i][0]}': type_name")
|
356
|
+
assert_equal(coldef[i][3], ci['nullable'], "'#{coldef[i][0]}': nullable")
|
357
|
+
assert_equal(coldef[i][4], ci['precision'], "'#{coldef[i][0]}': precision")
|
358
|
+
assert_equal(coldef[i][5], ci['scale'], "'#{coldef[i][0]}': scale")
|
359
|
+
assert_equal(nil, ci['indexed'], "'#{coldef[i][0]}': indexed")
|
360
|
+
assert_equal(nil, ci['primary'], "'#{coldef[i][0]}': primary")
|
361
|
+
assert_equal(nil, ci['unique'], "'#{coldef[i][0]}': unique")
|
362
|
+
assert_equal(nil, ci['default'], "'#{coldef[i][0]}': default")
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
end # TestDBI
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'dbi'
|
2
|
+
require 'oci8'
|
3
|
+
require 'test/unit'
|
4
|
+
require File.dirname(__FILE__) + '/config'
|
5
|
+
|
6
|
+
class TestDbiCLob < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@dbh = get_dbi_connection()
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_insert
|
13
|
+
filename = File.basename($lobfile)
|
14
|
+
@dbh.do("DELETE FROM test_clob WHERE filename = :1", filename)
|
15
|
+
|
16
|
+
# insert an empty clob and get the rowid.
|
17
|
+
rowid = @dbh.execute("INSERT INTO test_clob(filename, content) VALUES (:1, EMPTY_CLOB())", filename) do |sth|
|
18
|
+
sth.func(:rowid)
|
19
|
+
end
|
20
|
+
lob = @dbh.select_one("SELECT content FROM test_clob WHERE filename = :1 FOR UPDATE", filename)[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
|
+
filename = File.basename($lobfile)
|
34
|
+
test_insert() # first insert data.
|
35
|
+
lob = @dbh.select_one("SELECT content FROM test_clob WHERE filename = :1 FOR UPDATE", filename)[0]
|
36
|
+
begin
|
37
|
+
open($lobfile) do |f|
|
38
|
+
while buf = lob.read($lobreadnum)
|
39
|
+
fbuf = f.read(buf.size)
|
40
|
+
assert_equal(fbuf, buf)
|
41
|
+
end
|
42
|
+
assert_equal(nil, buf)
|
43
|
+
assert_equal(true, f.eof?)
|
44
|
+
end
|
45
|
+
ensure
|
46
|
+
lob.close()
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def teardown
|
51
|
+
@dbh.disconnect
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/config'
|
4
|
+
|
5
|
+
class TestEncoding < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@conn = get_oci8_connection
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_select
|
11
|
+
drop_table('test_table')
|
12
|
+
@conn.exec(<<EOS)
|
13
|
+
CREATE TABLE test_table
|
14
|
+
(C CHAR(10),
|
15
|
+
V VARCHAR2(10),
|
16
|
+
R RAW(10),
|
17
|
+
LR LONG RAW,
|
18
|
+
CL CLOB,
|
19
|
+
NCL NCLOB,
|
20
|
+
BL BLOB)
|
21
|
+
STORAGE (
|
22
|
+
INITIAL 4k
|
23
|
+
NEXT 4k
|
24
|
+
MINEXTENTS 1
|
25
|
+
MAXEXTENTS UNLIMITED
|
26
|
+
PCTINCREASE 0)
|
27
|
+
EOS
|
28
|
+
ascii_8bit = Encoding.find('ASCII-8BIT')
|
29
|
+
@conn.exec(<<EOS)
|
30
|
+
INSERT INTO test_table VALUES ('abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd')
|
31
|
+
EOS
|
32
|
+
@conn.exec("SELECT * FROM test_table") do |row|
|
33
|
+
assert_equal('abcd ', row[0], 'CHAR(10)')
|
34
|
+
assert_equal(OCI8.encoding, row[0].encoding);
|
35
|
+
assert_equal('abcd', row[1], 'VARCHAR2(10)')
|
36
|
+
assert_equal(OCI8.encoding, row[1].encoding);
|
37
|
+
assert_equal("\xab\xcd", row[2], 'RAW(10)')
|
38
|
+
assert_equal(ascii_8bit, row[2].encoding);
|
39
|
+
assert_equal("\xab\xcd", row[3], 'LONG RAW')
|
40
|
+
assert_equal(ascii_8bit, row[3].encoding);
|
41
|
+
assert_equal('abcd', (data = row[4].read), 'CLOB')
|
42
|
+
assert_equal(OCI8.encoding, data.encoding);
|
43
|
+
assert_equal('abcd', (data = row[5].read), 'NCLOB')
|
44
|
+
assert_equal(OCI8.encoding, data.encoding);
|
45
|
+
assert_equal("\xab\xcd", (data = row[6].read), 'BLOB')
|
46
|
+
assert_equal(ascii_8bit, data.encoding);
|
47
|
+
|
48
|
+
if OCI8.encoding.name == "UTF-8"
|
49
|
+
utf_8 = "\u00A1\u00A2\u00A3\u00A4\u00A5\u00A6\u00A7\u00A8\u00A9"
|
50
|
+
iso_8859_1 = utf_8.encode("ISO-8859-1")
|
51
|
+
# CLOB
|
52
|
+
lob = row[4]
|
53
|
+
lob.rewind
|
54
|
+
lob.write(iso_8859_1) # converted to OCI8.encoding(UTF-8)
|
55
|
+
lob.rewind
|
56
|
+
assert_equal(utf_8, lob.read)
|
57
|
+
# NCLOB
|
58
|
+
lob = row[5]
|
59
|
+
lob.rewind
|
60
|
+
lob.write(iso_8859_1) # converted to OCI8.encoding(UTF-8)
|
61
|
+
lob.rewind
|
62
|
+
assert_equal(utf_8, lob.read)
|
63
|
+
# BLOB
|
64
|
+
lob = row[6]
|
65
|
+
lob.rewind
|
66
|
+
lob.write(iso_8859_1) # written without encoding conversion
|
67
|
+
lob.rewind
|
68
|
+
assert_equal(iso_8859_1.force_encoding('ASCII-8BIT'), lob.read)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
drop_table('test_table')
|
72
|
+
end
|
73
|
+
|
74
|
+
if OCI8.encoding.name == "UTF-8"
|
75
|
+
def test_bind_string_with_code_conversion
|
76
|
+
drop_table('test_table')
|
77
|
+
@conn.exec(<<EOS)
|
78
|
+
CREATE TABLE test_table
|
79
|
+
(V VARCHAR2(3000))
|
80
|
+
STORAGE (
|
81
|
+
INITIAL 4k
|
82
|
+
NEXT 4k
|
83
|
+
MINEXTENTS 1
|
84
|
+
MAXEXTENTS UNLIMITED
|
85
|
+
PCTINCREASE 0)
|
86
|
+
EOS
|
87
|
+
utf_8 = "\u00A1" * 1500 # 3000 byte
|
88
|
+
iso_8859_1 = utf_8.encode("ISO-8859-1") # 1500 byte
|
89
|
+
@conn.exec("INSERT INTO test_table VALUES (:1)", iso_8859_1)
|
90
|
+
@conn.exec("SELECT * FROM test_table") do |row|
|
91
|
+
assert_equal(utf_8, row[0])
|
92
|
+
end
|
93
|
+
drop_table('test_table')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def teardown
|
98
|
+
@conn.logoff
|
99
|
+
end
|
100
|
+
end
|