ruby-oci8 1.0.6-x86-mswin32-60

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.
Files changed (50) hide show
  1. data/ChangeLog +693 -0
  2. data/Makefile +51 -0
  3. data/NEWS +407 -0
  4. data/README +415 -0
  5. data/VERSION +1 -0
  6. data/dist-files +71 -0
  7. data/doc/api.en.html +527 -0
  8. data/doc/api.en.rd +554 -0
  9. data/doc/api.ja.html +525 -0
  10. data/doc/api.ja.rd +557 -0
  11. data/doc/manual.css +35 -0
  12. data/ext/oci8/oci8lib.so +0 -0
  13. data/lib/dbd/OCI8.rb +591 -0
  14. data/lib/oci8.rb +1655 -0
  15. data/lib/oci8.rb.in +1655 -0
  16. data/metaconfig +142 -0
  17. data/pre-distclean.rb +7 -0
  18. data/ruby-oci8.gemspec +54 -0
  19. data/ruby-oci8.spec +62 -0
  20. data/setup.rb +1331 -0
  21. data/support/README +4 -0
  22. data/support/runit/assert.rb +281 -0
  23. data/support/runit/cui/testrunner.rb +101 -0
  24. data/support/runit/error.rb +4 -0
  25. data/support/runit/method_mappable.rb +20 -0
  26. data/support/runit/robserver.rb +25 -0
  27. data/support/runit/setuppable.rb +15 -0
  28. data/support/runit/teardownable.rb +16 -0
  29. data/support/runit/testcase.rb +113 -0
  30. data/support/runit/testfailure.rb +25 -0
  31. data/support/runit/testresult.rb +121 -0
  32. data/support/runit/testsuite.rb +43 -0
  33. data/support/runit/version.rb +3 -0
  34. data/test/README +4 -0
  35. data/test/config.rb +129 -0
  36. data/test/test_all.rb +48 -0
  37. data/test/test_bind_raw.rb +53 -0
  38. data/test/test_bind_time.rb +191 -0
  39. data/test/test_break.rb +81 -0
  40. data/test/test_clob.rb +101 -0
  41. data/test/test_connstr.rb +80 -0
  42. data/test/test_dbi.rb +327 -0
  43. data/test/test_dbi_clob.rb +58 -0
  44. data/test/test_describe.rb +137 -0
  45. data/test/test_metadata.rb +243 -0
  46. data/test/test_oci8.rb +273 -0
  47. data/test/test_oradate.rb +263 -0
  48. data/test/test_oranumber.rb +149 -0
  49. data/test/test_rowid.rb +38 -0
  50. metadata +105 -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
@@ -0,0 +1,327 @@
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
+ begin
150
+ if DBI::VERSION >= '0.4.0'
151
+ # suppress deprecated warnings while running this test.
152
+ saved_action = Deprecated.action
153
+ Deprecated.set_action(Proc.new {})
154
+ end
155
+
156
+ inval = DBI::Date.new(2004, 3, 20)
157
+ sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Date, inval)
158
+ outval = sth.func(:bind_value, 1)
159
+ assert_instance_of(DBI::Date, outval)
160
+ assert_equal(inval.to_time, outval.to_time)
161
+
162
+ inval = DBI::Timestamp.new(2004, 3, 20, 18, 26, 33)
163
+ sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Timestamp, inval)
164
+ outval = sth.func(:bind_value, 1)
165
+ assert_instance_of(DBI::Timestamp, outval)
166
+ assert_equal(inval.to_time, outval.to_time)
167
+ ensure
168
+ Deprecated.set_action(saved_action) if saved_action
169
+ end
170
+ end
171
+
172
+ def test_column_info
173
+ # data_size factor for nchar charset_form.
174
+ sth = @dbh.execute("select CAST('1' AS NCHAR(1)) from dual")
175
+ cfrm = sth.column_info[0]['precision']
176
+ if $oracle_version >= 900
177
+ # data_size factor for char semantics.
178
+ sth = @dbh.execute("select CAST('1' AS CHAR(1 char)) from dual")
179
+ csem = sth.column_info[0]['precision']
180
+ end
181
+
182
+ coldef =
183
+ [
184
+ # oracle_version, definition, sql_type, type_name, nullable, precision,scale,indexed,primary,unique,default
185
+ [800, "CHAR(10) NOT NULL", DBI::SQL_CHAR, 'CHAR', false, 10, nil, true, true, true, nil],
186
+ [900, "CHAR(10 CHAR)", DBI::SQL_CHAR, 'CHAR', true, 10 * csem, nil, false,false,false,nil],
187
+ [800, "NCHAR(10)", DBI::SQL_CHAR, 'NCHAR', true, 10 * cfrm, nil, true, false,true, nil],
188
+ [800, "VARCHAR2(10) DEFAULT 'a''b'", DBI::SQL_VARCHAR, 'VARCHAR2', true, 10, nil, true, false,false, "a'b"],
189
+ [900, "VARCHAR2(10 CHAR)", DBI::SQL_VARCHAR, 'VARCHAR2', true, 10 * csem, nil, false,false,false,nil],
190
+ [800, "NVARCHAR2(10)", DBI::SQL_VARCHAR, 'NVARCHAR2',true, 10 * cfrm, nil, false,false,false,nil],
191
+ [800, "RAW(10)", DBI::SQL_VARBINARY, 'RAW', true, 10, nil, false,false,false,nil],
192
+ [800, "CLOB", DBI::SQL_CLOB, 'CLOB', true, 4000, nil, false,false,false,nil],
193
+ [800, "NCLOB", DBI::SQL_CLOB, 'NCLOB', true, 4000, nil, false,false,false,nil],
194
+ [800, "BLOB", DBI::SQL_BLOB, 'BLOB', true, 4000, nil, false,false,false,nil],
195
+ [800, "BFILE", DBI::SQL_BLOB, 'BFILE', true, 4000, nil, false,false,false,nil],
196
+ [800, "NUMBER", DBI::SQL_NUMERIC, 'NUMBER', true, 38, nil, false,false,false,nil],
197
+ [800, "NUMBER(10)", DBI::SQL_NUMERIC, 'NUMBER', true, 10, 0, false,false,false,nil],
198
+ [800, "NUMBER(10,2)", DBI::SQL_NUMERIC, 'NUMBER', true, 10, 2, false,false,false,nil],
199
+ [800, "FLOAT", DBI::SQL_FLOAT, 'FLOAT', true, (126 * 0.30103).ceil, nil, false,false,false,nil],
200
+ [800, "FLOAT(10)", DBI::SQL_FLOAT, 'FLOAT', true, (10 * 0.30103).ceil, nil, false,false,false,nil],
201
+ [1000,"BINARY_FLOAT", DBI::SQL_FLOAT, 'BINARY_FLOAT', true, 7, nil, false,false,false,nil],
202
+ [1000,"BINARY_DOUBLE", DBI::SQL_DOUBLE, 'BINARY_DOUBLE', true, 16, nil, false,false,false,nil],
203
+ [800, "DATE", DBI::SQL_DATE, 'DATE', true, 19, nil, false,false,false,nil],
204
+ [900, "TIMESTAMP", DBI::SQL_TIMESTAMP, 'TIMESTAMP', true, 20 + 6, nil, false,false,false,nil],
205
+ [900, "TIMESTAMP(9)", DBI::SQL_TIMESTAMP, 'TIMESTAMP', true, 20 + 9, nil, false,false,false,nil],
206
+ [900, "TIMESTAMP WITH TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH TIME ZONE', true, 27 + 6, nil, false,false,false,nil],
207
+ [900, "TIMESTAMP(9) WITH TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH TIME ZONE', true, 27 + 9, nil, false,false,false,nil],
208
+ [900, "TIMESTAMP WITH LOCAL TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH LOCAL TIME ZONE', true, 20 + 6, nil, false,false,false,nil],
209
+ [900, "TIMESTAMP(9) WITH LOCAL TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH LOCAL TIME ZONE', true, 20 + 9, nil, false,false,false,nil],
210
+ [900, "INTERVAL YEAR TO MONTH", DBI::SQL_OTHER, 'INTERVAL YEAR TO MONTH', true, 2 + 3, nil, false,false,false,nil],
211
+ [900, "INTERVAL YEAR(4) TO MONTH", DBI::SQL_OTHER, 'INTERVAL YEAR TO MONTH', true, 4 + 3, nil, false,false,false,nil],
212
+ [900, "INTERVAL DAY TO SECOND", DBI::SQL_OTHER, 'INTERVAL DAY TO SECOND', true, 2 + 10 + 6, nil, false,false,false,nil],
213
+ [900, "INTERVAL DAY(4) TO SECOND(9)",DBI::SQL_OTHER, 'INTERVAL DAY TO SECOND', true, 4 + 10 + 9, nil, false,false,false,nil],
214
+ ]
215
+
216
+ coldef.reject! do |c| c[0] > $oracle_version end
217
+
218
+ drop_table('test_table')
219
+ @dbh.execute(<<-EOS)
220
+ CREATE TABLE test_table (#{i = 0; coldef.collect do |c| i += 1; "C#{i} " + c[1] + (c[8] ? ' PRIMARY KEY' : ''); end.join(',')})
221
+ STORAGE (
222
+ INITIAL 100k
223
+ NEXT 100k
224
+ MINEXTENTS 1
225
+ MAXEXTENTS UNLIMITED
226
+ PCTINCREASE 0)
227
+ EOS
228
+ coldef.each_with_index do |col, idx|
229
+ next if col[8] # primary
230
+ if col[7] # indexed
231
+ @dbh.execute(<<-EOS)
232
+ CREATE #{col[9] ? 'UNIQUE' : ''} INDEX test_table_idx#{idx + 1} ON test_table(C#{idx + 1})
233
+ STORAGE (
234
+ INITIAL 100k
235
+ NEXT 100k
236
+ MINEXTENTS 1
237
+ MAXEXTENTS UNLIMITED
238
+ PCTINCREASE 0)
239
+ EOS
240
+ end
241
+ end
242
+
243
+ @dbh.columns('test_table').each_with_index do |ci, i|
244
+ assert_equal("C#{i + 1}", ci['name'], "'#{coldef[i][1]}': name")
245
+ assert_equal(coldef[i][2], ci['sql_type'], "'#{coldef[i][1]}': sql_type")
246
+ assert_equal(coldef[i][3], ci['type_name'], "'#{coldef[i][1]}': type_name")
247
+ assert_equal(coldef[i][4], ci['nullable'], "'#{coldef[i][1]}': nullable")
248
+ assert_equal(coldef[i][5], ci['precision'], "'#{coldef[i][1]}': precision")
249
+ assert_equal(coldef[i][6], ci['scale'], "'#{coldef[i][1]}': scale")
250
+ assert_equal(coldef[i][7], ci['indexed'], "'#{coldef[i][1]}': indexed")
251
+ assert_equal(coldef[i][8], ci['primary'], "'#{coldef[i][1]}': primary")
252
+ assert_equal(coldef[i][9], ci['unique'], "'#{coldef[i][1]}': unique")
253
+ assert_equal(coldef[i][10],ci['default'], "'#{coldef[i][1]}': default")
254
+ end
255
+
256
+ # temporarily change OCI8::BindType::Mapping.
257
+ saved_mapping = {}
258
+ [OCI8::SQLT_TIMESTAMP_TZ,
259
+ OCI8::SQLT_TIMESTAMP_LTZ,
260
+ OCI8::SQLT_INTERVAL_YM,
261
+ OCI8::SQLT_INTERVAL_DS].each do |sqlt_type|
262
+ saved_mapping[sqlt_type] = OCI8::BindType::Mapping[sqlt_type]
263
+ OCI8::BindType::Mapping[sqlt_type] = OCI8::BindType::String
264
+ end
265
+ begin
266
+ sth = @dbh.execute("SELECT * FROM test_table")
267
+ ensure
268
+ saved_mapping.each do |key, val|
269
+ OCI8::BindType::Mapping[key] = val
270
+ end
271
+ end
272
+ sth.column_info.each_with_index do |ci, i|
273
+ assert_equal("C#{i + 1}", ci['name'], "'#{coldef[i][1]}': name")
274
+ assert_equal(coldef[i][2], ci['sql_type'], "'#{coldef[i][1]}': sql_type")
275
+ assert_equal(coldef[i][3], ci['type_name'], "'#{coldef[i][1]}': type_name")
276
+ assert_equal(coldef[i][4], ci['nullable'], "'#{coldef[i][1]}': nullable")
277
+ assert_equal(coldef[i][5], ci['precision'], "'#{coldef[i][1]}': precision")
278
+ assert_equal(coldef[i][6], ci['scale'], "'#{coldef[i][1]}': scale")
279
+ assert_equal(nil, ci['indexed'], "'#{coldef[i][1]}': indexed")
280
+ assert_equal(nil, ci['primary'], "'#{coldef[i][1]}': primary")
281
+ assert_equal(nil, ci['unique'], "'#{coldef[i][1]}': unique")
282
+ assert_equal(nil, ci['default'], "'#{coldef[i][1]}': default")
283
+ end
284
+
285
+ drop_table('test_table')
286
+ end
287
+
288
+ def test_column_info_of_tab
289
+ coldef =
290
+ [
291
+ # name, sql_type, type_name, nullable,precision,scale,indexed,primary,unique,default
292
+ ["TNAME", DBI::SQL_VARCHAR,'VARCHAR2',false, 30, nil, false, false, false, nil],
293
+ ["TABTYPE", DBI::SQL_VARCHAR,'VARCHAR2',true, 7, nil, false, false, false, nil],
294
+ ["CLUSTERID",DBI::SQL_NUMERIC,'NUMBER', true, 38, nil, false, false, false, nil],
295
+ ]
296
+ @dbh.columns('tab').each_with_index do |ci, i|
297
+ assert_equal(coldef[i][0], ci['name'], "'#{coldef[i][0]}': name")
298
+ assert_equal(coldef[i][1], ci['sql_type'], "'#{coldef[i][0]}': sql_type")
299
+ assert_equal(coldef[i][2], ci['type_name'], "'#{coldef[i][0]}': type_name")
300
+ assert_equal(coldef[i][3], ci['nullable'], "'#{coldef[i][0]}': nullable")
301
+ assert_equal(coldef[i][4], ci['precision'], "'#{coldef[i][0]}': precision")
302
+ assert_equal(coldef[i][5], ci['scale'], "'#{coldef[i][0]}': scale")
303
+ assert_equal(coldef[i][6], ci['indexed'], "'#{coldef[i][0]}': indexed")
304
+ assert_equal(coldef[i][7], ci['primary'], "'#{coldef[i][0]}': primary")
305
+ assert_equal(coldef[i][8], ci['unique'], "'#{coldef[i][0]}': unique")
306
+ assert_equal(coldef[i][9], ci['default'], "'#{coldef[i][0]}': default")
307
+ end
308
+
309
+ @dbh.execute("SELECT * FROM tab").column_info.each_with_index do |ci, i|
310
+ assert_equal(coldef[i][0], ci['name'], "'#{coldef[i][0]}': name")
311
+ assert_equal(coldef[i][1], ci['sql_type'], "'#{coldef[i][0]}': sql_type")
312
+ assert_equal(coldef[i][2], ci['type_name'], "'#{coldef[i][0]}': type_name")
313
+ assert_equal(coldef[i][3], ci['nullable'], "'#{coldef[i][0]}': nullable")
314
+ assert_equal(coldef[i][4], ci['precision'], "'#{coldef[i][0]}': precision")
315
+ assert_equal(coldef[i][5], ci['scale'], "'#{coldef[i][0]}': scale")
316
+ assert_equal(nil, ci['indexed'], "'#{coldef[i][0]}': indexed")
317
+ assert_equal(nil, ci['primary'], "'#{coldef[i][0]}': primary")
318
+ assert_equal(nil, ci['unique'], "'#{coldef[i][0]}': unique")
319
+ assert_equal(nil, ci['default'], "'#{coldef[i][0]}': default")
320
+ end
321
+ end
322
+
323
+ end # TestDBI
324
+
325
+ if $0 == __FILE__
326
+ RUNIT::CUI::TestRunner.run(TestDBI.suite())
327
+ end
@@ -0,0 +1,58 @@
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
+ filename = File.basename($lobfile)
15
+ @dbh.do("DELETE FROM test_clob WHERE filename = :1", filename)
16
+
17
+ # insert an empty clob and get the rowid.
18
+ rowid = @dbh.execute("INSERT INTO test_clob(filename, content) VALUES (:1, EMPTY_CLOB())", filename) do |sth|
19
+ sth.func(:rowid)
20
+ end
21
+ lob = @dbh.select_one("SELECT content FROM test_clob WHERE filename = :1 FOR UPDATE", filename)[0]
22
+ begin
23
+ open($lobfile) do |f|
24
+ while f.gets()
25
+ lob.write($_)
26
+ end
27
+ end
28
+ ensure
29
+ lob.close()
30
+ end
31
+ end
32
+
33
+ def test_read
34
+ filename = File.basename($lobfile)
35
+ test_insert() # first insert data.
36
+ lob = @dbh.select_one("SELECT content FROM test_clob WHERE filename = :1 FOR UPDATE", filename)[0]
37
+ begin
38
+ open($lobfile) do |f|
39
+ while buf = lob.read($lobreadnum)
40
+ fbuf = f.read(buf.size)
41
+ assert_equal(fbuf, buf)
42
+ end
43
+ assert_equal(nil, buf)
44
+ assert_equal(true, f.eof?)
45
+ end
46
+ ensure
47
+ lob.close()
48
+ end
49
+ end
50
+
51
+ def teardown
52
+ @dbh.disconnect()
53
+ end
54
+ end
55
+
56
+ if $0 == __FILE__
57
+ RUNIT::CUI::TestRunner.run(TestDbiCLob.suite())
58
+ end