ruby-oci8 1.0.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/ChangeLog +1254 -390
  2. data/Makefile +10 -13
  3. data/README +56 -385
  4. data/VERSION +1 -1
  5. data/dist-files +26 -27
  6. data/ext/oci8/.document +1 -0
  7. data/ext/oci8/MANIFEST +0 -4
  8. data/ext/oci8/apiwrap.c.tmpl +172 -0
  9. data/ext/oci8/apiwrap.h.tmpl +61 -0
  10. data/ext/oci8/apiwrap.rb +91 -0
  11. data/ext/oci8/apiwrap.yml +1243 -0
  12. data/ext/oci8/attr.c +124 -384
  13. data/ext/oci8/bind.c +472 -164
  14. data/ext/oci8/encoding.c +196 -0
  15. data/ext/oci8/env.c +84 -253
  16. data/ext/oci8/error.c +196 -127
  17. data/ext/oci8/extconf.rb +82 -59
  18. data/ext/oci8/lob.c +710 -370
  19. data/ext/oci8/metadata.c +359 -0
  20. data/ext/oci8/object.c +622 -0
  21. data/ext/oci8/oci8.c +577 -161
  22. data/ext/oci8/oci8.h +354 -258
  23. data/ext/oci8/oci8lib.c +493 -0
  24. data/ext/oci8/ocidatetime.c +473 -0
  25. data/ext/oci8/ocinumber.c +1123 -24
  26. data/ext/oci8/oraconf.rb +72 -106
  27. data/ext/oci8/oradate.c +511 -321
  28. data/ext/oci8/stmt.c +752 -572
  29. data/ext/oci8/win32.c +131 -0
  30. data/ext/oci8/xmldb.c +383 -0
  31. data/lib/.document +2 -0
  32. data/lib/dbd/OCI8.rb +2 -17
  33. data/lib/oci8.rb.in +41 -1622
  34. data/lib/oci8/.document +5 -0
  35. data/lib/oci8/compat.rb +108 -0
  36. data/lib/oci8/datetime.rb +489 -0
  37. data/lib/oci8/encoding-init.rb +40 -0
  38. data/lib/oci8/encoding.yml +537 -0
  39. data/lib/oci8/metadata.rb +2077 -0
  40. data/lib/oci8/object.rb +548 -0
  41. data/lib/oci8/oci8.rb +773 -0
  42. data/lib/oci8/oracle_version.rb +144 -0
  43. data/metaconfig +3 -3
  44. data/ruby-oci8.gemspec +5 -5
  45. data/setup.rb +4 -4
  46. data/test/config.rb +64 -84
  47. data/test/test_all.rb +14 -21
  48. data/test/test_array_dml.rb +317 -0
  49. data/test/test_bind_raw.rb +18 -25
  50. data/test/test_bind_time.rb +78 -91
  51. data/test/test_break.rb +37 -35
  52. data/test/test_clob.rb +33 -89
  53. data/test/test_connstr.rb +5 -4
  54. data/test/test_datetime.rb +469 -0
  55. data/test/test_dbi.rb +99 -60
  56. data/test/test_dbi_clob.rb +3 -8
  57. data/test/test_metadata.rb +65 -51
  58. data/test/test_oci8.rb +151 -55
  59. data/test/test_oracle_version.rb +70 -0
  60. data/test/test_oradate.rb +76 -83
  61. data/test/test_oranumber.rb +405 -71
  62. data/test/test_rowid.rb +6 -11
  63. metadata +31 -32
  64. data/NEWS +0 -420
  65. data/ext/oci8/const.c +0 -165
  66. data/ext/oci8/define.c +0 -53
  67. data/ext/oci8/describe.c +0 -81
  68. data/ext/oci8/descriptor.c +0 -39
  69. data/ext/oci8/handle.c +0 -273
  70. data/ext/oci8/oranumber.c +0 -445
  71. data/ext/oci8/param.c +0 -37
  72. data/ext/oci8/server.c +0 -182
  73. data/ext/oci8/session.c +0 -99
  74. data/ext/oci8/svcctx.c +0 -238
  75. data/ruby-oci8.spec +0 -62
  76. data/support/README +0 -4
  77. data/support/runit/assert.rb +0 -281
  78. data/support/runit/cui/testrunner.rb +0 -101
  79. data/support/runit/error.rb +0 -4
  80. data/support/runit/method_mappable.rb +0 -20
  81. data/support/runit/robserver.rb +0 -25
  82. data/support/runit/setuppable.rb +0 -15
  83. data/support/runit/teardownable.rb +0 -16
  84. data/support/runit/testcase.rb +0 -113
  85. data/support/runit/testfailure.rb +0 -25
  86. data/support/runit/testresult.rb +0 -121
  87. data/support/runit/testsuite.rb +0 -43
  88. data/support/runit/version.rb +0 -3
  89. data/test/test_describe.rb +0 -137
@@ -1,15 +1,18 @@
1
1
  require 'dbi'
2
2
  require 'oci8'
3
- require 'runit/testcase'
4
- require 'runit/cui/testrunner'
3
+ require 'test/unit'
5
4
  require File.dirname(__FILE__) + '/config'
6
5
 
7
- class TestDBI < RUNIT::TestCase
6
+ class TestDBI < Test::Unit::TestCase
8
7
 
9
8
  def setup
10
9
  @dbh = get_dbi_connection()
11
10
  end
12
11
 
12
+ def teardown
13
+ @dbh.disconnect
14
+ end
15
+
13
16
  def test_select
14
17
  drop_table('test_table')
15
18
  sql = <<-EOS
@@ -99,19 +102,34 @@ EOS
99
102
  sth = @dbh.prepare("INSERT INTO test_table VALUES (:C, :V, :N, :D1, :D2, :D3, :D4, :INT, :BIGNUM)")
100
103
  1.upto(10) do |i|
101
104
  if i == 1
102
- dt = nil
103
- v = ''
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
104
122
  else
105
- dt = OraDate.new(2000 + i, 8, 3, 23, 59, 59)
123
+ dt = OraDate.new(2000 + i, 8, 3, 23, 59, 59)
106
124
  v = i.to_s
125
+ sth.execute(format("%10d", i * 10), v, i, dt, dt, dt, dt, i, i)
107
126
  end
108
- sth.execute(format("%10d", i * 10), v, i, dt, dt, dt, dt, i, i)
109
127
  end
110
128
  sth.finish
111
129
  sth = @dbh.prepare("SELECT * FROM test_table ORDER BY c")
112
130
  sth.func(:define, 5, Time) # define 5th column as Time
113
131
  sth.func(:define, 6, Date) # define 6th column as Date
114
- sth.func(:define, 7, DateTime) if defined? DateTime # define 7th column as DateTime
132
+ sth.func(:define, 7, DateTime) # define 7th column as DateTime
115
133
  sth.func(:define, 8, Integer) # define 8th column as Integer
116
134
  sth.func(:define, 9, Bignum) # define 9th column as Bignum
117
135
  sth.execute
@@ -128,14 +146,16 @@ EOS
128
146
  assert_nil(rv[6])
129
147
  else
130
148
  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
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])
136
156
  assert_instance_of(Time, rv[4])
137
157
  assert_instance_of(Date, rv[5])
138
- assert_instance_of(DateTime, rv[6]) if defined? DateTime
158
+ assert_instance_of(DateTime, rv[6])
139
159
  end
140
160
  assert_equal(i, rv[7])
141
161
  assert_equal(i, rv[8])
@@ -170,47 +190,62 @@ EOS
170
190
  end
171
191
 
172
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
+
173
202
  # data_size factor for nchar charset_form.
174
- sth = @dbh.execute("select CAST('1' AS NCHAR(1)) from dual")
203
+ sth = @dbh.execute("select N'1' from dual")
175
204
  cfrm = sth.column_info[0]['precision']
176
- if $oracle_version >= 900
205
+ if $oracle_version >= OCI8::ORAVER_9_0
177
206
  # data_size factor for char semantics.
178
207
  sth = @dbh.execute("select CAST('1' AS CHAR(1 char)) from dual")
179
208
  csem = sth.column_info[0]['precision']
209
+ else
210
+ csem = 1
180
211
  end
181
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
182
217
  coldef =
183
218
  [
184
219
  # 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],
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],
214
249
  ]
215
250
 
216
251
  coldef.reject! do |c| c[0] > $oracle_version end
@@ -293,17 +328,25 @@ EOS
293
328
  ["TABTYPE", DBI::SQL_VARCHAR,'VARCHAR2',true, 7, nil, false, false, false, nil],
294
329
  ["CLUSTERID",DBI::SQL_NUMERIC,'NUMBER', true, 38, nil, false, false, false, nil],
295
330
  ]
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")
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
307
350
  end
308
351
 
309
352
  @dbh.execute("SELECT * FROM tab").column_info.each_with_index do |ci, i|
@@ -321,7 +364,3 @@ EOS
321
364
  end
322
365
 
323
366
  end # TestDBI
324
-
325
- if $0 == __FILE__
326
- RUNIT::CUI::TestRunner.run(TestDBI.suite())
327
- end
@@ -1,10 +1,9 @@
1
1
  require 'dbi'
2
2
  require 'oci8'
3
- require 'runit/testcase'
4
- require 'runit/cui/testrunner'
3
+ require 'test/unit'
5
4
  require File.dirname(__FILE__) + '/config'
6
5
 
7
- class TestDbiCLob < RUNIT::TestCase
6
+ class TestDbiCLob < Test::Unit::TestCase
8
7
 
9
8
  def setup
10
9
  @dbh = get_dbi_connection()
@@ -49,10 +48,6 @@ class TestDbiCLob < RUNIT::TestCase
49
48
  end
50
49
 
51
50
  def teardown
52
- @dbh.disconnect()
51
+ @dbh.disconnect
53
52
  end
54
53
  end
55
-
56
- if $0 == __FILE__
57
- RUNIT::CUI::TestRunner.run(TestDbiCLob.suite())
58
- end
@@ -1,12 +1,11 @@
1
1
  require 'oci8'
2
- require 'runit/testcase'
3
- require 'runit/cui/testrunner'
2
+ require 'test/unit'
4
3
  require File.dirname(__FILE__) + '/config'
5
4
 
6
- class TestMetadata < RUNIT::TestCase
5
+ class TestMetadata < Test::Unit::TestCase
7
6
 
8
7
  def setup
9
- @conn = get_oci_connection()
8
+ @conn = get_oci8_connection
10
9
  end
11
10
 
12
11
  def teardown
@@ -14,25 +13,40 @@ class TestMetadata < RUNIT::TestCase
14
13
  end
15
14
 
16
15
  def test_metadata
16
+ if $oracle_version < OCI8::ORAVER_8_1
17
+ begin
18
+ @conn.describe_table('tab').columns
19
+ rescue RuntimeError
20
+ assert_equal("This feature is unavailable on Oracle 8.0", $!.to_s)
21
+ end
22
+ return
23
+ end
24
+
17
25
  # data_size factor for nchar charset_form.
18
- cursor = @conn.exec("select CAST('1' AS NCHAR(1)) from dual")
26
+ cursor = @conn.exec("select N'1' from dual")
19
27
  cfrm = cursor.column_metadata[0].data_size
20
- if $oracle_version >= 900
28
+ if $oracle_version >= OCI8::ORAVER_9_0
21
29
  # data_size factor for char semantics.
22
30
  cursor = @conn.exec("select CAST('1' AS CHAR(1 char)) from dual")
23
31
  csem = cursor.column_metadata[0].data_size
32
+ else
33
+ csem = 1
24
34
  end
25
35
 
36
+ ora80 = OCI8::ORAVER_8_0
37
+ ora81 = OCI8::ORAVER_8_1
38
+ ora90 = OCI8::ORAVER_9_0
39
+ ora101 = OCI8::ORAVER_10_1
26
40
  coldef =
27
41
  [
28
- # oracle_version, definition, data_type, csfrm, null,csem?,csize, data_size,prec,scale,fsprec,lfprec
29
- [800, "CHAR(10) NOT NULL", :char, :implicit, false, false, 10, 10, 0, 0, 0, 0],
30
- [900, "CHAR(10 CHAR)", :char, :implicit, true, true, 10, 10 * csem, 0, 0, 0, 0],
31
- [800, "NCHAR(10)", :char, :nchar, true, true, 10, 10 * cfrm, 0, 0, 0, 0],
32
- [800, "VARCHAR2(10)", :varchar2, :implicit, true, false, 10, 10, 0, 0, 0, 0],
33
- [900, "VARCHAR2(10 CHAR)", :varchar2, :implicit, true, true, 10, 10 * csem, 0, 0, 0, 0],
34
- [800, "NVARCHAR2(10)", :varchar2, :nchar, true, true, 10, 10 * cfrm, 0, 0, 0, 0],
35
- [800, "RAW(10)", :raw, nil, true, false, 0, 10, 0, 0, 0, 0],
42
+ # oracle_version, definition, data_type, csfrm, null?,csem?,csize, data_size,prec,scale,fsprec,lfprec
43
+ [ora80, "CHAR(10) NOT NULL", :char, :implicit, false, false, 10, 10, 0, 0, 0, 0],
44
+ [ora90, "CHAR(10 CHAR)", :char, :implicit, true, true, 10, 10 * csem, 0, 0, 0, 0],
45
+ [ora80, "NCHAR(10)", :char, :nchar, true, true, 10, 10 * cfrm, 0, 0, 0, 0],
46
+ [ora80, "VARCHAR2(10)", :varchar2, :implicit, true, false, 10, 10, 0, 0, 0, 0],
47
+ [ora90, "VARCHAR2(10 CHAR)", :varchar2, :implicit, true, true, 10, 10 * csem, 0, 0, 0, 0],
48
+ [ora80, "NVARCHAR2(10)", :varchar2, :nchar, true, true, 10, 10 * cfrm, 0, 0, 0, 0],
49
+ [ora80, "RAW(10)", :raw, nil, true, false, 0, 10, 0, 0, 0, 0],
36
50
 
37
51
  # Don't check data_size of CLOB, NCLOB and BLOB.
38
52
  #
@@ -43,11 +57,11 @@ class TestMetadata < RUNIT::TestCase
43
57
  # | implicit | 4000 | <= OCI8::Cursor#column_metadata
44
58
  # | explicit | 86 | <= OCI8.describe_table('table_name').columns
45
59
  # +----------+-----------+
46
- [800, "CLOB", :clob, :implicit, true, false, 0, :nc, 0, 0, 0, 0],
47
- [800, "NCLOB", :clob, :nchar, true, false, 0, :nc, 0, 0, 0, 0],
48
- [800, "BLOB", :blob, nil, true, false, 0, :nc, 0, 0, 0, 0],
60
+ [ora81, "CLOB", :clob, :implicit, true, false, 0, :nc, 0, 0, 0, 0],
61
+ [ora81, "NCLOB", :clob, :nchar, true, false, 0, :nc, 0, 0, 0, 0],
62
+ [ora80, "BLOB", :blob, nil, true, false, 0, :nc, 0, 0, 0, 0],
49
63
 
50
- [800, "BFILE", :bfile, nil, true, false, 0, 530, 0, 0, 0, 0],
64
+ [ora80, "BFILE", :bfile, nil, true, false, 0, 530, 0, 0, 0, 0],
51
65
 
52
66
  # Don't check fsprecision and lfprecision for NUMBER and FLOAT
53
67
  #
@@ -70,15 +84,15 @@ class TestMetadata < RUNIT::TestCase
70
84
  # | FLOAT(10) | implicit | 129 | 10 |
71
85
  # | | explicit | 10 | 129 |
72
86
  # +----------------+----------+-------------+-------------+
73
- [800, "NUMBER", :number, nil, true, false, 0, 22, 0, -127, :nc, :nc],
74
- [800, "NUMBER(10)", :number, nil, true, false, 0, 22, 10, 0, :nc, :nc],
75
- [800, "NUMBER(10,2)", :number, nil, true, false, 0, 22, 10, 2, :nc, :nc],
76
- [800, "FLOAT", :number, nil, true, false, 0, 22, 126, -127, :nc, :nc],
77
- [800, "FLOAT(10)", :number, nil, true, false, 0, 22, 10, -127, :nc, :nc],
87
+ [ora80, "NUMBER", :number, nil, true, false, 0, 22, 0, $oracle_version >= ora90 ? -127 : 0, :nc, :nc],
88
+ [ora80, "NUMBER(10)", :number, nil, true, false, 0, 22, 10, 0, :nc, :nc],
89
+ [ora80, "NUMBER(10,2)", :number, nil, true, false, 0, 22, 10, 2, :nc, :nc],
90
+ [ora80, "FLOAT", :number, nil, true, false, 0, 22, 126, -127, :nc, :nc],
91
+ [ora80, "FLOAT(10)", :number, nil, true, false, 0, 22, 10, -127, :nc, :nc],
78
92
 
79
- [1000,"BINARY_FLOAT", :binary_float, nil, true, false, 0, 4, 0, 0, 0, 0],
80
- [1000,"BINARY_DOUBLE", :binary_double, nil, true, false, 0, 8, 0, 0, 0, 0],
81
- [800, "DATE", :date, nil, true, false, 0, 7, 0, 0, 0, 0],
93
+ [ora101,"BINARY_FLOAT", :binary_float, nil, true, false, 0, 4, 0, 0, 0, 0],
94
+ [ora101,"BINARY_DOUBLE", :binary_double, nil, true, false, 0, 8, 0, 0, 0, 0],
95
+ [ora80, "DATE", :date, nil, true, false, 0, 7, 0, 0, 0, 0],
82
96
 
83
97
  # Don't check precision and lfprecision for TIMESTAMP
84
98
  #
@@ -104,12 +118,12 @@ class TestMetadata < RUNIT::TestCase
104
118
  # | TIMESTAMP(9) WITH LOCAL TIME ZONE | implicit | 0 | 0 |
105
119
  # | | explicit | 9 | 9 |
106
120
  # +-----------------------------------+----------+-----------+-------------+
107
- [900, "TIMESTAMP", :timestamp, nil, true, false, 0, 11, :nc, 6, 6, :nc],
108
- [900, "TIMESTAMP(9)", :timestamp, nil, true, false, 0, 11, :nc, 9, 9, :nc],
109
- [900, "TIMESTAMP WITH TIME ZONE", :timestamp_tz, nil, true, false, 0, 13, :nc, 6, 6, :nc],
110
- [900, "TIMESTAMP(9) WITH TIME ZONE", :timestamp_tz, nil, true, false, 0, 13, :nc, 9, 9, :nc],
111
- [900, "TIMESTAMP WITH LOCAL TIME ZONE", :timestamp_ltz, nil, true, false, 0, 11, :nc, 6, 6, :nc],
112
- [900, "TIMESTAMP(9) WITH LOCAL TIME ZONE", :timestamp_ltz, nil, true, false, 0, 11, :nc, 9, 9, :nc],
121
+ [ora90, "TIMESTAMP", :timestamp, nil, true, false, 0, 11, :nc, 6, 6, :nc],
122
+ [ora90, "TIMESTAMP(9)", :timestamp, nil, true, false, 0, 11, :nc, 9, 9, :nc],
123
+ [ora90, "TIMESTAMP WITH TIME ZONE", :timestamp_tz, nil, true, false, 0, 13, :nc, 6, 6, :nc],
124
+ [ora90, "TIMESTAMP(9) WITH TIME ZONE", :timestamp_tz, nil, true, false, 0, 13, :nc, 9, 9, :nc],
125
+ [ora90, "TIMESTAMP WITH LOCAL TIME ZONE", :timestamp_ltz, nil, true, false, 0, 11, :nc, 6, 6, :nc],
126
+ [ora90, "TIMESTAMP(9) WITH LOCAL TIME ZONE", :timestamp_ltz, nil, true, false, 0, 11, :nc, 9, 9, :nc],
113
127
 
114
128
  # Don't check scale and fsprecision for INTERVAL YEAR TO MONTH
115
129
  #
@@ -123,8 +137,8 @@ class TestMetadata < RUNIT::TestCase
123
137
  # | INTERVAL YEAR(4) TO MONTH | implicit | 0 | 0 |
124
138
  # | | explicit | 4 | 4 |
125
139
  # +------------------------------+----------+-----------+-------------+
126
- [900, "INTERVAL YEAR TO MONTH", :interval_ym, nil, true, false, 0, 5, 2, :nc, :nc, 2],
127
- [900, "INTERVAL YEAR(4) TO MONTH", :interval_ym, nil, true, false, 0, 5, 4, :nc, :nc, 4],
140
+ [ora90, "INTERVAL YEAR TO MONTH", :interval_ym, nil, true, false, 0, 5, 2, :nc, :nc, 2],
141
+ [ora90, "INTERVAL YEAR(4) TO MONTH", :interval_ym, nil, true, false, 0, 5, 4, :nc, :nc, 4],
128
142
 
129
143
  # Don't check precision and scale for INTERVAL DAY TO SECOND
130
144
  #
@@ -138,15 +152,15 @@ class TestMetadata < RUNIT::TestCase
138
152
  # | INTERVAL DAY(4) TO SECOND(9) | implicit | 4 | 9 |
139
153
  # | | explicit | 9 | 4 |
140
154
  # +------------------------------+----------+-----------+-----------+
141
- [900, "INTERVAL DAY TO SECOND", :interval_ds, nil, true, false, 0, 11, :nc, :nc, 6, 2],
142
- [900, "INTERVAL DAY(4) TO SECOND(9)",:interval_ds, nil, true, false, 0, 11, :nc, :nc, 9, 4],
155
+ [ora90, "INTERVAL DAY TO SECOND", :interval_ds, nil, true, false, 0, 11, :nc, :nc, 6, 2],
156
+ [ora90, "INTERVAL DAY(4) TO SECOND(9)",:interval_ds, nil, true, false, 0, 11, :nc, :nc, 9, 4],
143
157
  ]
144
158
 
145
159
  coldef.reject! do |c| c[0] > $oracle_version end
146
160
 
147
161
  drop_table('test_table')
148
162
  sql = <<-EOS
149
- CREATE TABLE test_table (#{i = 0; coldef.collect do |c| i += 1; "C#{i} " + c[1]; end.join(',')})
163
+ CREATE TABLE test_table (#{idx = 0; coldef.collect do |c| idx += 1; "C#{idx} " + c[1]; end.join(',')})
150
164
  STORAGE (
151
165
  INITIAL 100k
152
166
  NEXT 100k
@@ -164,7 +178,7 @@ EOS
164
178
  assert_equal(coldef[i][3], md.charset_form, "'#{coldef[i][1]}': charset_form")
165
179
  assert_equal(coldef[i][4], md.nullable?, "'#{coldef[i][1]}': nullable? ")
166
180
  # string type
167
- if $oracle_version >= 900
181
+ if $oracle_version >= OCI8::ORAVER_9_0
168
182
  assert_equal(coldef[i][5], md.char_used?, "'#{coldef[i][1]}': char_used? ")
169
183
  assert_equal(coldef[i][6], md.char_size, "'#{coldef[i][1]}': char_size")
170
184
  end
@@ -172,8 +186,10 @@ EOS
172
186
  # number, timestamp and interval type
173
187
  assert_equal(coldef[i][8], md.precision, "'#{coldef[i][1]}': precision") if coldef[i][8] != :nc
174
188
  assert_equal(coldef[i][9], md.scale, "'#{coldef[i][1]}': scale") if coldef[i][9] != :nc
175
- assert_equal(coldef[i][10], md.fsprecision, "'#{coldef[i][1]}': fsprecision") if coldef[i][10] != :nc
176
- assert_equal(coldef[i][11], md.lfprecision, "'#{coldef[i][1]}': lfprecision") if coldef[i][11] != :nc
189
+ if $oracle_version >= OCI8::ORAVER_9_0
190
+ assert_equal(coldef[i][10], md.fsprecision, "'#{coldef[i][1]}': fsprecision") if coldef[i][10] != :nc
191
+ assert_equal(coldef[i][11], md.lfprecision, "'#{coldef[i][1]}': lfprecision") if coldef[i][11] != :nc
192
+ end
177
193
  end
178
194
 
179
195
  # temporarily change OCI8::BindType::Mapping.
@@ -200,7 +216,7 @@ EOS
200
216
  assert_equal(coldef[i][3], md.charset_form, "'#{coldef[i][1]}': charset_form")
201
217
  assert_equal(coldef[i][4], md.nullable?, "'#{coldef[i][1]}': nullable? ")
202
218
  # string type
203
- if $oracle_version >= 900
219
+ if $oracle_version >= OCI8::ORAVER_9_0
204
220
  assert_equal(coldef[i][5], md.char_used?, "'#{coldef[i][1]}': char_used? ")
205
221
  assert_equal(coldef[i][6], md.char_size, "'#{coldef[i][1]}': char_size")
206
222
  end
@@ -208,8 +224,10 @@ EOS
208
224
  # number, timestamp and interval type
209
225
  assert_equal(coldef[i][8], md.precision, "'#{coldef[i][1]}': precision") if coldef[i][8] != :nc
210
226
  assert_equal(coldef[i][9], md.scale, "'#{coldef[i][1]}': scale") if coldef[i][9] != :nc
211
- assert_equal(coldef[i][10], md.fsprecision, "'#{coldef[i][1]}': fsprecision") if coldef[i][10] != :nc
212
- assert_equal(coldef[i][11], md.lfprecision, "'#{coldef[i][1]}': lfprecision") if coldef[i][11] != :nc
227
+ if $oracle_version >= OCI8::ORAVER_9_0
228
+ assert_equal(coldef[i][10], md.fsprecision, "'#{coldef[i][1]}': fsprecision") if coldef[i][10] != :nc
229
+ assert_equal(coldef[i][11], md.lfprecision, "'#{coldef[i][1]}': lfprecision") if coldef[i][11] != :nc
230
+ end
213
231
  end
214
232
 
215
233
  drop_table('test_table')
@@ -219,17 +237,17 @@ EOS
219
237
  drop_table('test_table')
220
238
  begin
221
239
  @conn.describe_table('test_table')
222
- assert_fail("expects ORA-4043 but no error")
240
+ flunk("expects ORA-4043 but no error")
223
241
  rescue OCIError
224
- assert_fail("expects ORA-4043 but ORA-#{$!.code}") if $!.code != 4043
242
+ flunk("expects ORA-4043 but ORA-#{$!.code}") if $!.code != 4043
225
243
  end
226
244
  @conn.exec('create sequence test_table')
227
245
  begin
228
246
  begin
229
247
  @conn.describe_table('test_table')
230
- assert_fail('expects ORA-4043 but no error')
248
+ flunk('expects ORA-4043 but no error')
231
249
  rescue OCIError
232
- assert_fail("expects ORA-4043 but ORA-#{$!.code}") if $!.code != 4043
250
+ flunk("expects ORA-4043 but ORA-#{$!.code}") if $!.code != 4043
233
251
  end
234
252
  ensure
235
253
  @conn.exec('drop sequence test_table')
@@ -237,7 +255,3 @@ EOS
237
255
  end
238
256
 
239
257
  end # TestMetadata
240
-
241
- if $0 == __FILE__
242
- RUNIT::CUI::TestRunner.run(TestMetadata.suite())
243
- end