ruby-oci8 2.1.5.1-x64-mingw32 → 2.1.7-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,7 @@
1
1
  require 'oci8'
2
- require 'test/unit'
3
2
  require File.dirname(__FILE__) + '/config'
4
3
 
5
- class TestArrayDML < Test::Unit::TestCase
4
+ class TestArrayDML < Minitest::Test
6
5
  def setup
7
6
  @conn = get_oci8_connection
8
7
  end
@@ -131,7 +130,7 @@ EOS
131
130
  v_arr << i.to_s if i != max_array_size
132
131
  end
133
132
  cursor[1] = n_arr
134
- assert_raise(RuntimeError) { cursor[2] = v_arr }
133
+ assert_raises(RuntimeError) { cursor[2] = v_arr }
135
134
  cursor.close
136
135
 
137
136
  drop_table('test_table')
@@ -154,9 +153,9 @@ EOS
154
153
  cursor.bind_param_array(1, [1, 2, 3])
155
154
  cursor.bind_param_array(2, ['happy', 'new', 'year'])
156
155
  cursor.bind_param_array(3, [Time.gm(1990,1,1), Time.gm(2000,1,1), Time.gm(2010,1,1)])
157
- assert_nothing_raised() { cursor.exec_array }
156
+ cursor.exec_array
158
157
  cursor.max_array_size = 2
159
- assert_raise(RuntimeError) { cursor.exec_array }
158
+ assert_raises(RuntimeError) { cursor.exec_array }
160
159
  drop_table('test_table')
161
160
  end
162
161
 
@@ -184,7 +183,7 @@ EOS
184
183
  end
185
184
  cursor[1] = n_arr
186
185
  cursor[2] = v_arr
187
- assert_nothing_raised() { cursor.exec_array }
186
+ cursor.exec_array
188
187
  cursor.close
189
188
 
190
189
  cursor = @conn.parse("SELECT * FROM test_table ORDER BY N")
@@ -213,7 +212,7 @@ EOS
213
212
  cursor.max_array_size = max_array_size
214
213
  cursor.bind_param_array(1, nil, Fixnum)
215
214
  cursor.bind_param_array(2, nil, String)
216
- assert_raise(RuntimeError) { cursor.exec_array }
215
+ assert_raises(RuntimeError) { cursor.exec_array }
217
216
  cursor.close
218
217
  drop_table('test_table')
219
218
  end
@@ -1,9 +1,8 @@
1
1
  # Low-level API
2
2
  require 'oci8'
3
- require 'test/unit'
4
3
  require File.dirname(__FILE__) + '/config'
5
4
 
6
- class TestBindRaw < Test::Unit::TestCase
5
+ class TestBindRaw < Minitest::Test
7
6
  CHECK_TARGET = [
8
7
  ["0123456789:;<=>?", "303132333435363738393A3B3C3D3E3F"],
9
8
  ["@ABCDEFGHIJKLMNO", "404142434445464748494A4B4C4D4E4F"],
@@ -1,9 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'oci8'
3
- require 'test/unit'
4
3
  require File.dirname(__FILE__) + '/config'
5
4
 
6
- class TestBindString < Test::Unit::TestCase
5
+ class TestBindString < Minitest::Test
7
6
  def setup
8
7
  @conn = get_oci8_connection
9
8
  end
@@ -1,8 +1,7 @@
1
1
  require 'oci8'
2
- require 'test/unit'
3
2
  require File.dirname(__FILE__) + '/config'
4
3
 
5
- class TestBindTime < Test::Unit::TestCase
4
+ class TestBindTime < Minitest::Test
6
5
 
7
6
  YEAR_CHECK_TARGET = [1971, 1989, 2002, 2037]
8
7
  MON_CHECK_TARGET = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
@@ -1,10 +1,9 @@
1
1
  # High-level API
2
2
  require 'oci8'
3
- require 'test/unit'
4
3
  require 'timeout'
5
4
  require File.dirname(__FILE__) + '/config'
6
5
 
7
- class TestBreak < Test::Unit::TestCase
6
+ class TestBreak < Minitest::Test
8
7
 
9
8
  def setup
10
9
  @conn = get_oci8_connection
@@ -107,7 +106,7 @@ class TestBreak < Test::Unit::TestCase
107
106
  # MRI and Rubinius 2.0.0
108
107
  expected = Timeout::Error
109
108
  end
110
- assert_raise(expected) do
109
+ assert_raises(expected) do
111
110
  Timeout.timeout(1) do
112
111
  @conn.exec("BEGIN DBMS_LOCK.SLEEP(5); END;")
113
112
  end
@@ -1,9 +1,8 @@
1
1
  # Low-level API
2
2
  require 'oci8'
3
- require 'test/unit'
4
3
  require File.dirname(__FILE__) + '/config'
5
4
 
6
- class TestCLob < Test::Unit::TestCase
5
+ class TestCLob < Minitest::Test
7
6
 
8
7
  def setup
9
8
  @conn = get_oci8_connection
@@ -1,8 +1,7 @@
1
1
  require 'oci8'
2
- require 'test/unit'
3
2
  require File.dirname(__FILE__) + '/config'
4
3
 
5
- class TestConnectionPool < Test::Unit::TestCase
4
+ class TestConnectionPool < Minitest::Test
6
5
 
7
6
  def create_pool(min, max, incr)
8
7
  OCI8::ConnectionPool.new(min, max, incr, $dbuser, $dbpass, $dbname)
@@ -48,7 +47,7 @@ class TestConnectionPool < Test::Unit::TestCase
48
47
  if cnt == 0
49
48
  unless conn.non_blocking?
50
49
  non_blocking = false
51
- assert_raise(RuntimeError) do
50
+ assert_raises(RuntimeError) do
52
51
  # This should raise "Could not set non-blocking mode to a connection allocated from OCI8::ConnectionPool."
53
52
  conn.non_blocking = true
54
53
  end
@@ -1,8 +1,7 @@
1
1
  require 'oci8'
2
- require 'test/unit'
3
2
  require File.dirname(__FILE__) + '/config'
4
3
 
5
- class TestConnStr < Test::Unit::TestCase
4
+ class TestConnStr < Minitest::Test
6
5
  TEST_CASES =
7
6
  [
8
7
  # success cases:
@@ -77,5 +76,3 @@ class TestConnStr < Test::Unit::TestCase
77
76
  end
78
77
  end
79
78
  end
80
-
81
- Test::Unit::AutoRunner.run() if $0 == __FILE__
@@ -1,9 +1,8 @@
1
1
  require 'oci8'
2
- require 'test/unit'
3
2
  require File.dirname(__FILE__) + '/config'
4
3
  require 'scanf'
5
4
 
6
- class TestDateTime < Test::Unit::TestCase
5
+ class TestDateTime < Minitest::Test
7
6
 
8
7
  def timezone_string(tzh, tzm)
9
8
  if tzh >= 0
@@ -247,7 +246,7 @@ EOS
247
246
  def test_timezone
248
247
  begin
249
248
  # temporarily change the mapping to test OCI8::BindType::Util.default_timezone.
250
- assert_raise(ArgumentError) do
249
+ assert_raises(ArgumentError) do
251
250
  OCI8::BindType::Util.default_timezone = :invalid_value
252
251
  end
253
252
 
@@ -1,9 +1,8 @@
1
1
  require 'dbi'
2
2
  require 'oci8'
3
- require 'test/unit'
4
3
  require File.dirname(__FILE__) + '/config'
5
4
 
6
- class TestDBI < Test::Unit::TestCase
5
+ class TestDBI < Minitest::Test
7
6
 
8
7
  def setup
9
8
  @dbh = get_dbi_connection()
@@ -1,23 +1,23 @@
1
1
  require 'dbi'
2
2
  require 'oci8'
3
- require 'test/unit'
4
3
  require File.dirname(__FILE__) + '/config'
5
4
 
6
- class TestDbiCLob < Test::Unit::TestCase
5
+ class TestDbiCLob < Minitest::Test
7
6
 
8
7
  def setup
9
8
  @dbh = get_dbi_connection()
9
+ drop_table('test_table')
10
+ @dbh.execute('CREATE TABLE test_table (filename VARCHAR2(40), content CLOB)')
10
11
  end
11
12
 
12
13
  def test_insert
13
14
  filename = File.basename($lobfile)
14
- @dbh.do("DELETE FROM test_clob WHERE filename = :1", filename)
15
15
 
16
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|
17
+ rowid = @dbh.execute("INSERT INTO test_table(filename, content) VALUES (:1, EMPTY_CLOB())", filename) do |sth|
18
18
  sth.func(:rowid)
19
19
  end
20
- lob = @dbh.select_one("SELECT content FROM test_clob WHERE filename = :1 FOR UPDATE", filename)[0]
20
+ lob = @dbh.select_one("SELECT content FROM test_table WHERE filename = :1 FOR UPDATE", filename)[0]
21
21
  begin
22
22
  open($lobfile) do |f|
23
23
  while f.gets()
@@ -32,7 +32,7 @@ class TestDbiCLob < Test::Unit::TestCase
32
32
  def test_read
33
33
  filename = File.basename($lobfile)
34
34
  test_insert() # first insert data.
35
- lob = @dbh.select_one("SELECT content FROM test_clob WHERE filename = :1 FOR UPDATE", filename)[0]
35
+ lob = @dbh.select_one("SELECT content FROM test_table WHERE filename = :1 FOR UPDATE", filename)[0]
36
36
  begin
37
37
  open($lobfile) do |f|
38
38
  while buf = lob.read($lobreadnum)
@@ -1,8 +1,7 @@
1
1
  require 'oci8'
2
- require 'test/unit'
3
2
  require File.dirname(__FILE__) + '/config'
4
3
 
5
- class TestEncoding < Test::Unit::TestCase
4
+ class TestEncoding < Minitest::Test
6
5
  def setup
7
6
  @conn = get_oci8_connection
8
7
  end
@@ -1,8 +1,7 @@
1
1
  require 'oci8'
2
- require 'test/unit'
3
2
  require File.dirname(__FILE__) + '/config'
4
3
 
5
- class TestError < Test::Unit::TestCase
4
+ class TestError < Minitest::Test
6
5
  def setup
7
6
  @conn = get_oci8_connection
8
7
  end
@@ -1,15 +1,14 @@
1
1
  require 'oci8'
2
- require 'test/unit'
3
2
  require File.dirname(__FILE__) + '/config'
4
3
 
5
- class TestMetadata < Test::Unit::TestCase
4
+ class TestMetadata < Minitest::Test
6
5
 
7
6
  def setup
8
7
  @conn = get_oci8_connection
9
8
  end
10
9
 
11
10
  def teardown
12
- @conn.logoff
11
+ @conn.logoff if @conn
13
12
  end
14
13
 
15
14
  def drop_type(name, drop_body = false)
@@ -27,577 +26,28 @@ class TestMetadata < Test::Unit::TestCase
27
26
  end
28
27
  end
29
28
 
30
- class DatatypeData
31
- @@attributes =
32
- [:data_type_string,
33
- :data_type,
34
- :charset_form,
35
- :nullable?,
36
- :data_size,
37
- :precision,
38
- :scale,
39
- ]
40
- @@attributes +=
41
- [
42
- :char_used?,
43
- :char_size,
44
- :fsprecision,
45
- :lfprecision,
46
- ] if $oracle_version >= OCI8::ORAVER_9_0
47
-
48
- @@attributes.each do |attr|
49
- define_method attr do
50
- @table[attr]
51
- end
52
- end
53
-
54
- def self.attributes
55
- @@attributes
56
- end
29
+ def to_obj_id(owner_name, object_name)
30
+ @conn.select_one('select object_id from all_objects where owner = :1 and object_name = :2', owner_name, object_name)[0].to_i
31
+ end
57
32
 
58
- def initialize(hash = {})
59
- @table = hash
60
- end
33
+ def check_attributes(msg, obj, attrs)
34
+ attrs.each do |method, expected_value|
35
+ next if expected_value == :skip
61
36
 
62
- def available?(conn)
63
- return false if $oracle_version < @table[:oraver]
64
- if /^(\w+)\.(\w+)$/ =~ @table[:data_type_string]
65
- if conn.select_one('select 1 from all_objects where owner = :1 and object_name = :2', $1, $2)
66
- true
67
- else
68
- warn "skip a test for unsupported datatype: #{@table[:data_type_string]}."
69
- false
70
- end
37
+ val = method.is_a?(Array) ? obj[method[0]] : obj.send(method)
38
+ case expected_value
39
+ when Hash
40
+ check_attributes("#{msg} > #{method}", val, expected_value)
41
+ when Proc
42
+ assert(expected_value.call(val), "#{msg} > #{method}")
43
+ when Regexp
44
+ assert_match(expected_value, val, "#{msg} > #{method}")
71
45
  else
72
- true
46
+ assert_equal(expected_value, val, "#{msg} > #{method}")
73
47
  end
74
48
  end
75
49
  end
76
50
 
77
- # Get data_size of NCHAR(1) and that of CHAR(1 CHAR).
78
- # They depend on the database character set and the
79
- # client character set.
80
- conn = OCI8.new($dbuser, $dbpass, $dbname)
81
- begin
82
- cursor = conn.exec("select N'1' from dual")
83
- # cfrm: data_size of NCHAR(1).
84
- cfrm = cursor.column_metadata[0].data_size
85
- if $oracle_version >= OCI8::ORAVER_9_0
86
- # csem: data_size of CHAR(1 CHAR).
87
- cursor = conn.exec("select CAST('1' AS CHAR(1 char)) from dual")
88
- csem = cursor.column_metadata[0].data_size
89
- else
90
- csem = 1
91
- end
92
- ensure
93
- conn.logoff
94
- end
95
-
96
- ora80 = OCI8::ORAVER_8_0
97
- ora81 = OCI8::ORAVER_8_1
98
- ora90 = OCI8::ORAVER_9_0
99
- ora101 = OCI8::ORAVER_10_1
100
-
101
- @@column_test_data =
102
- [
103
- DatatypeData.new(:data_type_string => "CHAR(10) NOT NULL",
104
- :oraver => ora80,
105
- :data_type => :char,
106
- :charset_form => :implicit,
107
- :nullable? => false,
108
- :char_used? => false,
109
- :char_size => 10,
110
- :data_size => 10,
111
- :precision => 0,
112
- :scale => 0,
113
- :fsprecision => 0,
114
- :lfprecision => 0
115
- ),
116
- DatatypeData.new(:data_type_string => "CHAR(10 CHAR)",
117
- :oraver => ora90,
118
- :data_type => :char,
119
- :charset_form => :implicit,
120
- :nullable? => true,
121
- :char_used? => true,
122
- :char_size => 10,
123
- :data_size => 10 * csem,
124
- :precision => 0,
125
- :scale => 0,
126
- :fsprecision => 0,
127
- :lfprecision => 0
128
- ),
129
- DatatypeData.new(:data_type_string => "NCHAR(10)",
130
- :oraver => ora80,
131
- :data_type => :char,
132
- :charset_form => :nchar,
133
- :nullable? => true,
134
- :char_used? => true,
135
- :char_size => 10,
136
- :data_size => 10 * cfrm,
137
- :precision => 0,
138
- :scale => 0,
139
- :fsprecision => 0,
140
- :lfprecision => 0
141
- ),
142
- DatatypeData.new(:data_type_string => "VARCHAR2(10)",
143
- :oraver => ora80,
144
- :data_type => :varchar2,
145
- :charset_form => :implicit,
146
- :nullable? => true,
147
- :char_used? => false,
148
- :char_size => 10,
149
- :data_size => 10,
150
- :precision => 0,
151
- :scale => 0,
152
- :fsprecision => 0,
153
- :lfprecision => 0
154
- ),
155
- DatatypeData.new(:data_type_string => "VARCHAR2(10 CHAR)",
156
- :oraver => ora90,
157
- :data_type => :varchar2,
158
- :charset_form => :implicit,
159
- :nullable? => true,
160
- :char_used? => true,
161
- :char_size => 10,
162
- :data_size => 10 * csem,
163
- :precision => 0,
164
- :scale => 0,
165
- :fsprecision => 0,
166
- :lfprecision => 0
167
- ),
168
- DatatypeData.new(:data_type_string => "NVARCHAR2(10)",
169
- :oraver => ora80,
170
- :data_type => :varchar2,
171
- :charset_form => :nchar,
172
- :nullable? => true,
173
- :char_used? => true,
174
- :char_size => 10,
175
- :data_size => 10 * cfrm,
176
- :precision => 0,
177
- :scale => 0,
178
- :fsprecision => 0,
179
- :lfprecision => 0
180
- ),
181
- DatatypeData.new(:data_type_string => "RAW(10)",
182
- :oraver => ora80,
183
- :data_type => :raw,
184
- :charset_form => nil,
185
- :nullable? => true,
186
- :char_used? => false,
187
- :char_size => 0,
188
- :data_size => 10,
189
- :precision => 0,
190
- :scale => 0,
191
- :fsprecision => 0,
192
- :lfprecision => 0
193
- ),
194
-
195
- # Skip tests for data_size of CLOB, NCLOB and BLOB
196
- # because their values depend on how they are described.
197
- #
198
- # Oracle 10g XE 10.2.0.1.0 on Linux:
199
- # +----------------+-----------+
200
- # | | data_size |
201
- # +----------------+-----------+
202
- # | implicitly(*1) | 4000 |
203
- # | explicitly(*2) | 86 |
204
- # +----------------+-----------+
205
- #
206
- # *1 explicitly described by column definition.
207
- # *2 implicitly described by select list.
208
- DatatypeData.new(:data_type_string => "CLOB",
209
- :oraver => ora81,
210
- :data_type => :clob,
211
- :charset_form => :implicit,
212
- :nullable? => true,
213
- :char_used? => false,
214
- :char_size => 0,
215
- :data_size => :skip,
216
- :precision => 0,
217
- :scale => 0,
218
- :fsprecision => 0,
219
- :lfprecision => 0
220
- ),
221
- DatatypeData.new(:data_type_string => "NCLOB",
222
- :oraver => ora81,
223
- :data_type => :clob,
224
- :charset_form => :nchar,
225
- :nullable? => true,
226
- :char_used? => false,
227
- :char_size => 0,
228
- :data_size => :skip,
229
- :precision => 0,
230
- :scale => 0,
231
- :fsprecision => 0,
232
- :lfprecision => 0
233
- ),
234
- DatatypeData.new(:data_type_string => "BLOB",
235
- :oraver => ora80,
236
- :data_type => :blob,
237
- :charset_form => nil,
238
- :nullable? => true,
239
- :char_used? => false,
240
- :char_size => 0,
241
- :data_size => :skip,
242
- :precision => 0,
243
- :scale => 0,
244
- :fsprecision => 0,
245
- :lfprecision => 0
246
- ),
247
- DatatypeData.new(:data_type_string => "BFILE",
248
- :oraver => ora80,
249
- :data_type => :bfile,
250
- :charset_form => nil,
251
- :nullable? => true,
252
- :char_used? => false,
253
- :char_size => 0,
254
- :data_size => 530,
255
- :precision => 0,
256
- :scale => 0,
257
- :fsprecision => 0,
258
- :lfprecision => 0
259
- ),
260
-
261
- # Skip tests for fsprecision and lfprecision for NUMBER and FLOAT
262
- # because their values depend on how they are described.
263
- #
264
- # Oracle 10g XE 10.2.0.1.0 on Linux:
265
- # +-----------------------------+-------------+-------------+
266
- # | | fsprecision | lfprecision |
267
- # +----------------+------------+-------------+-------------+
268
- # | NUMBER | implicitly | 129 | 0 |
269
- # | | explicitly | 0 | 129 |
270
- # +----------------+------------+-------------+-------------+
271
- # | NUMBER(10) | implicitly | 0 | 10 |
272
- # | | explicitly | 10 | 0 |
273
- # +----------------+------------+-------------+-------------+
274
- # | NUMBER(10,2) | implicitly | 2 | 10 |
275
- # | | explicitly | 10 | 2 |
276
- # +----------------+------------+-------------+-------------+
277
- # | FLOAT | implicitly | 129 | 126 |
278
- # | | explicitly | 126 | 129 |
279
- # +----------------+------------+-------------+-------------+
280
- # | FLOAT(10) | implicitly | 129 | 10 |
281
- # | | explicitly | 10 | 129 |
282
- # +----------------+------------+-------------+-------------+
283
- DatatypeData.new(:data_type_string => "NUMBER",
284
- :oraver => ora80,
285
- :data_type => :number,
286
- :charset_form => nil,
287
- :nullable? => true,
288
- :char_used? => false,
289
- :char_size => 0,
290
- :data_size => 22,
291
- :precision => 0,
292
- :scale => $oracle_version > ora90 ? -127 : 0,
293
- :fsprecision => :skip,
294
- :lfprecision => :skip
295
- ),
296
- DatatypeData.new(:data_type_string => "NUMBER(10)",
297
- :oraver => ora80,
298
- :data_type => :number,
299
- :charset_form => nil,
300
- :nullable? => true,
301
- :char_used? => false,
302
- :char_size => 0,
303
- :data_size => 22,
304
- :precision => 10,
305
- :scale => 0,
306
- :fsprecision => :skip,
307
- :lfprecision => :skip
308
- ),
309
- DatatypeData.new(:data_type_string => "NUMBER(10,2)",
310
- :oraver => ora80,
311
- :data_type => :number,
312
- :charset_form => nil,
313
- :nullable? => true,
314
- :char_used? => false,
315
- :char_size => 0,
316
- :data_size => 22,
317
- :precision => 10,
318
- :scale => 2,
319
- :fsprecision => :skip,
320
- :lfprecision => :skip
321
- ),
322
- DatatypeData.new(:data_type_string => "FLOAT",
323
- :oraver => ora80,
324
- :data_type => :number,
325
- :charset_form => nil,
326
- :nullable? => true,
327
- :char_used? => false,
328
- :char_size => 0,
329
- :data_size => 22,
330
- :precision => 126,
331
- :scale => -127,
332
- :fsprecision => :skip,
333
- :lfprecision => :skip
334
- ),
335
- DatatypeData.new(:data_type_string => "FLOAT(10)",
336
- :oraver => ora80,
337
- :data_type => :number,
338
- :charset_form => nil,
339
- :nullable? => true,
340
- :char_used? => false,
341
- :char_size => 0,
342
- :data_size => 22,
343
- :precision => 10,
344
- :scale => -127,
345
- :fsprecision => :skip,
346
- :lfprecision => :skip
347
- ),
348
- DatatypeData.new(:data_type_string => "BINARY_FLOAT",
349
- :oraver => ora101,
350
- :data_type => :binary_float,
351
- :charset_form => nil,
352
- :nullable? => true,
353
- :char_used? => false,
354
- :char_size => 0,
355
- :data_size => 4,
356
- :precision => 0,
357
- :scale => 0,
358
- :fsprecision => 0,
359
- :lfprecision => 0
360
- ),
361
- DatatypeData.new(:data_type_string => "BINARY_DOUBLE",
362
- :oraver => ora101,
363
- :data_type => :binary_double,
364
- :charset_form => nil,
365
- :nullable? => true,
366
- :char_used? => false,
367
- :char_size => 0,
368
- :data_size => 8,
369
- :precision => 0,
370
- :scale => 0,
371
- :fsprecision => 0,
372
- :lfprecision => 0
373
- ),
374
- DatatypeData.new(:data_type_string => "DATE",
375
- :oraver => ora80,
376
- :data_type => :date,
377
- :charset_form => nil,
378
- :nullable? => true,
379
- :char_used? => false,
380
- :char_size => 0,
381
- :data_size => 7,
382
- :precision => 0,
383
- :scale => 0,
384
- :fsprecision => 0,
385
- :lfprecision => 0
386
- ),
387
-
388
- # Skip tests for precision and lfprecision for TIMESTAMP
389
- # because their values depend on how they are described.
390
- #
391
- # Oracle 10g XE 10.2.0.1.0 on Linux:
392
- # +------------------------------------------------+-----------+-------------+
393
- # | | precision | lfprecision |
394
- # +-----------------------------------+------------+-----------+-------------+
395
- # | TIMESTAMP | implicitly | 0 | 0 |
396
- # | | explicitly | 6 | 6 |
397
- # +-----------------------------------+------------+-----------+-------------+
398
- # | TIMESTAMP(9) | implicitly | 0 | 0 |
399
- # | | explicitly | 9 | 9 |
400
- # +-----------------------------------+------------+-----------+-------------+
401
- # | TIMESTAMP WITH TIME ZONE | implicitly | 0 | 0 |
402
- # | | explicitly | 6 | 6 |
403
- # +-----------------------------------+------------+-----------+-------------+
404
- # | TIMESTAMP(9) WITH TIME ZONE | implicitly | 0 | 0 |
405
- # | | explicitly | 9 | 9 |
406
- # +-----------------------------------+------------+-----------+-------------+
407
- # | TIMESTAMP WITH LOCAL TIME ZONE | implicitly | 0 | 0 |
408
- # | | explicitly | 6 | 6 |
409
- # +-----------------------------------+------------+-----------+-------------+
410
- # | TIMESTAMP(9) WITH LOCAL TIME ZONE | implicitly | 0 | 0 |
411
- # | | explicitly | 9 | 9 |
412
- # +-----------------------------------+------------+-----------+-------------+
413
- DatatypeData.new(:data_type_string => "TIMESTAMP",
414
- :oraver => ora90,
415
- :data_type => :timestamp,
416
- :charset_form => nil,
417
- :nullable? => true,
418
- :char_used? => false,
419
- :char_size => 0,
420
- :data_size => 11,
421
- :precision => :skip,
422
- :scale => 6,
423
- :fsprecision => 6,
424
- :lfprecision => :skip
425
- ),
426
- DatatypeData.new(:data_type_string => "TIMESTAMP(9)",
427
- :oraver => ora90,
428
- :data_type => :timestamp,
429
- :charset_form => nil,
430
- :nullable? => true,
431
- :char_used? => false,
432
- :char_size => 0,
433
- :data_size => 11,
434
- :precision => :skip,
435
- :scale => 9,
436
- :fsprecision => 9,
437
- :lfprecision => :skip
438
- ),
439
- DatatypeData.new(:data_type_string => "TIMESTAMP WITH TIME ZONE",
440
- :oraver => ora90,
441
- :data_type => :timestamp_tz,
442
- :charset_form => nil,
443
- :nullable? => true,
444
- :char_used? => false,
445
- :char_size => 0,
446
- :data_size => 13,
447
- :precision => :skip,
448
- :scale => 6,
449
- :fsprecision => 6,
450
- :lfprecision => :skip
451
- ),
452
- DatatypeData.new(:data_type_string => "TIMESTAMP(9) WITH TIME ZONE",
453
- :oraver => ora90,
454
- :data_type => :timestamp_tz,
455
- :charset_form => nil,
456
- :nullable? => true,
457
- :char_used? => false,
458
- :char_size => 0,
459
- :data_size => 13,
460
- :precision => :skip,
461
- :scale => 9,
462
- :fsprecision => 9,
463
- :lfprecision => :skip
464
- ),
465
- DatatypeData.new(:data_type_string => "TIMESTAMP WITH LOCAL TIME ZONE",
466
- :oraver => ora90,
467
- :data_type => :timestamp_ltz,
468
- :charset_form => nil,
469
- :nullable? => true,
470
- :char_used? => false,
471
- :char_size => 0,
472
- :data_size => 11,
473
- :precision => :skip,
474
- :scale => 6,
475
- :fsprecision => 6,
476
- :lfprecision => :skip
477
- ),
478
- DatatypeData.new(:data_type_string => "TIMESTAMP(9) WITH LOCAL TIME ZONE",
479
- :oraver => ora90,
480
- :data_type => :timestamp_ltz,
481
- :charset_form => nil,
482
- :nullable? => true,
483
- :char_used? => false,
484
- :char_size => 0,
485
- :data_size => 11,
486
- :precision => :skip,
487
- :scale => 9,
488
- :fsprecision => 9,
489
- :lfprecision => :skip
490
- ),
491
-
492
- # Skip tsets for scale and fsprecision for INTERVAL YEAR TO MONTH
493
- # because their values depend on how they are described.
494
- #
495
- # Oracle 10g XE 10.2.0.1.0 on Linux:
496
- # +-------------------------------------------+-----------+-------------+
497
- # | | scale | fsprecision |
498
- # +------------------------------+------------+-----------+-------------+
499
- # | INTERVAL YEAR TO MONTH | implicitly | 0 | 0 |
500
- # | | explicitly | 2 | 2 |
501
- # +------------------------------+------------+-----------+-------------+
502
- # | INTERVAL YEAR(4) TO MONTH | implicitly | 0 | 0 |
503
- # | | explicitly | 4 | 4 |
504
- # +------------------------------+------------+-----------+-------------+
505
- DatatypeData.new(:data_type_string => "INTERVAL YEAR TO MONTH",
506
- :oraver => ora90,
507
- :data_type => :interval_ym,
508
- :charset_form => nil,
509
- :nullable? => true,
510
- :char_used? => false,
511
- :char_size => 0,
512
- :data_size => 5,
513
- :precision => 2,
514
- :scale => :skip,
515
- :fsprecision => :skip,
516
- :lfprecision => 2
517
- ),
518
- DatatypeData.new(:data_type_string => "INTERVAL YEAR(4) TO MONTH",
519
- :oraver => ora90,
520
- :data_type => :interval_ym,
521
- :charset_form => nil,
522
- :nullable? => true,
523
- :char_used? => false,
524
- :char_size => 0,
525
- :data_size => 5,
526
- :precision => 4,
527
- :scale => :skip,
528
- :fsprecision => :skip,
529
- :lfprecision => 4
530
- ),
531
- # Skip tests for precision and scale for INTERVAL DAY TO SECOND
532
- # because their values depend on how they are described.
533
- #
534
- # Oracle 10g XE 10.2.0.1.0 on Linux:
535
- # +-------------------------------------------+-----------+-----------+
536
- # | | precision | scale |
537
- # +------------------------------+------------+-----------+-----------+
538
- # | INTERVAL DAY TO SECOND | implicitly | 2 | 6 |
539
- # | | explicitly | 6 | 2 |
540
- # +------------------------------+------------+-----------+-----------+
541
- # | INTERVAL DAY(4) TO SECOND(9) | implicitly | 4 | 9 |
542
- # | | explicitly | 9 | 4 |
543
- # +------------------------------+------------+-----------+-----------+
544
- DatatypeData.new(:data_type_string => "INTERVAL DAY TO SECOND",
545
- :oraver => ora90,
546
- :data_type => :interval_ds,
547
- :charset_form => nil,
548
- :nullable? => true,
549
- :char_used? => false,
550
- :char_size => 0,
551
- :data_size => 11,
552
- :precision => :skip,
553
- :scale => :skip,
554
- :fsprecision => 6,
555
- :lfprecision => 2
556
- ),
557
- DatatypeData.new(:data_type_string => "INTERVAL DAY(4) TO SECOND(9)",
558
- :oraver => ora90,
559
- :data_type => :interval_ds,
560
- :charset_form => nil,
561
- :nullable? => true,
562
- :char_used? => false,
563
- :char_size => 0,
564
- :data_size => 11,
565
- :precision => :skip,
566
- :scale => :skip,
567
- :fsprecision => 9,
568
- :lfprecision => 4
569
- ),
570
- # Object Types
571
- DatatypeData.new(:data_type_string => "MDSYS.SDO_GEOMETRY",
572
- :oraver => ora101,
573
- :data_type => :named_type,
574
- :charset_form => nil,
575
- :nullable? => true,
576
- :char_used? => false,
577
- :char_size => 0,
578
- :data_size => :skip, # 1 when explicitly, 2000 when implicitly.
579
- :precision => 0,
580
- :scale => 0,
581
- :fsprecision => 0,
582
- :lfprecision => 0
583
- ),
584
- =begin # uncomment after ref is supported.
585
- DatatypeData.new(:data_type_string => "REF MDSYS.SDO_GEOMETRY",
586
- :oraver => ora101,
587
- :data_type => :ref,
588
- :charset_form => nil,
589
- :nullable? => true,
590
- :char_used? => false,
591
- :char_size => 0,
592
- :data_size => :skip,
593
- :precision => 0,
594
- :scale => 0,
595
- :fsprecision => 0,
596
- :lfprecision => 0,
597
- ),
598
- =end
599
- ]
600
-
601
51
  def test_error_describe_table
602
52
  drop_table('test_table')
603
53
  begin
@@ -619,12 +69,6 @@ class TestMetadata < Test::Unit::TestCase
619
69
  end
620
70
  end
621
71
 
622
- def assert_object_id(object_name, object_id, owner_name = nil)
623
- owner_name ||= @conn.username
624
- expected_val = @conn.select_one('select object_id from all_objects where owner = :1 and object_name = :2', owner_name, object_name)[0]
625
- assert_equal(expected_val, object_id, "ID of #{object_name}")
626
- end
627
-
628
72
  def test_table_metadata
629
73
  drop_table('test_table')
630
74
 
@@ -638,6 +82,41 @@ STORAGE (
638
82
  MAXEXTENTS UNLIMITED
639
83
  PCTINCREASE 0)
640
84
  EOS
85
+ attrs = {
86
+ :class => OCI8::Metadata::Table,
87
+ :obj_id => to_obj_id(@conn.username, 'TEST_TABLE'),
88
+ :obj_name => 'TEST_TABLE',
89
+ :obj_schema => @conn.username,
90
+ :num_cols => 2,
91
+ :type_metadata => nil,
92
+ :is_temporary? => false,
93
+ :is_typed? => false,
94
+ :duration => nil,
95
+ #:dba => 0,
96
+ #:tablespace => 0,
97
+ :clustered? => false,
98
+ :partitioned? => false,
99
+ :index_only? => false,
100
+ :columns => {
101
+ :class => Array,
102
+ :size => 2,
103
+ [0] => {
104
+ :class => OCI8::Metadata::Column,
105
+ :obj_id => nil,
106
+ :obj_name => nil,
107
+ :obj_schema => nil,
108
+ :name => 'COL1',
109
+ },
110
+ [1] => {
111
+ :class => OCI8::Metadata::Column,
112
+ :obj_id => nil,
113
+ :obj_name => nil,
114
+ :obj_schema => nil,
115
+ :name => 'COL2',
116
+ },
117
+ },
118
+ :inspect => /#<OCI8::Metadata::Table:\(\d+\) #{@conn.username}.TEST_TABLE>/,
119
+ }
641
120
  [
642
121
  @conn.describe_any('test_table'),
643
122
  @conn.describe_table('test_table'),
@@ -645,21 +124,7 @@ EOS
645
124
  obj.obj_name == 'TEST_TABLE'
646
125
  end
647
126
  ].each do |desc|
648
- assert_object_id('TEST_TABLE', desc.obj_id)
649
- assert_equal('TEST_TABLE', desc.obj_name)
650
- assert_equal(@conn.username, desc.obj_schema)
651
- assert_equal(2, desc.num_cols)
652
- assert_nil(desc.type_metadata)
653
- assert_equal(false, desc.is_temporary?)
654
- assert_equal(false, desc.is_typed?)
655
- assert_nil(desc.duration)
656
- assert_not_nil(desc.dba)
657
- assert_not_nil(desc.tablespace)
658
- assert_equal(false, desc.clustered?)
659
- assert_equal(false, desc.partitioned?)
660
- assert_equal(false, desc.index_only?)
661
- assert_instance_of(Array, desc.columns)
662
- assert_instance_of(OCI8::Metadata::Column, desc.columns[0])
127
+ check_attributes("line: #{__LINE__}", desc, attrs)
663
128
  end
664
129
  drop_table('test_table')
665
130
 
@@ -667,6 +132,41 @@ EOS
667
132
  @conn.exec(<<-EOS)
668
133
  CREATE GLOBAL TEMPORARY TABLE test_table (col1 number(38,0), col2 varchar2(60))
669
134
  EOS
135
+ attrs = {
136
+ :class => OCI8::Metadata::Table,
137
+ :obj_id => to_obj_id(@conn.username, 'TEST_TABLE'),
138
+ :obj_name => 'TEST_TABLE',
139
+ :obj_schema => @conn.username,
140
+ :num_cols => 2,
141
+ :type_metadata => nil,
142
+ :is_temporary? => true,
143
+ :is_typed? => false,
144
+ :duration => :transaction,
145
+ #:dba => 0,
146
+ #:tablespace => 0,
147
+ :clustered? => false,
148
+ :partitioned? => false,
149
+ :index_only? => false,
150
+ :columns => {
151
+ :class => Array,
152
+ :size => 2,
153
+ [0] => {
154
+ :class => OCI8::Metadata::Column,
155
+ :obj_id => nil,
156
+ :obj_name => nil,
157
+ :obj_schema => nil,
158
+ :name => 'COL1',
159
+ },
160
+ [1] => {
161
+ :class => OCI8::Metadata::Column,
162
+ :obj_id => nil,
163
+ :obj_name => nil,
164
+ :obj_schema => nil,
165
+ :name => 'COL2',
166
+ },
167
+ },
168
+ :inspect => /#<OCI8::Metadata::Table:\(\d+\) #{@conn.username}.TEST_TABLE>/,
169
+ }
670
170
  [
671
171
  @conn.describe_any('test_table'),
672
172
  @conn.describe_table('test_table'),
@@ -674,21 +174,7 @@ EOS
674
174
  obj.obj_name == 'TEST_TABLE'
675
175
  end
676
176
  ].each do |desc|
677
- assert_object_id('TEST_TABLE', desc.obj_id)
678
- assert_equal('TEST_TABLE', desc.obj_name)
679
- assert_equal(@conn.username, desc.obj_schema)
680
- assert_equal(2, desc.num_cols)
681
- assert_nil(desc.type_metadata)
682
- assert_equal(true, desc.is_temporary?)
683
- assert_equal(false, desc.is_typed?)
684
- assert_equal(:transaction, desc.duration)
685
- assert_not_nil(desc.dba)
686
- assert_not_nil(desc.tablespace)
687
- assert_equal(false, desc.clustered?)
688
- assert_equal(false, desc.partitioned?)
689
- assert_equal(false, desc.index_only?)
690
- assert_instance_of(Array, desc.columns)
691
- assert_instance_of(OCI8::Metadata::Column, desc.columns[0])
177
+ check_attributes("line: #{__LINE__}", desc, attrs)
692
178
  end
693
179
  drop_table('test_table')
694
180
 
@@ -697,6 +183,41 @@ EOS
697
183
  CREATE GLOBAL TEMPORARY TABLE test_table (col1 number(38,0), col2 varchar2(60))
698
184
  ON COMMIT PRESERVE ROWS
699
185
  EOS
186
+ attrs = {
187
+ :class => OCI8::Metadata::Table,
188
+ :obj_id => to_obj_id(@conn.username, 'TEST_TABLE'),
189
+ :obj_name => 'TEST_TABLE',
190
+ :obj_schema => @conn.username,
191
+ :num_cols => 2,
192
+ :type_metadata => nil,
193
+ :is_temporary? => true,
194
+ :is_typed? => false,
195
+ :duration => :session,
196
+ #:dba => 0,
197
+ #:tablespace => 0,
198
+ :clustered? => false,
199
+ :partitioned? => false,
200
+ :index_only? => false,
201
+ :columns => {
202
+ :class => Array,
203
+ :size => 2,
204
+ [0] => {
205
+ :class => OCI8::Metadata::Column,
206
+ :obj_id => nil,
207
+ :obj_name => nil,
208
+ :obj_schema => nil,
209
+ :name => 'COL1',
210
+ },
211
+ [1] => {
212
+ :class => OCI8::Metadata::Column,
213
+ :obj_id => nil,
214
+ :obj_name => nil,
215
+ :obj_schema => nil,
216
+ :name => 'COL2',
217
+ },
218
+ },
219
+ :inspect => /#<OCI8::Metadata::Table:\(\d+\) #{@conn.username}.TEST_TABLE>/,
220
+ }
700
221
  [
701
222
  @conn.describe_any('test_table'),
702
223
  @conn.describe_table('test_table'),
@@ -704,21 +225,7 @@ EOS
704
225
  obj.obj_name == 'TEST_TABLE'
705
226
  end
706
227
  ].each do |desc|
707
- assert_object_id('TEST_TABLE', desc.obj_id)
708
- assert_equal('TEST_TABLE', desc.obj_name)
709
- assert_equal(@conn.username, desc.obj_schema)
710
- assert_equal(2, desc.num_cols)
711
- assert_nil(desc.type_metadata)
712
- assert_equal(true, desc.is_temporary?)
713
- assert_equal(false, desc.is_typed?)
714
- assert_equal(:session, desc.duration)
715
- assert_not_nil(desc.dba)
716
- assert_not_nil(desc.tablespace)
717
- assert_equal(false, desc.clustered?)
718
- assert_equal(false, desc.partitioned?)
719
- assert_equal(false, desc.index_only?)
720
- assert_instance_of(Array, desc.columns)
721
- assert_instance_of(OCI8::Metadata::Column, desc.columns[0])
228
+ check_attributes("line: #{__LINE__}", desc, attrs)
722
229
  end
723
230
  drop_table('test_table')
724
231
 
@@ -729,6 +236,114 @@ EOS
729
236
  @conn.exec(<<-EOS)
730
237
  CREATE TABLE test_table OF test_type
731
238
  EOS
239
+ attrs = {
240
+ :class => OCI8::Metadata::Table,
241
+ :obj_id => to_obj_id(@conn.username, 'TEST_TABLE'),
242
+ :obj_name => 'TEST_TABLE',
243
+ :obj_schema => @conn.username,
244
+ :num_cols => 2,
245
+ :type_metadata => {
246
+ :class => OCI8::Metadata::Type,
247
+ :obj_id => 0,
248
+ :obj_name => nil,
249
+ :obj_schema => nil,
250
+ :typecode => :named_type,
251
+ :collection_typecode => nil,
252
+ :is_incomplete_type? => false,
253
+ :is_system_type? => false,
254
+ :is_predefined_type? => false,
255
+ :is_transient_type? => false,
256
+ :is_system_generated_type? => false,
257
+ :has_nested_table? => false,
258
+ :has_lob? => false,
259
+ :has_file? => false,
260
+ :collection_element => nil,
261
+ :num_type_attrs => 2,
262
+ :num_type_methods => 0,
263
+ :map_method => nil,
264
+ :order_method => nil,
265
+ :is_invoker_rights? => false,
266
+ :name => 'TEST_TYPE',
267
+ :schema_name => @conn.username,
268
+ :is_final_type? => true,
269
+ :is_instantiable_type? => true,
270
+ :is_subtype? => false,
271
+ :package_name => nil,
272
+ :type_attrs => {
273
+ :class => Array,
274
+ :size => 2,
275
+ [0] => {
276
+ :class => OCI8::Metadata::TypeAttr,
277
+ :obj_id => nil,
278
+ :obj_name => nil,
279
+ :obj_schema => nil,
280
+ :data_size => 22,
281
+ :typecode => :number,
282
+ :data_type => :number,
283
+ :name => 'COL1',
284
+ :precision => 38,
285
+ :scale => 0,
286
+ :type_name => 'NUMBER',
287
+ :schema_name => 'SYS',
288
+ :fsprecision => 0,
289
+ :lfprecision => 38,
290
+ :type_metadata => {
291
+ :class => OCI8::Metadata::Type,
292
+ },
293
+ :inspect => '#<OCI8::Metadata::TypeAttr: COL1 NUMBER(38)>',
294
+ },
295
+ [1] => {
296
+ :class => OCI8::Metadata::TypeAttr,
297
+ :obj_id => nil,
298
+ :obj_name => nil,
299
+ :obj_schema => nil,
300
+ :data_size => 60,
301
+ :typecode => :varchar2,
302
+ :data_type => :varchar2,
303
+ :name => 'COL2',
304
+ :precision => 0,
305
+ :scale => 0,
306
+ :type_name => 'VARCHAR2',
307
+ :schema_name => 'SYS',
308
+ :fsprecision => 0,
309
+ :lfprecision => 60,
310
+ :type_metadata => {
311
+ :class => OCI8::Metadata::Type,
312
+ },
313
+ :inspect => '#<OCI8::Metadata::TypeAttr: COL2 VARCHAR2(60)>',
314
+ },
315
+ },
316
+ :type_methods => [],
317
+ :inspect => "#<OCI8::Metadata::Type:(0) #{@conn.username}.TEST_TYPE>",
318
+ },
319
+ :is_temporary? => false,
320
+ :is_typed? => true,
321
+ :duration => nil,
322
+ #:dba => 0,
323
+ #:tablespace => 0,
324
+ :clustered? => false,
325
+ :partitioned? => false,
326
+ :index_only? => false,
327
+ :columns => {
328
+ :class => Array,
329
+ :size => 2,
330
+ [0] => {
331
+ :class => OCI8::Metadata::Column,
332
+ :obj_id => nil,
333
+ :obj_name => nil,
334
+ :obj_schema => nil,
335
+ :name => 'COL1',
336
+ },
337
+ [1] => {
338
+ :class => OCI8::Metadata::Column,
339
+ :obj_id => nil,
340
+ :obj_name => nil,
341
+ :obj_schema => nil,
342
+ :name => 'COL2',
343
+ },
344
+ },
345
+ :inspect => /#<OCI8::Metadata::Table:\(\d+\) #{@conn.username}.TEST_TABLE>/,
346
+ }
732
347
  [
733
348
  @conn.describe_any('test_table'),
734
349
  @conn.describe_table('test_table'),
@@ -736,21 +351,7 @@ EOS
736
351
  obj.obj_name == 'TEST_TABLE'
737
352
  end
738
353
  ].each do |desc|
739
- assert_object_id('TEST_TABLE', desc.obj_id)
740
- assert_equal('TEST_TABLE', desc.obj_name)
741
- assert_equal(@conn.username, desc.obj_schema)
742
- assert_equal(2, desc.num_cols)
743
- assert_instance_of(OCI8::Metadata::Type, desc.type_metadata)
744
- assert_equal(false, desc.is_temporary?)
745
- assert_equal(true, desc.is_typed?)
746
- assert_equal(nil, desc.duration)
747
- assert_not_nil(desc.dba)
748
- assert_not_nil(desc.tablespace)
749
- assert_equal(false, desc.clustered?)
750
- assert_equal(false, desc.partitioned?)
751
- assert_equal(false, desc.index_only?)
752
- assert_instance_of(Array, desc.columns)
753
- assert_instance_of(OCI8::Metadata::Column, desc.columns[0])
354
+ check_attributes("line: #{__LINE__}", desc, attrs)
754
355
  end
755
356
  drop_table('test_table')
756
357
  @conn.exec('DROP TYPE TEST_TYPE')
@@ -760,6 +361,41 @@ EOS
760
361
  CREATE TABLE test_table (col1 number(38,0) PRIMARY KEY, col2 varchar2(60))
761
362
  ORGANIZATION INDEX
762
363
  EOS
364
+ attrs = {
365
+ :class => OCI8::Metadata::Table,
366
+ :obj_id => to_obj_id(@conn.username, 'TEST_TABLE'),
367
+ :obj_name => 'TEST_TABLE',
368
+ :obj_schema => @conn.username,
369
+ :num_cols => 2,
370
+ :type_metadata => nil,
371
+ :is_temporary? => false,
372
+ :is_typed? => false,
373
+ :duration => nil,
374
+ #:dba => 0,
375
+ #:tablespace => 0,
376
+ :clustered? => false,
377
+ :partitioned? => false,
378
+ :index_only? => true,
379
+ :columns => {
380
+ :class => Array,
381
+ :size => 2,
382
+ [0] => {
383
+ :class => OCI8::Metadata::Column,
384
+ :obj_id => nil,
385
+ :obj_name => nil,
386
+ :obj_schema => nil,
387
+ :name => 'COL1',
388
+ },
389
+ [1] => {
390
+ :class => OCI8::Metadata::Column,
391
+ :obj_id => nil,
392
+ :obj_name => nil,
393
+ :obj_schema => nil,
394
+ :name => 'COL2',
395
+ },
396
+ },
397
+ :inspect => /#<OCI8::Metadata::Table:\(\d+\) #{@conn.username}.TEST_TABLE>/,
398
+ }
763
399
  [
764
400
  @conn.describe_any('test_table'),
765
401
  @conn.describe_table('test_table'),
@@ -767,27 +403,46 @@ EOS
767
403
  obj.obj_name == 'TEST_TABLE'
768
404
  end
769
405
  ].each do |desc|
770
- assert_object_id('TEST_TABLE', desc.obj_id)
771
- assert_equal('TEST_TABLE', desc.obj_name)
772
- assert_equal(@conn.username, desc.obj_schema)
773
- assert_equal(2, desc.num_cols)
774
- assert_nil(desc.type_metadata)
775
- assert_equal(false, desc.is_temporary?)
776
- assert_equal(false, desc.is_typed?)
777
- assert_equal(nil, desc.duration)
778
- assert_not_nil(desc.dba)
779
- assert_not_nil(desc.tablespace)
780
- assert_equal(false, desc.clustered?)
781
- assert_equal(false, desc.partitioned?)
782
- assert_equal(true, desc.index_only?)
783
- assert_instance_of(Array, desc.columns)
784
- assert_instance_of(OCI8::Metadata::Column, desc.columns[0])
406
+ check_attributes("line: #{__LINE__}", desc, attrs)
785
407
  end
786
408
  drop_table('test_table')
787
409
  end # test_table_metadata
788
410
 
789
411
  def test_view_metadata
790
412
  @conn.exec('CREATE OR REPLACE VIEW test_view as SELECT * FROM tab')
413
+ attrs = {
414
+ :class => OCI8::Metadata::View,
415
+ :obj_id => to_obj_id(@conn.username, 'TEST_VIEW'),
416
+ :obj_name => 'TEST_VIEW',
417
+ :obj_schema => @conn.username,
418
+ :num_cols => 3,
419
+ :columns => {
420
+ :class => Array,
421
+ :size => 3,
422
+ [0] => {
423
+ :class => OCI8::Metadata::Column,
424
+ :obj_id => nil,
425
+ :obj_name => nil,
426
+ :obj_schema => nil,
427
+ :name => 'TNAME',
428
+ },
429
+ [1] => {
430
+ :class => OCI8::Metadata::Column,
431
+ :obj_id => nil,
432
+ :obj_name => nil,
433
+ :obj_schema => nil,
434
+ :name => 'TABTYPE',
435
+ },
436
+ [2] => {
437
+ :class => OCI8::Metadata::Column,
438
+ :obj_id => nil,
439
+ :obj_name => nil,
440
+ :obj_schema => nil,
441
+ :name => 'CLUSTERID',
442
+ },
443
+ },
444
+ :inspect => /#<OCI8::Metadata::View:\(\d+\) #{@conn.username}.TEST_VIEW>/,
445
+ }
791
446
  [
792
447
  @conn.describe_any('test_view'),
793
448
  @conn.describe_view('test_view'),
@@ -796,12 +451,7 @@ EOS
796
451
  obj.obj_name == 'TEST_VIEW'
797
452
  end
798
453
  ].each do |desc|
799
- assert_object_id('TEST_VIEW', desc.obj_id)
800
- assert_equal('TEST_VIEW', desc.obj_name)
801
- assert_equal(@conn.username, desc.obj_schema)
802
- assert_equal(3, desc.num_cols)
803
- assert_instance_of(Array, desc.columns)
804
- assert_instance_of(OCI8::Metadata::Column, desc.columns[0])
454
+ check_attributes("line: #{__LINE__}", desc, attrs)
805
455
  end
806
456
  @conn.exec('DROP VIEW test_view')
807
457
  end # test_view_metadata
@@ -813,6 +463,71 @@ BEGIN
813
463
  NULL;
814
464
  END;
815
465
  EOS
466
+ attrs = {
467
+ :class => OCI8::Metadata::Procedure,
468
+ :obj_id => to_obj_id(@conn.username, 'TEST_PROC'),
469
+ :obj_name => 'TEST_PROC',
470
+ :obj_schema => @conn.username,
471
+ :is_invoker_rights? => false,
472
+ :name => 'TEST_PROC',
473
+ :overload_id => nil,
474
+ :arguments => {
475
+ :class => Array,
476
+ :size => 2,
477
+ [0] => {
478
+ :class => OCI8::Metadata::Argument,
479
+ :obj_id => nil,
480
+ :obj_name => nil,
481
+ :obj_schema => nil,
482
+ :name => "ARG1",
483
+ :position => 1,
484
+ #:typecode => nil,
485
+ :data_type => :number,
486
+ :data_size => 22,
487
+ :precision => 38,
488
+ :scale => 0,
489
+ :level => 0,
490
+ :has_default => 0,
491
+ :has_default? => false,
492
+ :iomode => :in,
493
+ :radix => 10,
494
+ :type_name => "",
495
+ :schema_name => "",
496
+ :sub_name => "",
497
+ :link => "",
498
+ #:type_metadata => nil,
499
+ :arguments => [],
500
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
501
+ },
502
+ [1] => {
503
+ :class => OCI8::Metadata::Argument,
504
+ :obj_id => nil,
505
+ :obj_name => nil,
506
+ :obj_schema => nil,
507
+ :name => "ARG2",
508
+ :position => 2,
509
+ #:typecode => nil,
510
+ :data_type => :varchar2,
511
+ :data_size => 0,
512
+ :precision => 0,
513
+ :scale => 0,
514
+ :level => 0,
515
+ :has_default => 0,
516
+ :has_default? => false,
517
+ :iomode => :out,
518
+ :radix => 0,
519
+ :type_name => "",
520
+ :schema_name => "",
521
+ :sub_name => "",
522
+ :link => "",
523
+ #:type_metadata => nil,
524
+ :arguments => [],
525
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
526
+ },
527
+ },
528
+ :is_standalone? => true,
529
+ :inspect => '#<OCI8::Metadata::Procedure: TEST_PROC>',
530
+ }
816
531
  [
817
532
  @conn.describe_any('test_proc'),
818
533
  @conn.describe_procedure('test_proc'),
@@ -820,16 +535,7 @@ EOS
820
535
  obj.obj_name == 'TEST_PROC'
821
536
  end
822
537
  ].each do |desc|
823
- assert_instance_of(OCI8::Metadata::Procedure, desc)
824
- assert_object_id('TEST_PROC', desc.obj_id)
825
- assert_equal('TEST_PROC', desc.obj_name)
826
- assert_equal('TEST_PROC', desc.name)
827
- assert_equal(@conn.username, desc.obj_schema)
828
- assert_equal(false, desc.is_invoker_rights?)
829
- assert_equal(nil, desc.overload_id)
830
- assert_instance_of(Array, desc.arguments)
831
- assert_equal(2, desc.arguments.length)
832
- assert_instance_of(OCI8::Metadata::Argument, desc.arguments[0])
538
+ check_attributes("line: #{__LINE__}", desc, attrs)
833
539
  end
834
540
 
835
541
  @conn.exec(<<-EOS)
@@ -840,6 +546,71 @@ BEGIN
840
546
  NULL;
841
547
  END;
842
548
  EOS
549
+ attrs = {
550
+ :class => OCI8::Metadata::Procedure,
551
+ :obj_id => to_obj_id(@conn.username, 'TEST_PROC'),
552
+ :obj_name => 'TEST_PROC',
553
+ :obj_schema => @conn.username,
554
+ :is_invoker_rights? => true,
555
+ :name => 'TEST_PROC',
556
+ :overload_id => nil,
557
+ :arguments => {
558
+ :class => Array,
559
+ :size => 2,
560
+ [0] => {
561
+ :class => OCI8::Metadata::Argument,
562
+ :obj_id => nil,
563
+ :obj_name => nil,
564
+ :obj_schema => nil,
565
+ :name => "ARG1",
566
+ :position => 1,
567
+ #:typecode => nil,
568
+ :data_type => :number,
569
+ :data_size => 22,
570
+ :precision => 38,
571
+ :scale => 0,
572
+ :level => 0,
573
+ :has_default => 0,
574
+ :has_default? => false,
575
+ :iomode => :in,
576
+ :radix => 10,
577
+ :type_name => "",
578
+ :schema_name => "",
579
+ :sub_name => "",
580
+ :link => "",
581
+ #:type_metadata => nil,
582
+ :arguments => [],
583
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
584
+ },
585
+ [1] => {
586
+ :class => OCI8::Metadata::Argument,
587
+ :obj_id => nil,
588
+ :obj_name => nil,
589
+ :obj_schema => nil,
590
+ :name => "ARG2",
591
+ :position => 2,
592
+ #:typecode => nil,
593
+ :data_type => :varchar2,
594
+ :data_size => 0,
595
+ :precision => 0,
596
+ :scale => 0,
597
+ :level => 0,
598
+ :has_default => 0,
599
+ :has_default? => false,
600
+ :iomode => :out,
601
+ :radix => 0,
602
+ :type_name => "",
603
+ :schema_name => "",
604
+ :sub_name => "",
605
+ :link => "",
606
+ #:type_metadata => nil,
607
+ :arguments => [],
608
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
609
+ },
610
+ },
611
+ :is_standalone? => true,
612
+ :inspect => '#<OCI8::Metadata::Procedure: TEST_PROC>',
613
+ }
843
614
  [
844
615
  @conn.describe_any('test_proc'),
845
616
  @conn.describe_procedure('test_proc'),
@@ -847,62 +618,11 @@ EOS
847
618
  obj.obj_name == 'TEST_PROC'
848
619
  end
849
620
  ].each do |desc|
850
- assert_instance_of(OCI8::Metadata::Procedure, desc)
851
- assert_object_id('TEST_PROC', desc.obj_id)
852
- assert_equal('TEST_PROC', desc.obj_name)
853
- assert_equal(@conn.username, desc.obj_schema)
854
- assert_equal(true, desc.is_invoker_rights?)
855
- assert_equal(nil, desc.overload_id)
856
- assert_instance_of(Array, desc.arguments)
857
- assert_equal(2, desc.arguments.length)
858
- assert_instance_of(OCI8::Metadata::Argument, desc.arguments[0])
621
+ check_attributes("line: #{__LINE__}", desc, attrs)
859
622
  end
860
623
 
861
624
  @conn.exec('DROP PROCEDURE test_proc');
862
625
 
863
- @conn.exec(<<-EOS)
864
- CREATE OR REPLACE PACKAGE TEST_PKG IS
865
- PROCEDURE test_proc(arg1 IN INTEGER, arg2 OUT varchar2);
866
- END;
867
- EOS
868
- desc = @conn.describe_package('test_pkg').subprograms[0]
869
- assert_instance_of(OCI8::Metadata::Procedure, desc)
870
- assert_equal(nil, desc.obj_id)
871
- assert_equal('TEST_PROC', desc.obj_name)
872
- assert_equal(nil, desc.obj_schema)
873
- assert_equal(false, desc.is_invoker_rights?)
874
- assert_equal(0, desc.overload_id)
875
- assert_instance_of(Array, desc.arguments)
876
- assert_equal(2, desc.arguments.length)
877
- assert_instance_of(OCI8::Metadata::Argument, desc.arguments[0])
878
-
879
- @conn.exec(<<-EOS)
880
- CREATE OR REPLACE PACKAGE TEST_PKG AUTHID CURRENT_USER
881
- IS
882
- PROCEDURE test_proc(arg1 IN INTEGER, arg2 OUT varchar2);
883
- PROCEDURE test_proc(arg1 IN INTEGER);
884
- END;
885
- EOS
886
- desc = @conn.describe_package('test_pkg').subprograms
887
- assert_instance_of(OCI8::Metadata::Procedure, desc[0])
888
- assert_equal(nil, desc[0].obj_id)
889
- assert_equal('TEST_PROC', desc[0].obj_name)
890
- assert_equal(nil, desc[0].obj_schema)
891
- assert_equal(true, desc[0].is_invoker_rights?)
892
- assert_equal(2, desc[0].overload_id)
893
- assert_instance_of(Array, desc[0].arguments)
894
- assert_equal(2, desc[0].arguments.length)
895
- assert_instance_of(OCI8::Metadata::Argument, desc[0].arguments[0])
896
-
897
- assert_instance_of(OCI8::Metadata::Procedure, desc[1])
898
- assert_equal(nil, desc[1].obj_id)
899
- assert_equal('TEST_PROC', desc[1].obj_name)
900
- assert_equal(nil, desc[1].obj_schema)
901
- assert_equal(true, desc[1].is_invoker_rights?)
902
- assert_equal(1, desc[1].overload_id)
903
- assert_instance_of(Array, desc[1].arguments)
904
- assert_equal(1, desc[1].arguments.length)
905
- assert_instance_of(OCI8::Metadata::Argument, desc[1].arguments[0])
906
626
  end # test_procedure_metadata
907
627
 
908
628
  def test_function_metadata
@@ -912,6 +632,96 @@ BEGIN
912
632
  RETURN arg1;
913
633
  END;
914
634
  EOS
635
+ attrs = {
636
+ :class => OCI8::Metadata::Function,
637
+ :obj_id => to_obj_id(@conn.username, 'TEST_FUNC'),
638
+ :obj_name => 'TEST_FUNC',
639
+ :obj_schema => @conn.username,
640
+ :is_invoker_rights? => false,
641
+ :name => 'TEST_FUNC',
642
+ :overload_id => nil,
643
+ :arguments => {
644
+ :class => Array,
645
+ :size => 3,
646
+ [0] => {
647
+ :class => OCI8::Metadata::Argument,
648
+ :obj_id => nil,
649
+ :obj_name => nil,
650
+ :obj_schema => nil,
651
+ :name => "",
652
+ :position => 0,
653
+ #:typecode => nil,
654
+ :data_type => :number,
655
+ :data_size => 22,
656
+ :precision => 0,
657
+ :scale => 0,
658
+ :level => 0,
659
+ :has_default => 0,
660
+ :has_default? => false,
661
+ :iomode => :out,
662
+ :radix => 10,
663
+ :type_name => "",
664
+ :schema_name => "",
665
+ :sub_name => "",
666
+ :link => "",
667
+ #:type_metadata => nil,
668
+ :arguments => [],
669
+ :inspect => '#<OCI8::Metadata::Argument: NUMBER>',
670
+ },
671
+ [1] => {
672
+ :class => OCI8::Metadata::Argument,
673
+ :obj_id => nil,
674
+ :obj_name => nil,
675
+ :obj_schema => nil,
676
+ :name => "ARG1",
677
+ :position => 1,
678
+ #:typecode => nil,
679
+ :data_type => :number,
680
+ :data_size => 22,
681
+ :precision => 38,
682
+ :scale => 0,
683
+ :level => 0,
684
+ :has_default => 0,
685
+ :has_default? => false,
686
+ :iomode => :in,
687
+ :radix => 10,
688
+ :type_name => "",
689
+ :schema_name => "",
690
+ :sub_name => "",
691
+ :link => "",
692
+ #:type_metadata => nil,
693
+ :arguments => [],
694
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
695
+ },
696
+ [2] => {
697
+ :class => OCI8::Metadata::Argument,
698
+ :obj_id => nil,
699
+ :obj_name => nil,
700
+ :obj_schema => nil,
701
+ :name => "ARG2",
702
+ :position => 2,
703
+ #:typecode => nil,
704
+ :data_type => :varchar2,
705
+ :data_size => 0,
706
+ :precision => 0,
707
+ :scale => 0,
708
+ :level => 0,
709
+ :has_default => 0,
710
+ :has_default? => false,
711
+ :iomode => :out,
712
+ :radix => 0,
713
+ :type_name => "",
714
+ :schema_name => "",
715
+ :sub_name => "",
716
+ :link => "",
717
+ #:type_metadata => nil,
718
+ :arguments => [],
719
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
720
+ },
721
+ },
722
+ :is_standalone? => true,
723
+ :inspect => '#<OCI8::Metadata::Function: TEST_FUNC>',
724
+ }
915
725
  [
916
726
  @conn.describe_any('test_func'),
917
727
  @conn.describe_function('test_func'),
@@ -919,16 +729,7 @@ EOS
919
729
  obj.obj_name == 'TEST_FUNC'
920
730
  end
921
731
  ].each do |desc|
922
- assert_instance_of(OCI8::Metadata::Function, desc)
923
- assert_object_id('TEST_FUNC', desc.obj_id)
924
- assert_equal('TEST_FUNC', desc.obj_name)
925
- assert_equal('TEST_FUNC', desc.name)
926
- assert_equal(@conn.username, desc.obj_schema)
927
- assert_equal(false, desc.is_invoker_rights?)
928
- assert_equal(nil, desc.overload_id)
929
- assert_instance_of(Array, desc.arguments)
930
- assert_equal(3, desc.arguments.length)
931
- assert_instance_of(OCI8::Metadata::Argument, desc.arguments[0])
732
+ check_attributes("line: #{__LINE__}", desc, attrs)
932
733
  end
933
734
 
934
735
  @conn.exec(<<-EOS)
@@ -939,6 +740,96 @@ BEGIN
939
740
  RETURN arg1;
940
741
  END;
941
742
  EOS
743
+ attrs = {
744
+ :class => OCI8::Metadata::Function,
745
+ :obj_id => to_obj_id(@conn.username, 'TEST_FUNC'),
746
+ :obj_name => 'TEST_FUNC',
747
+ :obj_schema => @conn.username,
748
+ :is_invoker_rights? => true,
749
+ :name => 'TEST_FUNC',
750
+ :overload_id => nil,
751
+ :arguments => {
752
+ :class => Array,
753
+ :size => 3,
754
+ [0] => {
755
+ :class => OCI8::Metadata::Argument,
756
+ :obj_id => nil,
757
+ :obj_name => nil,
758
+ :obj_schema => nil,
759
+ :name => "",
760
+ :position => 0,
761
+ #:typecode => nil,
762
+ :data_type => :number,
763
+ :data_size => 22,
764
+ :precision => 0,
765
+ :scale => 0,
766
+ :level => 0,
767
+ :has_default => 0,
768
+ :has_default? => false,
769
+ :iomode => :out,
770
+ :radix => 10,
771
+ :type_name => "",
772
+ :schema_name => "",
773
+ :sub_name => "",
774
+ :link => "",
775
+ #:type_metadata => nil,
776
+ :arguments => [],
777
+ :inspect => '#<OCI8::Metadata::Argument: NUMBER>',
778
+ },
779
+ [1] => {
780
+ :class => OCI8::Metadata::Argument,
781
+ :obj_id => nil,
782
+ :obj_name => nil,
783
+ :obj_schema => nil,
784
+ :name => "ARG1",
785
+ :position => 1,
786
+ #:typecode => nil,
787
+ :data_type => :number,
788
+ :data_size => 22,
789
+ :precision => 38,
790
+ :scale => 0,
791
+ :level => 0,
792
+ :has_default => 0,
793
+ :has_default? => false,
794
+ :iomode => :in,
795
+ :radix => 10,
796
+ :type_name => "",
797
+ :schema_name => "",
798
+ :sub_name => "",
799
+ :link => "",
800
+ #:type_metadata => nil,
801
+ :arguments => [],
802
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
803
+ },
804
+ [2] => {
805
+ :class => OCI8::Metadata::Argument,
806
+ :obj_id => nil,
807
+ :obj_name => nil,
808
+ :obj_schema => nil,
809
+ :name => "ARG2",
810
+ :position => 2,
811
+ #:typecode => nil,
812
+ :data_type => :varchar2,
813
+ :data_size => 0,
814
+ :precision => 0,
815
+ :scale => 0,
816
+ :level => 0,
817
+ :has_default => 0,
818
+ :has_default? => false,
819
+ :iomode => :out,
820
+ :radix => 0,
821
+ :type_name => "",
822
+ :schema_name => "",
823
+ :sub_name => "",
824
+ :link => "",
825
+ #:type_metadata => nil,
826
+ :arguments => [],
827
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
828
+ },
829
+ },
830
+ :is_standalone? => true,
831
+ :inspect => '#<OCI8::Metadata::Function: TEST_FUNC>',
832
+ }
942
833
  [
943
834
  @conn.describe_any('test_func'),
944
835
  @conn.describe_function('test_func'),
@@ -946,70 +837,188 @@ EOS
946
837
  obj.obj_name == 'TEST_FUNC'
947
838
  end
948
839
  ].each do |desc|
949
- assert_instance_of(OCI8::Metadata::Function, desc)
950
- assert_object_id('TEST_FUNC', desc.obj_id)
951
- assert_equal('TEST_FUNC', desc.obj_name)
952
- assert_equal(@conn.username, desc.obj_schema)
953
- assert_equal(true, desc.is_invoker_rights?)
954
- assert_equal(nil, desc.overload_id)
955
- assert_instance_of(Array, desc.arguments)
956
- assert_equal(3, desc.arguments.length)
957
- assert_instance_of(OCI8::Metadata::Argument, desc.arguments[0])
840
+ check_attributes("line: #{__LINE__}", desc, attrs)
958
841
  end
959
842
 
960
843
  @conn.exec('DROP FUNCTION test_func');
961
844
 
962
- @conn.exec(<<-EOS)
963
- CREATE OR REPLACE PACKAGE TEST_PKG IS
964
- FUNCTION test_func(arg1 IN INTEGER, arg2 OUT varchar2) RETURN NUMBER;
965
- END;
966
- EOS
967
- desc = @conn.describe_package('test_pkg').subprograms[0]
968
- assert_instance_of(OCI8::Metadata::Function, desc)
969
- assert_equal(nil, desc.obj_id)
970
- assert_equal('TEST_FUNC', desc.obj_name)
971
- assert_equal(nil, desc.obj_schema)
972
- assert_equal(false, desc.is_invoker_rights?)
973
- assert_equal(0, desc.overload_id)
974
- assert_instance_of(Array, desc.arguments)
975
- assert_equal(3, desc.arguments.length)
976
- assert_instance_of(OCI8::Metadata::Argument, desc.arguments[0])
977
-
978
- @conn.exec(<<-EOS)
979
- CREATE OR REPLACE PACKAGE TEST_PKG AUTHID CURRENT_USER
980
- IS
981
- FUNCTION test_func(arg1 IN INTEGER, arg2 OUT varchar2) RETURN NUMBER;
982
- FUNCTION test_func(arg1 IN INTEGER) RETURN NUMBER;
983
- END;
984
- EOS
985
- desc = @conn.describe_package('test_pkg').subprograms
986
- assert_instance_of(OCI8::Metadata::Function, desc[0])
987
- assert_equal(nil, desc[0].obj_id)
988
- assert_equal('TEST_FUNC', desc[0].obj_name)
989
- assert_equal(nil, desc[0].obj_schema)
990
- assert_equal(true, desc[0].is_invoker_rights?)
991
- assert_equal(2, desc[0].overload_id)
992
- assert_instance_of(Array, desc[0].arguments)
993
- assert_equal(3, desc[0].arguments.length)
994
- assert_instance_of(OCI8::Metadata::Argument, desc[0].arguments[0])
995
-
996
- assert_instance_of(OCI8::Metadata::Function, desc[1])
997
- assert_equal(nil, desc[1].obj_id)
998
- assert_equal('TEST_FUNC', desc[1].obj_name)
999
- assert_equal(nil, desc[1].obj_schema)
1000
- assert_equal(true, desc[1].is_invoker_rights?)
1001
- assert_equal(1, desc[1].overload_id)
1002
- assert_instance_of(Array, desc[1].arguments)
1003
- assert_equal(2, desc[1].arguments.length)
1004
- assert_instance_of(OCI8::Metadata::Argument, desc[1].arguments[0])
1005
845
  end # test_function_metadata
1006
846
 
1007
847
  def test_package_metadata
1008
848
  @conn.exec(<<-EOS)
1009
849
  CREATE OR REPLACE PACKAGE TEST_PKG IS
1010
850
  FUNCTION test_func(arg1 IN INTEGER, arg2 OUT varchar2) RETURN NUMBER;
851
+ PROCEDURE test_proc(arg1 IN INTEGER, arg2 OUT varchar2);
1011
852
  END;
1012
853
  EOS
854
+ attrs = {
855
+ :class => OCI8::Metadata::Package,
856
+ :obj_id => to_obj_id(@conn.username, 'TEST_PKG'),
857
+ :obj_name => 'TEST_PKG',
858
+ :obj_schema => @conn.username,
859
+ :is_invoker_rights? => false,
860
+ :subprograms => {
861
+ :class => Array,
862
+ :size => 2,
863
+ [0] => {
864
+ :class => OCI8::Metadata::Function,
865
+ :obj_id => nil,
866
+ :obj_name => 'TEST_FUNC',
867
+ :obj_schema => nil,
868
+ :is_invoker_rights? => false,
869
+ :name => 'TEST_FUNC',
870
+ :overload_id => 0,
871
+ :arguments => {
872
+ :class => Array,
873
+ :size => 3,
874
+ [0] => {
875
+ :class => OCI8::Metadata::Argument,
876
+ :obj_id => nil,
877
+ :obj_name => nil,
878
+ :obj_schema => nil,
879
+ :name => "",
880
+ :position => 0,
881
+ #:typecode => nil,
882
+ :data_type => :number,
883
+ :data_size => 22,
884
+ :precision => 0,
885
+ :scale => 0,
886
+ :level => 0,
887
+ :has_default => 0,
888
+ :has_default? => false,
889
+ :iomode => :out,
890
+ :radix => 10,
891
+ :type_name => "",
892
+ :schema_name => "",
893
+ :sub_name => "",
894
+ :link => "",
895
+ #:type_metadata => nil,
896
+ :arguments => [],
897
+ :inspect => '#<OCI8::Metadata::Argument: NUMBER>',
898
+ },
899
+ [1] => {
900
+ :class => OCI8::Metadata::Argument,
901
+ :obj_id => nil,
902
+ :obj_name => nil,
903
+ :obj_schema => nil,
904
+ :name => "ARG1",
905
+ :position => 1,
906
+ #:typecode => nil,
907
+ :data_type => :number,
908
+ :data_size => 22,
909
+ :precision => 38,
910
+ :scale => 0,
911
+ :level => 0,
912
+ :has_default => 0,
913
+ :has_default? => false,
914
+ :iomode => :in,
915
+ :radix => 10,
916
+ :type_name => "",
917
+ :schema_name => "",
918
+ :sub_name => "",
919
+ :link => "",
920
+ #:type_metadata => nil,
921
+ :arguments => [],
922
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
923
+ },
924
+ [2] => {
925
+ :class => OCI8::Metadata::Argument,
926
+ :obj_id => nil,
927
+ :obj_name => nil,
928
+ :obj_schema => nil,
929
+ :name => "ARG2",
930
+ :position => 2,
931
+ #:typecode => nil,
932
+ :data_type => :varchar2,
933
+ :data_size => 0,
934
+ :precision => 0,
935
+ :scale => 0,
936
+ :level => 0,
937
+ :has_default => 0,
938
+ :has_default? => false,
939
+ :iomode => :out,
940
+ :radix => 0,
941
+ :type_name => "",
942
+ :schema_name => "",
943
+ :sub_name => "",
944
+ :link => "",
945
+ #:type_metadata => nil,
946
+ :arguments => [],
947
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
948
+ },
949
+ },
950
+ :is_standalone? => false,
951
+ :inspect => '#<OCI8::Metadata::Function: TEST_FUNC>',
952
+ },
953
+ [1] => {
954
+ :class => OCI8::Metadata::Procedure,
955
+ :obj_id => nil,
956
+ :obj_name => 'TEST_PROC',
957
+ :obj_schema => nil,
958
+ :is_invoker_rights? => false,
959
+ :name => 'TEST_PROC',
960
+ :overload_id => 0,
961
+ :arguments => {
962
+ :class => Array,
963
+ :size => 2,
964
+ [0] => {
965
+ :class => OCI8::Metadata::Argument,
966
+ :obj_id => nil,
967
+ :obj_name => nil,
968
+ :obj_schema => nil,
969
+ :name => "ARG1",
970
+ :position => 1,
971
+ #:typecode => nil,
972
+ :data_type => :number,
973
+ :data_size => 22,
974
+ :precision => 38,
975
+ :scale => 0,
976
+ :level => 0,
977
+ :has_default => 0,
978
+ :has_default? => false,
979
+ :iomode => :in,
980
+ :radix => 10,
981
+ :type_name => "",
982
+ :schema_name => "",
983
+ :sub_name => "",
984
+ :link => "",
985
+ #:type_metadata => nil,
986
+ :arguments => [],
987
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
988
+ },
989
+ [1] => {
990
+ :class => OCI8::Metadata::Argument,
991
+ :obj_id => nil,
992
+ :obj_name => nil,
993
+ :obj_schema => nil,
994
+ :name => "ARG2",
995
+ :position => 2,
996
+ #:typecode => nil,
997
+ :data_type => :varchar2,
998
+ :data_size => 0,
999
+ :precision => 0,
1000
+ :scale => 0,
1001
+ :level => 0,
1002
+ :has_default => 0,
1003
+ :has_default? => false,
1004
+ :iomode => :out,
1005
+ :radix => 0,
1006
+ :type_name => "",
1007
+ :schema_name => "",
1008
+ :sub_name => "",
1009
+ :link => "",
1010
+ #:type_metadata => nil,
1011
+ :arguments => [],
1012
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
1013
+ },
1014
+ },
1015
+ :is_standalone? => false,
1016
+ :inspect => '#<OCI8::Metadata::Procedure: TEST_PROC>',
1017
+ },
1018
+ },
1019
+ :types => ($oracle_version >= OCI8::ORAVER_12_1) ? [] : :skip,
1020
+ :inspect => /#<OCI8::Metadata::Package:\(\d+\) #{@conn.username}.TEST_PKG>/,
1021
+ }
1013
1022
  [
1014
1023
  @conn.describe_any('test_pkg'),
1015
1024
  @conn.describe_package('test_pkg'),
@@ -1017,21 +1026,290 @@ EOS
1017
1026
  obj.obj_name == 'TEST_PKG'
1018
1027
  end
1019
1028
  ].each do |desc|
1020
- assert_instance_of(OCI8::Metadata::Package, desc)
1021
- assert_object_id('TEST_PKG', desc.obj_id)
1022
- assert_equal('TEST_PKG', desc.obj_name)
1023
- assert_equal(@conn.username, desc.obj_schema)
1024
- assert_equal(false, desc.is_invoker_rights?)
1025
- assert_instance_of(Array, desc.subprograms)
1026
- assert_equal(1, desc.subprograms.length)
1027
- assert_instance_of(OCI8::Metadata::Function, desc.subprograms[0])
1029
+ check_attributes("line: #{__LINE__}", desc, attrs)
1028
1030
  end
1029
1031
 
1030
1032
  @conn.exec(<<-EOS)
1031
1033
  CREATE OR REPLACE PACKAGE TEST_PKG AUTHID CURRENT_USER IS
1032
1034
  PROCEDURE test_proc(arg1 IN INTEGER, arg2 OUT varchar2);
1035
+ PROCEDURE test_proc(arg1 IN INTEGER);
1036
+ FUNCTION test_func(arg1 IN INTEGER, arg2 OUT varchar2) RETURN NUMBER;
1037
+ FUNCTION test_func(arg1 IN INTEGER) RETURN NUMBER;
1033
1038
  END;
1034
1039
  EOS
1040
+ attrs = {
1041
+ :class => OCI8::Metadata::Package,
1042
+ :obj_id => to_obj_id(@conn.username, 'TEST_PKG'),
1043
+ :obj_name => 'TEST_PKG',
1044
+ :obj_schema => @conn.username,
1045
+ :is_invoker_rights? => true,
1046
+ :subprograms => {
1047
+ :class => Array,
1048
+ :size => 4,
1049
+ [0] => {
1050
+ :class => OCI8::Metadata::Function,
1051
+ :obj_id => nil,
1052
+ :obj_name => 'TEST_FUNC',
1053
+ :obj_schema => nil,
1054
+ :is_invoker_rights? => true,
1055
+ :name => 'TEST_FUNC',
1056
+ :overload_id => 2,
1057
+ :arguments => {
1058
+ :class => Array,
1059
+ :size => 3,
1060
+ [0] => {
1061
+ :class => OCI8::Metadata::Argument,
1062
+ :obj_id => nil,
1063
+ :obj_name => nil,
1064
+ :obj_schema => nil,
1065
+ :name => "",
1066
+ :position => 0,
1067
+ #:typecode => nil,
1068
+ :data_type => :number,
1069
+ :data_size => 22,
1070
+ :precision => 0,
1071
+ :scale => 0,
1072
+ :level => 0,
1073
+ :has_default => 0,
1074
+ :has_default? => false,
1075
+ :iomode => :out,
1076
+ :radix => 10,
1077
+ :type_name => "",
1078
+ :schema_name => "",
1079
+ :sub_name => "",
1080
+ :link => "",
1081
+ #:type_metadata => nil,
1082
+ :arguments => [],
1083
+ :inspect => '#<OCI8::Metadata::Argument: NUMBER>',
1084
+ },
1085
+ [1] => {
1086
+ :class => OCI8::Metadata::Argument,
1087
+ :obj_id => nil,
1088
+ :obj_name => nil,
1089
+ :obj_schema => nil,
1090
+ :name => "ARG1",
1091
+ :position => 1,
1092
+ #:typecode => nil,
1093
+ :data_type => :number,
1094
+ :data_size => 22,
1095
+ :precision => 38,
1096
+ :scale => 0,
1097
+ :level => 0,
1098
+ :has_default => 0,
1099
+ :has_default? => false,
1100
+ :iomode => :in,
1101
+ :radix => 10,
1102
+ :type_name => "",
1103
+ :schema_name => "",
1104
+ :sub_name => "",
1105
+ :link => "",
1106
+ #:type_metadata => nil,
1107
+ :arguments => [],
1108
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
1109
+ },
1110
+ [2] => {
1111
+ :class => OCI8::Metadata::Argument,
1112
+ :obj_id => nil,
1113
+ :obj_name => nil,
1114
+ :obj_schema => nil,
1115
+ :name => "ARG2",
1116
+ :position => 2,
1117
+ #:typecode => nil,
1118
+ :data_type => :varchar2,
1119
+ :data_size => 0,
1120
+ :precision => 0,
1121
+ :scale => 0,
1122
+ :level => 0,
1123
+ :has_default => 0,
1124
+ :has_default? => false,
1125
+ :iomode => :out,
1126
+ :radix => 0,
1127
+ :type_name => "",
1128
+ :schema_name => "",
1129
+ :sub_name => "",
1130
+ :link => "",
1131
+ #:type_metadata => nil,
1132
+ :arguments => [],
1133
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
1134
+ },
1135
+ },
1136
+ :is_standalone? => false,
1137
+ :inspect => '#<OCI8::Metadata::Function: TEST_FUNC>',
1138
+ },
1139
+ [1] => {
1140
+ :class => OCI8::Metadata::Function,
1141
+ :obj_id => nil,
1142
+ :obj_name => 'TEST_FUNC',
1143
+ :obj_schema => nil,
1144
+ :is_invoker_rights? => true,
1145
+ :name => 'TEST_FUNC',
1146
+ :overload_id => 1,
1147
+ :arguments => {
1148
+ :class => Array,
1149
+ :size => 2,
1150
+ [0] => {
1151
+ :class => OCI8::Metadata::Argument,
1152
+ :obj_id => nil,
1153
+ :obj_name => nil,
1154
+ :obj_schema => nil,
1155
+ :name => "",
1156
+ :position => 0,
1157
+ #:typecode => nil,
1158
+ :data_type => :number,
1159
+ :data_size => 22,
1160
+ :precision => 0,
1161
+ :scale => 0,
1162
+ :level => 0,
1163
+ :has_default => 0,
1164
+ :has_default? => false,
1165
+ :iomode => :out,
1166
+ :radix => 10,
1167
+ :type_name => "",
1168
+ :schema_name => "",
1169
+ :sub_name => "",
1170
+ :link => "",
1171
+ #:type_metadata => nil,
1172
+ :arguments => [],
1173
+ :inspect => '#<OCI8::Metadata::Argument: NUMBER>',
1174
+ },
1175
+ [1] => {
1176
+ :class => OCI8::Metadata::Argument,
1177
+ :obj_id => nil,
1178
+ :obj_name => nil,
1179
+ :obj_schema => nil,
1180
+ :name => "ARG1",
1181
+ :position => 1,
1182
+ #:typecode => nil,
1183
+ :data_type => :number,
1184
+ :data_size => 22,
1185
+ :precision => 38,
1186
+ :scale => 0,
1187
+ :level => 0,
1188
+ :has_default => 0,
1189
+ :has_default? => false,
1190
+ :iomode => :in,
1191
+ :radix => 10,
1192
+ :type_name => "",
1193
+ :schema_name => "",
1194
+ :sub_name => "",
1195
+ :link => "",
1196
+ #:type_metadata => nil,
1197
+ :arguments => [],
1198
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
1199
+ },
1200
+ },
1201
+ :is_standalone? => false,
1202
+ :inspect => '#<OCI8::Metadata::Function: TEST_FUNC>',
1203
+ },
1204
+ [2] => {
1205
+ :class => OCI8::Metadata::Procedure,
1206
+ :obj_id => nil,
1207
+ :obj_name => 'TEST_PROC',
1208
+ :obj_schema => nil,
1209
+ :is_invoker_rights? => true,
1210
+ :name => 'TEST_PROC',
1211
+ :overload_id => 2,
1212
+ :arguments => {
1213
+ :class => Array,
1214
+ :size => 2,
1215
+ [0] => {
1216
+ :class => OCI8::Metadata::Argument,
1217
+ :obj_id => nil,
1218
+ :obj_name => nil,
1219
+ :obj_schema => nil,
1220
+ :name => "ARG1",
1221
+ :position => 1,
1222
+ #:typecode => nil,
1223
+ :data_type => :number,
1224
+ :data_size => 22,
1225
+ :precision => 38,
1226
+ :scale => 0,
1227
+ :level => 0,
1228
+ :has_default => 0,
1229
+ :has_default? => false,
1230
+ :iomode => :in,
1231
+ :radix => 10,
1232
+ :type_name => "",
1233
+ :schema_name => "",
1234
+ :sub_name => "",
1235
+ :link => "",
1236
+ #:type_metadata => nil,
1237
+ :arguments => [],
1238
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
1239
+ },
1240
+ [1] => {
1241
+ :class => OCI8::Metadata::Argument,
1242
+ :obj_id => nil,
1243
+ :obj_name => nil,
1244
+ :obj_schema => nil,
1245
+ :name => "ARG2",
1246
+ :position => 2,
1247
+ #:typecode => nil,
1248
+ :data_type => :varchar2,
1249
+ :data_size => 0,
1250
+ :precision => 0,
1251
+ :scale => 0,
1252
+ :level => 0,
1253
+ :has_default => 0,
1254
+ :has_default? => false,
1255
+ :iomode => :out,
1256
+ :radix => 0,
1257
+ :type_name => "",
1258
+ :schema_name => "",
1259
+ :sub_name => "",
1260
+ :link => "",
1261
+ #:type_metadata => nil,
1262
+ :arguments => [],
1263
+ :inspect => '#<OCI8::Metadata::Argument: ARG2 VARCHAR2(0)>', # TODO: change to "VARCHAR2"
1264
+ },
1265
+ },
1266
+ :is_standalone? => false,
1267
+ :inspect => '#<OCI8::Metadata::Procedure: TEST_PROC>',
1268
+ },
1269
+ [3] => {
1270
+ :class => OCI8::Metadata::Procedure,
1271
+ :obj_id => nil,
1272
+ :obj_name => 'TEST_PROC',
1273
+ :obj_schema => nil,
1274
+ :is_invoker_rights? => true,
1275
+ :name => 'TEST_PROC',
1276
+ :overload_id => 1,
1277
+ :arguments => {
1278
+ :class => Array,
1279
+ :size => 1,
1280
+ [0] => {
1281
+ :class => OCI8::Metadata::Argument,
1282
+ :obj_id => nil,
1283
+ :obj_name => nil,
1284
+ :obj_schema => nil,
1285
+ :name => "ARG1",
1286
+ :position => 1,
1287
+ #:typecode => nil,
1288
+ :data_type => :number,
1289
+ :data_size => 22,
1290
+ :precision => 38,
1291
+ :scale => 0,
1292
+ :level => 0,
1293
+ :has_default => 0,
1294
+ :has_default? => false,
1295
+ :iomode => :in,
1296
+ :radix => 10,
1297
+ :type_name => "",
1298
+ :schema_name => "",
1299
+ :sub_name => "",
1300
+ :link => "",
1301
+ #:type_metadata => nil,
1302
+ :arguments => [],
1303
+ :inspect => '#<OCI8::Metadata::Argument: ARG1 NUMBER(38)>',
1304
+ },
1305
+ },
1306
+ :is_standalone? => false,
1307
+ :inspect => '#<OCI8::Metadata::Procedure: TEST_PROC>',
1308
+ },
1309
+ },
1310
+ :types => ($oracle_version >= OCI8::ORAVER_12_1) ? [] : :skip,
1311
+ :inspect => /#<OCI8::Metadata::Package:\(\d+\) #{@conn.username}.TEST_PKG>/,
1312
+ }
1035
1313
  [
1036
1314
  @conn.describe_any('test_pkg'),
1037
1315
  @conn.describe_package('test_pkg'),
@@ -1039,15 +1317,9 @@ EOS
1039
1317
  obj.obj_name == 'TEST_PKG'
1040
1318
  end
1041
1319
  ].each do |desc|
1042
- assert_instance_of(OCI8::Metadata::Package, desc)
1043
- assert_object_id('TEST_PKG', desc.obj_id)
1044
- assert_equal('TEST_PKG', desc.obj_name)
1045
- assert_equal(@conn.username, desc.obj_schema)
1046
- assert_equal(true, desc.is_invoker_rights?)
1047
- assert_instance_of(Array, desc.subprograms)
1048
- assert_equal(1, desc.subprograms.length)
1049
- assert_instance_of(OCI8::Metadata::Procedure, desc.subprograms[0])
1320
+ check_attributes("line: #{__LINE__}", desc, attrs)
1050
1321
  end
1322
+
1051
1323
  end # test_package_metadata
1052
1324
 
1053
1325
  def test_type_metadata
@@ -1064,6 +1336,7 @@ EOS
1064
1336
  drop_type('TEST_TYPE_CHILD')
1065
1337
  drop_type('TEST_TYPE_PARENT')
1066
1338
  expected_values = []
1339
+ attrs_map = {}
1067
1340
 
1068
1341
  @conn.exec(<<-EOS)
1069
1342
  CREATE TYPE test_type_parent AS OBJECT (
@@ -1073,8 +1346,11 @@ CREATE TYPE test_type_parent AS OBJECT (
1073
1346
  NOT INSTANTIABLE
1074
1347
  NOT FINAL
1075
1348
  EOS
1076
- expected_values << {
1349
+ attrs_map['TEST_TYPE_PARENT'] = {
1350
+ :class => OCI8::Metadata::Type,
1351
+ :obj_id => to_obj_id(@conn.username, 'TEST_TYPE_PARENT'),
1077
1352
  :obj_name => 'TEST_TYPE_PARENT',
1353
+ :obj_schema => @conn.username,
1078
1354
  :typecode => :named_type,
1079
1355
  :collection_typecode => nil,
1080
1356
  :is_incomplete_type? => false,
@@ -1091,13 +1367,28 @@ EOS
1091
1367
  :map_method => nil,
1092
1368
  :order_method => nil,
1093
1369
  :is_invoker_rights? => false,
1370
+ :name => 'TEST_TYPE_PARENT',
1371
+ :schema_name => @conn.username,
1094
1372
  :is_final_type? => false,
1095
1373
  :is_instantiable_type? => false,
1096
1374
  :is_subtype? => false,
1097
1375
  :supertype_schema_name => nil,
1098
1376
  :supertype_name => nil,
1099
- :type_attrs => [:array, 2, OCI8::Metadata::TypeAttr],
1100
- :type_methods => [:array, 0],
1377
+ :package_name => nil,
1378
+ :type_attrs => {
1379
+ :class => Array,
1380
+ :size => 2,
1381
+ [0] => {
1382
+ :class => OCI8::Metadata::TypeAttr,
1383
+ :inspect => '#<OCI8::Metadata::TypeAttr: COL1 NUMBER(38)>',
1384
+ },
1385
+ [1] => {
1386
+ :class => OCI8::Metadata::TypeAttr,
1387
+ :inspect => '#<OCI8::Metadata::TypeAttr: COL2 VARCHAR2(60)>',
1388
+ },
1389
+ },
1390
+ :type_methods => [],
1391
+ :inspect => /#<OCI8::Metadata::Type:\(\d+\) #{@conn.username}.TEST_TYPE_PARENT>/,
1101
1392
  }
1102
1393
  @conn.exec(<<-EOS)
1103
1394
  CREATE TYPE test_type_child UNDER test_type_parent (
@@ -1105,8 +1396,11 @@ CREATE TYPE test_type_child UNDER test_type_parent (
1105
1396
  )
1106
1397
  NOT FINAL
1107
1398
  EOS
1108
- expected_values << {
1399
+ attrs_map['TEST_TYPE_CHILD'] = {
1400
+ :class => OCI8::Metadata::Type,
1401
+ :obj_id => to_obj_id(@conn.username, 'TEST_TYPE_CHILD'),
1109
1402
  :obj_name => 'TEST_TYPE_CHILD',
1403
+ :obj_schema => @conn.username,
1110
1404
  :typecode => :named_type,
1111
1405
  :collection_typecode => nil,
1112
1406
  :is_incomplete_type? => false,
@@ -1123,19 +1417,35 @@ EOS
1123
1417
  :map_method => nil,
1124
1418
  :order_method => nil,
1125
1419
  :is_invoker_rights? => false,
1420
+ :name => 'TEST_TYPE_CHILD',
1421
+ :schema_name => @conn.username,
1126
1422
  :is_final_type? => false,
1127
1423
  :is_instantiable_type? => true,
1128
1424
  :is_subtype? => true,
1129
1425
  :supertype_schema_name => @conn.username,
1130
1426
  :supertype_name => 'TEST_TYPE_PARENT',
1131
- :type_attrs => [:array, 3, OCI8::Metadata::TypeAttr],
1132
- :type_methods => [:array, 0],
1427
+ :package_name => nil,
1428
+ :type_attrs => {
1429
+ :class => Array,
1430
+ :size => 3,
1431
+ [0] => attrs_map['TEST_TYPE_PARENT'][:type_attrs][[0]],
1432
+ [1] => attrs_map['TEST_TYPE_PARENT'][:type_attrs][[1]],
1433
+ [2] => {
1434
+ :class => OCI8::Metadata::TypeAttr,
1435
+ :inspect => '#<OCI8::Metadata::TypeAttr: LOB BLOB>',
1436
+ },
1437
+ },
1438
+ :type_methods => [],
1439
+ :inspect => /#<OCI8::Metadata::Type:\(\d+\) #{@conn.username}.TEST_TYPE_CHILD>/,
1133
1440
  }
1134
1441
  @conn.exec(<<-EOS)
1135
1442
  CREATE TYPE test_type_nestead_table AS TABLE OF test_type_child
1136
1443
  EOS
1137
- expected_values << {
1444
+ attrs_map['TEST_TYPE_NESTEAD_TABLE'] = {
1445
+ :class => OCI8::Metadata::Type,
1446
+ :obj_id => to_obj_id(@conn.username, 'TEST_TYPE_NESTEAD_TABLE'),
1138
1447
  :obj_name => 'TEST_TYPE_NESTEAD_TABLE',
1448
+ :obj_schema => @conn.username,
1139
1449
  :typecode => :named_collection,
1140
1450
  :collection_typecode => :table,
1141
1451
  :is_incomplete_type? => false,
@@ -1146,25 +1456,93 @@ EOS
1146
1456
  :has_nested_table? => true,
1147
1457
  :has_lob? => true,
1148
1458
  :has_file? => false,
1149
- :collection_element => [:type, OCI8::Metadata::Collection],
1459
+ :collection_element => {
1460
+ :class => OCI8::Metadata::Collection,
1461
+ :obj_id => nil,
1462
+ :obj_name => nil,
1463
+ :obj_schema => nil,
1464
+ :data_size => 0,
1465
+ :typecode => :named_type,
1466
+ :data_type => :named_type,
1467
+ :num_elems => 0,
1468
+ :precision => 0,
1469
+ :scale => 0,
1470
+ :type_name => 'TEST_TYPE_CHILD',
1471
+ :schema_name => @conn.username,
1472
+ :type_metadata => {
1473
+ :class => OCI8::Metadata::Type,
1474
+ :obj_id => 0,
1475
+ :obj_name => nil,
1476
+ :obj_schema => nil,
1477
+ :typecode => :named_type,
1478
+ :collection_typecode => nil,
1479
+ :is_incomplete_type? => false,
1480
+ :is_system_type? => false,
1481
+ :is_predefined_type? => false,
1482
+ :is_transient_type? => false,
1483
+ :is_system_generated_type? => false,
1484
+ :has_nested_table? => false,
1485
+ :has_lob? => true,
1486
+ :has_file? => false,
1487
+ :collection_element => nil,
1488
+ :num_type_attrs => 3,
1489
+ :num_type_methods => 0,
1490
+ :map_method => nil,
1491
+ :order_method => nil,
1492
+ :is_invoker_rights? => false,
1493
+ :name => 'TEST_TYPE_CHILD',
1494
+ :schema_name => @conn.username,
1495
+ :is_final_type? => false,
1496
+ :is_instantiable_type? => true,
1497
+ :is_subtype? => true,
1498
+ :supertype_schema_name => @conn.username,
1499
+ :supertype_name => 'TEST_TYPE_PARENT',
1500
+ :package_name => nil,
1501
+ :type_attrs => {
1502
+ :class => Array,
1503
+ :size => 3,
1504
+ [0] => {
1505
+ :class => OCI8::Metadata::TypeAttr,
1506
+ :inspect => '#<OCI8::Metadata::TypeAttr: COL1 NUMBER(38)>',
1507
+ },
1508
+ [1] => {
1509
+ :class => OCI8::Metadata::TypeAttr,
1510
+ :inspect => '#<OCI8::Metadata::TypeAttr: COL2 VARCHAR2(60)>',
1511
+ },
1512
+ [2] => {
1513
+ :class => OCI8::Metadata::TypeAttr,
1514
+ :inspect => '#<OCI8::Metadata::TypeAttr: LOB BLOB>',
1515
+ },
1516
+ },
1517
+ :inspect => "#<OCI8::Metadata::Type:(0) #{@conn.username}.TEST_TYPE_CHILD>",
1518
+ },
1519
+ :inspect => "#<OCI8::Metadata::Collection: #{@conn.username}.TEST_TYPE_CHILD>",
1520
+ },
1150
1521
  :num_type_attrs => 0,
1151
1522
  :num_type_methods => 0,
1152
1523
  :map_method => nil,
1153
1524
  :order_method => nil,
1154
1525
  :is_invoker_rights? => false,
1526
+ :name => 'TEST_TYPE_NESTEAD_TABLE',
1527
+ :schema_name => @conn.username,
1155
1528
  :is_final_type? => true,
1156
1529
  :is_instantiable_type? => true,
1157
1530
  :is_subtype? => false,
1158
1531
  :supertype_schema_name => nil,
1159
1532
  :supertype_name => nil,
1160
- :type_attrs => [:array, 0],
1161
- :type_methods => [:array, 0],
1533
+ :package_name => nil,
1534
+ :type_attrs => [],
1535
+ :type_methods => [],
1536
+ :inspect => /#<OCI8::Metadata::Type:\(\d+\) #{@conn.username}.TEST_TYPE_NESTEAD_TABLE>/,
1162
1537
  }
1163
1538
  @conn.exec(<<-EOS)
1164
1539
  CREATE TYPE test_type_varray AS VARRAY(10) OF test_type_child
1165
1540
  EOS
1166
- expected_values << {
1541
+ attrs_map['TEST_TYPE_VARRAY'] = {
1542
+ :class => OCI8::Metadata::Type,
1543
+ :obj_id => to_obj_id(@conn.username, 'TEST_TYPE_VARRAY'),
1167
1544
  :obj_name => 'TEST_TYPE_VARRAY',
1545
+ :obj_schema => @conn.username,
1168
1546
  :typecode => :named_collection,
1169
1547
  :collection_typecode => :varray,
1170
1548
  :is_incomplete_type? => false,
@@ -1175,19 +1553,38 @@ EOS
1175
1553
  :has_nested_table? => false,
1176
1554
  :has_lob? => true,
1177
1555
  :has_file? => false,
1178
- :collection_element => [:type, OCI8::Metadata::Collection],
1556
+ :collection_element => {
1557
+ :class => OCI8::Metadata::Collection,
1558
+ :obj_id => nil,
1559
+ :obj_name => nil,
1560
+ :obj_schema => nil,
1561
+ :data_size => 0,
1562
+ :typecode => :named_type,
1563
+ :data_type => :named_type,
1564
+ :num_elems => 10,
1565
+ :precision => 0,
1566
+ :scale => 0,
1567
+ :type_name => 'TEST_TYPE_CHILD',
1568
+ :schema_name => @conn.username,
1569
+ :type_metadata => attrs_map['TEST_TYPE_NESTEAD_TABLE'][:collection_element][:type_metadata],
1570
+ :inspect => "#<OCI8::Metadata::Collection: #{@conn.username}.TEST_TYPE_CHILD>",
1571
+ },
1179
1572
  :num_type_attrs => 0,
1180
1573
  :num_type_methods => 0,
1181
1574
  :map_method => nil,
1182
1575
  :order_method => nil,
1183
1576
  :is_invoker_rights? => false,
1577
+ :name => 'TEST_TYPE_VARRAY',
1578
+ :schema_name => @conn.username,
1184
1579
  :is_final_type? => true,
1185
1580
  :is_instantiable_type? => true,
1186
1581
  :is_subtype? => false,
1187
1582
  :supertype_schema_name => nil,
1188
1583
  :supertype_name => nil,
1189
- :type_attrs => [:array, 0],
1190
- :type_methods => [:array, 0],
1584
+ :package_name => nil,
1585
+ :type_attrs => [],
1586
+ :type_methods => [],
1587
+ :inspect => /#<OCI8::Metadata::Type:\(\d+\) #{@conn.username}.TEST_TYPE_VARRAY>/,
1191
1588
  }
1192
1589
  @conn.exec(<<-EOS)
1193
1590
  CREATE TYPE test_type_grandchild UNDER test_type_child (
@@ -1195,8 +1592,11 @@ CREATE TYPE test_type_grandchild UNDER test_type_child (
1195
1592
  file_column BFILE
1196
1593
  )
1197
1594
  EOS
1198
- expected_values << {
1595
+ attrs_map['TEST_TYPE_GRANDCHILD'] = {
1596
+ :class => OCI8::Metadata::Type,
1597
+ :obj_id => to_obj_id(@conn.username, 'TEST_TYPE_GRANDCHILD'),
1199
1598
  :obj_name => 'TEST_TYPE_GRANDCHILD',
1599
+ :obj_schema => @conn.username,
1200
1600
  :typecode => :named_type,
1201
1601
  :collection_typecode => nil,
1202
1602
  :is_incomplete_type? => false,
@@ -1213,19 +1613,40 @@ EOS
1213
1613
  :map_method => nil,
1214
1614
  :order_method => nil,
1215
1615
  :is_invoker_rights? => false,
1616
+ :name => 'TEST_TYPE_GRANDCHILD',
1617
+ :schema_name => @conn.username,
1216
1618
  :is_final_type? => true,
1217
1619
  :is_instantiable_type? => true,
1218
1620
  :is_subtype? => true,
1219
1621
  :supertype_schema_name => @conn.username,
1220
1622
  :supertype_name => 'TEST_TYPE_CHILD',
1221
- :type_attrs => [:array, 5, OCI8::Metadata::TypeAttr],
1222
- :type_methods => [:array, 0],
1623
+ :package_name => nil,
1624
+ :type_attrs => {
1625
+ :class => Array,
1626
+ :size => 5,
1627
+ [0] => attrs_map['TEST_TYPE_CHILD'][:type_attrs][[0]],
1628
+ [1] => attrs_map['TEST_TYPE_CHILD'][:type_attrs][[1]],
1629
+ [2] => attrs_map['TEST_TYPE_CHILD'][:type_attrs][[2]],
1630
+ [3] => {
1631
+ :class => OCI8::Metadata::TypeAttr,
1632
+ :inspect => "#<OCI8::Metadata::TypeAttr: TABLE_COLUMN #{@conn.username}.TEST_TYPE_NESTEAD_TABLE>",
1633
+ },
1634
+ [4] => {
1635
+ :class => OCI8::Metadata::TypeAttr,
1636
+ :inspect => '#<OCI8::Metadata::TypeAttr: FILE_COLUMN BFILE>',
1637
+ },
1638
+ },
1639
+ :type_methods => [],
1640
+ :inspect => /#<OCI8::Metadata::Type:\(\d+\) #{@conn.username}.TEST_TYPE_GRANDCHILD>/,
1223
1641
  }
1224
1642
  @conn.exec(<<-EOS)
1225
1643
  CREATE TYPE test_type_incomplete
1226
1644
  EOS
1227
- expected_values << {
1645
+ attrs_map['TEST_TYPE_INCOMPLETE'] = {
1646
+ :class => OCI8::Metadata::Type,
1647
+ :obj_id => to_obj_id(@conn.username, 'TEST_TYPE_INCOMPLETE'),
1228
1648
  :obj_name => 'TEST_TYPE_INCOMPLETE',
1649
+ :obj_schema => @conn.username,
1229
1650
  :typecode => :named_type,
1230
1651
  :collection_typecode => nil,
1231
1652
  :is_incomplete_type? => true,
@@ -1242,20 +1663,23 @@ EOS
1242
1663
  :map_method => nil,
1243
1664
  :order_method => nil,
1244
1665
  :is_invoker_rights? => false,
1666
+ :name => 'TEST_TYPE_INCOMPLETE',
1667
+ :schema_name => @conn.username,
1245
1668
  :is_final_type? => true,
1246
1669
  :is_instantiable_type? => true,
1247
1670
  :is_subtype? => false,
1248
1671
  :supertype_schema_name => nil,
1249
1672
  :supertype_name => nil,
1250
- :type_attrs => [:array, 0],
1251
- :type_methods => [:array, 0],
1673
+ :package_name => nil,
1674
+ :type_attrs => [],
1675
+ :type_methods => [],
1676
+ :inspect => /#<OCI8::Metadata::Type:\(\d+\) #{@conn.username}.TEST_TYPE_INCOMPLETE>/,
1252
1677
  }
1253
-
1254
1678
  @conn.exec(<<-EOS)
1255
1679
  CREATE TYPE test_type_has_clob AS OBJECT (lob CLOB)
1256
1680
  EOS
1257
- expected_values << {
1258
- :obj_name => 'TEST_TYPE_HAS_CLOB',
1681
+ attrs_map['TEST_TYPE_HAS_CLOB'] = {
1682
+ :class => OCI8::Metadata::Type,
1259
1683
  :has_lob? => true,
1260
1684
  :has_file? => false,
1261
1685
  }
@@ -1263,8 +1687,8 @@ EOS
1263
1687
  @conn.exec(<<-EOS)
1264
1688
  CREATE TYPE test_type_has_nclob AS OBJECT (lob NCLOB)
1265
1689
  EOS
1266
- expected_values << {
1267
- :obj_name => 'TEST_TYPE_HAS_NCLOB',
1690
+ attrs_map['TEST_TYPE_HAS_NCLOB'] = {
1691
+ :class => OCI8::Metadata::Type,
1268
1692
  :has_lob? => true,
1269
1693
  :has_file? => false,
1270
1694
  }
@@ -1272,16 +1696,16 @@ EOS
1272
1696
  @conn.exec(<<-EOS)
1273
1697
  CREATE TYPE test_type_has_blob AS OBJECT (lob BLOB)
1274
1698
  EOS
1275
- expected_values << {
1276
- :obj_name => 'TEST_TYPE_HAS_BLOB',
1699
+ attrs_map['TEST_TYPE_HAS_BLOB'] = {
1700
+ :class => OCI8::Metadata::Type,
1277
1701
  :has_lob? => true,
1278
1702
  :has_file? => false,
1279
1703
  }
1280
1704
  @conn.exec(<<-EOS)
1281
1705
  CREATE TYPE test_type_has_bfile AS OBJECT (lob BFILE)
1282
1706
  EOS
1283
- expected_values << {
1284
- :obj_name => 'TEST_TYPE_HAS_BFILE',
1707
+ attrs_map['TEST_TYPE_HAS_BFILE'] = {
1708
+ :class => OCI8::Metadata::Type,
1285
1709
  :has_lob? => false,
1286
1710
  :has_file? => true,
1287
1711
  }
@@ -1292,9 +1716,60 @@ CREATE TYPE test_type_map_method AS OBJECT (
1292
1716
  MAP MEMBER FUNCTION area RETURN NUMBER
1293
1717
  )
1294
1718
  EOS
1295
- expected_values << {
1296
- :obj_name => 'TEST_TYPE_MAP_METHOD',
1297
- :map_method => [:type, OCI8::Metadata::TypeMethod],
1719
+ attrs_map['TEST_TYPE_MAP_METHOD'] = {
1720
+ :class => OCI8::Metadata::Type,
1721
+ :map_method => {
1722
+ :class => OCI8::Metadata::TypeMethod,
1723
+ :name => 'AREA',
1724
+ :encapsulation => :public,
1725
+ :has_result? => true,
1726
+ :is_constructor? => false,
1727
+ :is_destructor? => false,
1728
+ :is_operator? => false,
1729
+ :is_selfish? => true,
1730
+ :is_map? => true,
1731
+ :is_order? => false,
1732
+ :is_rnds? => true,
1733
+ :is_rnps? => true,
1734
+ :is_wnds? => true,
1735
+ :is_wnps? => true,
1736
+ :is_final_method? => false,
1737
+ :is_instantiable_method? => true,
1738
+ :is_overriding_method? => false,
1739
+ :arguments => {
1740
+ :class => Array,
1741
+ :size => 1,
1742
+ [0] => {
1743
+ :class => OCI8::Metadata::TypeArgument,
1744
+ :obj_id => nil,
1745
+ :obj_name => nil,
1746
+ :obj_schema => nil,
1747
+ :name => "SELF",
1748
+ :position => 1,
1749
+ #:typecode => nil,
1750
+ :data_type => :named_type,
1751
+ #:data_size => 0, # ORA-24328: illegal attribute value
1752
+ #:precision => 0, # ORA-24328: illegal attribute value
1753
+ #:scale => 0, # ORA-24328: illegal attribute value
1754
+ :level => 0,
1755
+ :has_default => 0,
1756
+ :has_default? => false,
1757
+ :iomode => :in,
1758
+ #:radix => 0, # ORA-24328: illegal attribute value
1759
+ :type_name => "TEST_TYPE_MAP_METHOD",
1760
+ :schema_name => @conn.username,
1761
+ #:sub_name => nil, # ORA-24328: illegal attribute value
1762
+ #:link => nil, # ORA-24328: illegal attribute value
1763
+ :type_metadata => {
1764
+ :class => OCI8::Metadata::Type,
1765
+ :inspect => "#<OCI8::Metadata::Type:(0) #{@conn.username}.TEST_TYPE_MAP_METHOD>",
1766
+ },
1767
+ :arguments => [],
1768
+ :inspect => "#<OCI8::Metadata::TypeArgument: SELF #{@conn.username}.TEST_TYPE_MAP_METHOD>",
1769
+ },
1770
+ },
1771
+ :inspect => '#<OCI8::Metadata::TypeMethod: AREA>',
1772
+ },
1298
1773
  :order_method => nil,
1299
1774
  }
1300
1775
  @conn.exec(<<-EOS)
@@ -1304,42 +1779,100 @@ CREATE TYPE test_type_order_method AS OBJECT (
1304
1779
  ORDER MEMBER FUNCTION match(l test_type_order_method) RETURN INTEGER
1305
1780
  )
1306
1781
  EOS
1307
- expected_values << {
1308
- :obj_name => 'TEST_TYPE_ORDER_METHOD',
1782
+ attrs_map['TEST_TYPE_ORDER_METHOD'] = {
1783
+ :class => OCI8::Metadata::Type,
1309
1784
  :map_method => nil,
1310
- :order_method => [:type, OCI8::Metadata::TypeMethod],
1785
+ :order_method => {
1786
+ :class => OCI8::Metadata::TypeMethod,
1787
+ :name => 'MATCH',
1788
+ :encapsulation => :public,
1789
+ :has_result? => true,
1790
+ :is_constructor? => false,
1791
+ :is_destructor? => false,
1792
+ :is_operator? => false,
1793
+ :is_selfish? => true,
1794
+ :is_map? => false,
1795
+ :is_order? => true,
1796
+ :is_rnds? => true,
1797
+ :is_rnps? => true,
1798
+ :is_wnds? => true,
1799
+ :is_wnps? => true,
1800
+ :is_final_method? => false,
1801
+ :is_instantiable_method? => true,
1802
+ :is_overriding_method? => false,
1803
+ :arguments => {
1804
+ :class => Array,
1805
+ :size => 2,
1806
+ [0] => {
1807
+ :class => OCI8::Metadata::TypeArgument,
1808
+ :obj_id => nil,
1809
+ :obj_name => nil,
1810
+ :obj_schema => nil,
1811
+ :name => "SELF",
1812
+ :position => 1,
1813
+ :typecode => :named_type,
1814
+ :data_type => :named_type,
1815
+ #:data_size => 0, # ORA-24328: illegal attribute value
1816
+ #:precision => 0, # ORA-24328: illegal attribute value
1817
+ #:scale => 0, # ORA-24328: illegal attribute value
1818
+ :level => 0,
1819
+ :has_default => 0,
1820
+ :has_default? => false,
1821
+ :iomode => :in,
1822
+ #:radix => 0, # ORA-24328: illegal attribute value
1823
+ :type_name => "TEST_TYPE_ORDER_METHOD",
1824
+ :schema_name => @conn.username,
1825
+ #:sub_name => nil, # ORA-24328: illegal attribute value
1826
+ #:link => nil, # ORA-24328: illegal attribute value
1827
+ :type_metadata => {
1828
+ :class => OCI8::Metadata::Type,
1829
+ :inspect => "#<OCI8::Metadata::Type:(0) #{@conn.username}.TEST_TYPE_ORDER_METHOD>",
1830
+ },
1831
+ :arguments => [],
1832
+ :inspect => "#<OCI8::Metadata::TypeArgument: SELF #{@conn.username}.TEST_TYPE_ORDER_METHOD>",
1833
+ },
1834
+ [1] => {
1835
+ :class => OCI8::Metadata::TypeArgument,
1836
+ :obj_id => nil,
1837
+ :obj_name => nil,
1838
+ :obj_schema => nil,
1839
+ :name => "L",
1840
+ :position => 2,
1841
+ :typecode => :named_type,
1842
+ :data_type => :named_type,
1843
+ #:data_size => 0, # ORA-24328: illegal attribute value
1844
+ #:precision => 0, # ORA-24328: illegal attribute value
1845
+ #:scale => 0, # ORA-24328: illegal attribute value
1846
+ :level => 0,
1847
+ :has_default => 0,
1848
+ :has_default? => false,
1849
+ :iomode => :in,
1850
+ #:radix => 0, # ORA-24328: illegal attribute value
1851
+ :type_name => "TEST_TYPE_ORDER_METHOD",
1852
+ :schema_name => @conn.username,
1853
+ #:sub_name => nil, # ORA-24328: illegal attribute value
1854
+ #:link => nil, # ORA-24328: illegal attribute value
1855
+ :type_metadata => {
1856
+ :class => OCI8::Metadata::Type,
1857
+ :inspect => "#<OCI8::Metadata::Type:(0) #{@conn.username}.TEST_TYPE_ORDER_METHOD>",
1858
+ },
1859
+ :arguments => [],
1860
+ :inspect => "#<OCI8::Metadata::TypeArgument: L #{@conn.username}.TEST_TYPE_ORDER_METHOD>",
1861
+ },
1862
+ },
1863
+ :inspect => '#<OCI8::Metadata::TypeMethod: MATCH>',
1864
+ },
1311
1865
  }
1312
1866
 
1313
- expected_values.each do |elem|
1867
+ attrs_map.each do |name, attrs|
1314
1868
  [
1315
- @conn.describe_any(elem[:obj_name]),
1316
- @conn.describe_type(elem[:obj_name]),
1869
+ @conn.describe_any(name),
1870
+ @conn.describe_type(name),
1317
1871
  @conn.describe_schema(@conn.username).objects.detect do |obj|
1318
- obj.obj_name == elem[:obj_name]
1872
+ obj.obj_name == name
1319
1873
  end,
1320
1874
  ].each do |desc|
1321
- assert_object_id(elem[:obj_name], desc.obj_id)
1322
- assert_equal(@conn.username, desc.obj_schema)
1323
- assert_equal(elem[:obj_name], desc.name)
1324
- assert_equal(@conn.username, desc.schema_name)
1325
-
1326
- elem.each do |key, val|
1327
- msg = elem[:obj_name] + '.' + key.to_s
1328
- if val.is_a? Array
1329
- case val[0]
1330
- when :array
1331
- assert_instance_of(Array, desc.send(key), msg)
1332
- assert_equal(val[1], desc.send(key).length)
1333
- assert_instance_of(val[2], desc.send(key)[0]) if val[1] > 0
1334
- when :type
1335
- assert_instance_of(val[1], desc.send(key), msg)
1336
- else
1337
- raise "Invalid test case: #{elem[:obj_name]}.#{key} : #{val[0]}"
1338
- end
1339
- else
1340
- assert_equal(val, desc.send(key), msg)
1341
- end
1342
- end
1875
+ check_attributes(name, desc, attrs)
1343
1876
  end
1344
1877
  end
1345
1878
 
@@ -1358,22 +1891,570 @@ EOS
1358
1891
  end # test_type_metadata
1359
1892
 
1360
1893
  def test_column_metadata
1361
- if $oracle_version < OCI8::ORAVER_8_1
1362
- begin
1363
- @conn.describe_table('tab').columns
1364
- rescue RuntimeError
1365
- assert_equal("This feature is unavailable on Oracle 8.0", $!.to_s)
1366
- end
1367
- return
1894
+
1895
+ # Get data_size of NCHAR(1) and that of CHAR(1 CHAR).
1896
+ # They depend on the database character set and the
1897
+ # client character set.
1898
+ @conn.exec('CREATE TABLE test_table (nc NCHAR(1), c CHAR(1 CHAR))')
1899
+ cursor = @conn.exec("select * from test_table")
1900
+ cfrm = cursor.column_metadata[0].data_size # size of NCHAR(1) in bytes
1901
+ csem = cursor.column_metadata[1].data_size # size of CHAR(1 CHAR) in bytes
1902
+ cursor.close
1903
+ drop_table('test_table')
1904
+
1905
+ column_attrs_list = []
1906
+
1907
+ column_attrs_list << {
1908
+ :name => 'CHAR_10_NOT_NULL_COL',
1909
+ :data_type_string => 'CHAR(10) NOT NULL',
1910
+ :data_type => :char,
1911
+ :charset_form => :implicit,
1912
+ :nullable? => false,
1913
+ :char_used? => false,
1914
+ :char_size => 10,
1915
+ :data_size => 10,
1916
+ :precision => 0,
1917
+ :scale => 0,
1918
+ :fsprecision => 0,
1919
+ :lfprecision => 0,
1920
+ :inspect => '#<OCI8::Metadata::Column: CHAR_10_NOT_NULL_COL CHAR(10) NOT NULL>',
1921
+ }
1922
+ column_attrs_list << {
1923
+ :name => 'CHAR_10_CHAR_COL',
1924
+ :data_type_string => 'CHAR(10 CHAR)',
1925
+ :data_type => :char,
1926
+ :charset_form => :implicit,
1927
+ :nullable? => true,
1928
+ :char_used? => true,
1929
+ :char_size => 10,
1930
+ :data_size => 10 * csem,
1931
+ :precision => 0,
1932
+ :scale => 0,
1933
+ :fsprecision => 0,
1934
+ :lfprecision => 0,
1935
+ :inspect => '#<OCI8::Metadata::Column: CHAR_10_CHAR_COL CHAR(10 CHAR)>',
1936
+ }
1937
+ column_attrs_list << {
1938
+ :name => 'NCHAR_10_COL',
1939
+ :data_type_string => 'NCHAR(10)',
1940
+ :data_type => :char,
1941
+ :charset_form => :nchar,
1942
+ :nullable? => true,
1943
+ :char_used? => true,
1944
+ :char_size => 10,
1945
+ :data_size => 10 * cfrm,
1946
+ :precision => 0,
1947
+ :scale => 0,
1948
+ :fsprecision => 0,
1949
+ :lfprecision => 0,
1950
+ :inspect => '#<OCI8::Metadata::Column: NCHAR_10_COL NCHAR(10)>',
1951
+ }
1952
+ column_attrs_list << {
1953
+ :name => 'VARCHAR2_10_COL',
1954
+ :data_type_string => 'VARCHAR2(10)',
1955
+ :data_type => :varchar2,
1956
+ :charset_form => :implicit,
1957
+ :nullable? => true,
1958
+ :char_used? => false,
1959
+ :char_size => 10,
1960
+ :data_size => 10,
1961
+ :precision => 0,
1962
+ :scale => 0,
1963
+ :fsprecision => 0,
1964
+ :lfprecision => 0,
1965
+ :inspect => '#<OCI8::Metadata::Column: VARCHAR2_10_COL VARCHAR2(10)>',
1966
+ }
1967
+ column_attrs_list << {
1968
+ :name => 'VARCHAR2_10_CHAR_COL',
1969
+ :data_type_string => 'VARCHAR2(10 CHAR)',
1970
+ :data_type => :varchar2,
1971
+ :charset_form => :implicit,
1972
+ :nullable? => true,
1973
+ :char_used? => true,
1974
+ :char_size => 10,
1975
+ :data_size => 10 * csem,
1976
+ :precision => 0,
1977
+ :scale => 0,
1978
+ :fsprecision => 0,
1979
+ :lfprecision => 0,
1980
+ :inspect => '#<OCI8::Metadata::Column: VARCHAR2_10_CHAR_COL VARCHAR2(10 CHAR)>',
1981
+ }
1982
+ column_attrs_list << {
1983
+ :name => 'NVARCHAR2_10_COL',
1984
+ :data_type_string => 'NVARCHAR2(10)',
1985
+ :data_type => :varchar2,
1986
+ :charset_form => :nchar,
1987
+ :nullable? => true,
1988
+ :char_used? => true,
1989
+ :char_size => 10,
1990
+ :data_size => 10 * cfrm,
1991
+ :precision => 0,
1992
+ :scale => 0,
1993
+ :fsprecision => 0,
1994
+ :lfprecision => 0,
1995
+ :inspect => '#<OCI8::Metadata::Column: NVARCHAR2_10_COL NVARCHAR2(10)>',
1996
+ }
1997
+ column_attrs_list << {
1998
+ :name => 'RAW_10_COL',
1999
+ :data_type_string => 'RAW(10)',
2000
+ :data_type => :raw,
2001
+ :charset_form => nil,
2002
+ :nullable? => true,
2003
+ :char_used? => false,
2004
+ :char_size => 0,
2005
+ :data_size => 10,
2006
+ :precision => 0,
2007
+ :scale => 0,
2008
+ :fsprecision => 0,
2009
+ :lfprecision => 0,
2010
+ :inspect => '#<OCI8::Metadata::Column: RAW_10_COL RAW(10)>',
2011
+ }
2012
+
2013
+ # Skip tests for data_size of CLOB, NCLOB and BLOB
2014
+ # because their values depend on how they are described.
2015
+ #
2016
+ # Oracle 10g XE 10.2.0.1.0 on Linux:
2017
+ # +----------------+-----------+
2018
+ # | | data_size |
2019
+ # +----------------+-----------+
2020
+ # | implicitly(*1) | 4000 |
2021
+ # | explicitly(*2) | 86 |
2022
+ # +----------------+-----------+
2023
+ #
2024
+ # *1 explicitly described by column definition.
2025
+ # *2 implicitly described by select list.
2026
+ column_attrs_list << {
2027
+ :name => 'CLOB_COL',
2028
+ :data_type_string => 'CLOB',
2029
+ :data_type => :clob,
2030
+ :charset_form => :implicit,
2031
+ :nullable? => true,
2032
+ :char_used? => false,
2033
+ :char_size => 0,
2034
+ :data_size => :skip,
2035
+ :precision => 0,
2036
+ :scale => 0,
2037
+ :fsprecision => 0,
2038
+ :lfprecision => 0,
2039
+ :inspect => '#<OCI8::Metadata::Column: CLOB_COL CLOB>',
2040
+ }
2041
+ column_attrs_list << {
2042
+ :name => 'NCLOB_COL',
2043
+ :data_type_string => 'NCLOB',
2044
+ :data_type => :clob,
2045
+ :charset_form => :nchar,
2046
+ :nullable? => true,
2047
+ :char_used? => false,
2048
+ :char_size => 0,
2049
+ :data_size => :skip,
2050
+ :precision => 0,
2051
+ :scale => 0,
2052
+ :fsprecision => 0,
2053
+ :lfprecision => 0,
2054
+ :inspect => '#<OCI8::Metadata::Column: NCLOB_COL NCLOB>',
2055
+ }
2056
+ column_attrs_list << {
2057
+ :name => 'BLOB_COL',
2058
+ :data_type_string => 'BLOB',
2059
+ :data_type => :blob,
2060
+ :charset_form => nil,
2061
+ :nullable? => true,
2062
+ :char_used? => false,
2063
+ :char_size => 0,
2064
+ :data_size => :skip,
2065
+ :precision => 0,
2066
+ :scale => 0,
2067
+ :fsprecision => 0,
2068
+ :lfprecision => 0,
2069
+ :inspect => '#<OCI8::Metadata::Column: BLOB_COL BLOB>',
2070
+ }
2071
+ column_attrs_list << {
2072
+ :name => 'BFILE_COL',
2073
+ :data_type_string => 'BFILE',
2074
+ :data_type => :bfile,
2075
+ :charset_form => nil,
2076
+ :nullable? => true,
2077
+ :char_used? => false,
2078
+ :char_size => 0,
2079
+ :data_size => 530,
2080
+ :precision => 0,
2081
+ :scale => 0,
2082
+ :fsprecision => 0,
2083
+ :lfprecision => 0,
2084
+ :inspect => '#<OCI8::Metadata::Column: BFILE_COL BFILE>',
2085
+ }
2086
+
2087
+ # Skip tests for fsprecision and lfprecision for NUMBER and FLOAT
2088
+ # because their values depend on how they are described.
2089
+ #
2090
+ # Oracle 10g XE 10.2.0.1.0 on Linux:
2091
+ # +-----------------------------+-------------+-------------+
2092
+ # | | fsprecision | lfprecision |
2093
+ # +----------------+------------+-------------+-------------+
2094
+ # | NUMBER | implicitly | 129 | 0 |
2095
+ # | | explicitly | 0 | 129 |
2096
+ # +----------------+------------+-------------+-------------+
2097
+ # | NUMBER(10) | implicitly | 0 | 10 |
2098
+ # | | explicitly | 10 | 0 |
2099
+ # +----------------+------------+-------------+-------------+
2100
+ # | NUMBER(10,2) | implicitly | 2 | 10 |
2101
+ # | | explicitly | 10 | 2 |
2102
+ # +----------------+------------+-------------+-------------+
2103
+ # | FLOAT | implicitly | 129 | 126 |
2104
+ # | | explicitly | 126 | 129 |
2105
+ # +----------------+------------+-------------+-------------+
2106
+ # | FLOAT(10) | implicitly | 129 | 10 |
2107
+ # | | explicitly | 10 | 129 |
2108
+ # +----------------+------------+-------------+-------------+
2109
+ column_attrs_list << {
2110
+ :name => 'NUMBER_COL',
2111
+ :data_type_string => 'NUMBER',
2112
+ :data_type => :number,
2113
+ :charset_form => nil,
2114
+ :nullable? => true,
2115
+ :char_used? => false,
2116
+ :char_size => 0,
2117
+ :data_size => 22,
2118
+ :precision => 0,
2119
+ :scale => -127,
2120
+ :fsprecision => :skip,
2121
+ :lfprecision => :skip,
2122
+ :inspect => '#<OCI8::Metadata::Column: NUMBER_COL NUMBER>',
2123
+ }
2124
+ column_attrs_list << {
2125
+ :name => 'NUMBER_10_COL',
2126
+ :data_type_string => 'NUMBER(10)',
2127
+ :data_type => :number,
2128
+ :charset_form => nil,
2129
+ :nullable? => true,
2130
+ :char_used? => false,
2131
+ :char_size => 0,
2132
+ :data_size => 22,
2133
+ :precision => 10,
2134
+ :scale => 0,
2135
+ :fsprecision => :skip,
2136
+ :lfprecision => :skip,
2137
+ :inspect => '#<OCI8::Metadata::Column: NUMBER_10_COL NUMBER(10)>',
2138
+ }
2139
+ column_attrs_list << {
2140
+ :name => 'NUMBER_10_2_COL',
2141
+ :data_type_string => 'NUMBER(10,2)',
2142
+ :data_type => :number,
2143
+ :charset_form => nil,
2144
+ :nullable? => true,
2145
+ :char_used? => false,
2146
+ :char_size => 0,
2147
+ :data_size => 22,
2148
+ :precision => 10,
2149
+ :scale => 2,
2150
+ :fsprecision => :skip,
2151
+ :lfprecision => :skip,
2152
+ :inspect => '#<OCI8::Metadata::Column: NUMBER_10_2_COL NUMBER(10,2)>',
2153
+ }
2154
+ column_attrs_list << {
2155
+ :name => 'FLOAT_COL',
2156
+ :data_type_string => 'FLOAT',
2157
+ :data_type => :number,
2158
+ :charset_form => nil,
2159
+ :nullable? => true,
2160
+ :char_used? => false,
2161
+ :char_size => 0,
2162
+ :data_size => 22,
2163
+ :precision => 126,
2164
+ :scale => -127,
2165
+ :fsprecision => :skip,
2166
+ :lfprecision => :skip,
2167
+ :inspect => '#<OCI8::Metadata::Column: FLOAT_COL FLOAT>',
2168
+ }
2169
+ column_attrs_list << {
2170
+ :name => 'FLOAT_10_COL',
2171
+ :data_type_string => 'FLOAT(10)',
2172
+ :data_type => :number,
2173
+ :charset_form => nil,
2174
+ :nullable? => true,
2175
+ :char_used? => false,
2176
+ :char_size => 0,
2177
+ :data_size => 22,
2178
+ :precision => 10,
2179
+ :scale => -127,
2180
+ :fsprecision => :skip,
2181
+ :lfprecision => :skip,
2182
+ :inspect => '#<OCI8::Metadata::Column: FLOAT_10_COL FLOAT(10)>',
2183
+ }
2184
+ if $oracle_version >= OCI8::ORAVER_10_1
2185
+ column_attrs_list << {
2186
+ :name => 'BINARY_FLOAT_COL',
2187
+ :data_type_string => 'BINARY_FLOAT',
2188
+ :data_type => :binary_float,
2189
+ :charset_form => nil,
2190
+ :nullable? => true,
2191
+ :char_used? => false,
2192
+ :char_size => 0,
2193
+ :data_size => 4,
2194
+ :precision => 0,
2195
+ :scale => 0,
2196
+ :fsprecision => 0,
2197
+ :lfprecision => 0,
2198
+ :inspect => '#<OCI8::Metadata::Column: BINARY_FLOAT_COL BINARY_FLOAT>',
2199
+ }
2200
+ column_attrs_list << {
2201
+ :name => 'BINARY_DOUBLE_COL',
2202
+ :data_type_string => 'BINARY_DOUBLE',
2203
+ :data_type => :binary_double,
2204
+ :charset_form => nil,
2205
+ :nullable? => true,
2206
+ :char_used? => false,
2207
+ :char_size => 0,
2208
+ :data_size => 8,
2209
+ :precision => 0,
2210
+ :scale => 0,
2211
+ :fsprecision => 0,
2212
+ :lfprecision => 0,
2213
+ :inspect => '#<OCI8::Metadata::Column: BINARY_DOUBLE_COL BINARY_DOUBLE>',
2214
+ }
1368
2215
  end
2216
+ column_attrs_list << {
2217
+ :name => 'DATE_COL',
2218
+ :data_type_string => 'DATE',
2219
+ :data_type => :date,
2220
+ :charset_form => nil,
2221
+ :nullable? => true,
2222
+ :char_used? => false,
2223
+ :char_size => 0,
2224
+ :data_size => 7,
2225
+ :precision => 0,
2226
+ :scale => 0,
2227
+ :fsprecision => 0,
2228
+ :lfprecision => 0,
2229
+ :inspect => '#<OCI8::Metadata::Column: DATE_COL DATE>',
2230
+ }
2231
+
2232
+ # Skip tests for precision and lfprecision for TIMESTAMP
2233
+ # because their values depend on how they are described.
2234
+ #
2235
+ # Oracle 10g XE 10.2.0.1.0 on Linux:
2236
+ # +------------------------------------------------+-----------+-------------+
2237
+ # | | precision | lfprecision |
2238
+ # +-----------------------------------+------------+-----------+-------------+
2239
+ # | TIMESTAMP | implicitly | 0 | 0 |
2240
+ # | | explicitly | 6 | 6 |
2241
+ # +-----------------------------------+------------+-----------+-------------+
2242
+ # | TIMESTAMP(9) | implicitly | 0 | 0 |
2243
+ # | | explicitly | 9 | 9 |
2244
+ # +-----------------------------------+------------+-----------+-------------+
2245
+ # | TIMESTAMP WITH TIME ZONE | implicitly | 0 | 0 |
2246
+ # | | explicitly | 6 | 6 |
2247
+ # +-----------------------------------+------------+-----------+-------------+
2248
+ # | TIMESTAMP(9) WITH TIME ZONE | implicitly | 0 | 0 |
2249
+ # | | explicitly | 9 | 9 |
2250
+ # +-----------------------------------+------------+-----------+-------------+
2251
+ # | TIMESTAMP WITH LOCAL TIME ZONE | implicitly | 0 | 0 |
2252
+ # | | explicitly | 6 | 6 |
2253
+ # +-----------------------------------+------------+-----------+-------------+
2254
+ # | TIMESTAMP(9) WITH LOCAL TIME ZONE | implicitly | 0 | 0 |
2255
+ # | | explicitly | 9 | 9 |
2256
+ # +-----------------------------------+------------+-----------+-------------+
2257
+ column_attrs_list << {
2258
+ :name => 'TIMESTAMP_COL',
2259
+ :data_type_string => 'TIMESTAMP',
2260
+ :data_type => :timestamp,
2261
+ :charset_form => nil,
2262
+ :nullable? => true,
2263
+ :char_used? => false,
2264
+ :char_size => 0,
2265
+ :data_size => 11,
2266
+ :precision => :skip,
2267
+ :scale => 6,
2268
+ :fsprecision => 6,
2269
+ :lfprecision => :skip,
2270
+ :inspect => '#<OCI8::Metadata::Column: TIMESTAMP_COL TIMESTAMP>',
2271
+ }
2272
+ column_attrs_list << {
2273
+ :name => 'TIMESTAMP_9_COL',
2274
+ :data_type_string => 'TIMESTAMP(9)',
2275
+ :data_type => :timestamp,
2276
+ :charset_form => nil,
2277
+ :nullable? => true,
2278
+ :char_used? => false,
2279
+ :char_size => 0,
2280
+ :data_size => 11,
2281
+ :precision => :skip,
2282
+ :scale => 9,
2283
+ :fsprecision => 9,
2284
+ :lfprecision => :skip,
2285
+ :inspect => '#<OCI8::Metadata::Column: TIMESTAMP_9_COL TIMESTAMP(9)>',
2286
+ }
2287
+ column_attrs_list << {
2288
+ :name => 'TIMESTAMP_TZ_COL',
2289
+ :data_type_string => 'TIMESTAMP WITH TIME ZONE',
2290
+ :data_type => :timestamp_tz,
2291
+ :charset_form => nil,
2292
+ :nullable? => true,
2293
+ :char_used? => false,
2294
+ :char_size => 0,
2295
+ :data_size => 13,
2296
+ :precision => :skip,
2297
+ :scale => 6,
2298
+ :fsprecision => 6,
2299
+ :lfprecision => :skip,
2300
+ :inspect => '#<OCI8::Metadata::Column: TIMESTAMP_TZ_COL TIMESTAMP WITH TIME ZONE>',
2301
+ }
2302
+ column_attrs_list << {
2303
+ :name => 'TIMESTAMP_9_TZ_COL',
2304
+ :data_type_string => 'TIMESTAMP(9) WITH TIME ZONE',
2305
+ :data_type => :timestamp_tz,
2306
+ :charset_form => nil,
2307
+ :nullable? => true,
2308
+ :char_used? => false,
2309
+ :char_size => 0,
2310
+ :data_size => 13,
2311
+ :precision => :skip,
2312
+ :scale => 9,
2313
+ :fsprecision => 9,
2314
+ :lfprecision => :skip,
2315
+ :inspect => '#<OCI8::Metadata::Column: TIMESTAMP_9_TZ_COL TIMESTAMP(9) WITH TIME ZONE>',
2316
+ }
2317
+ column_attrs_list << {
2318
+ :name => 'TIMESTAMP_LTZ_COL',
2319
+ :data_type_string => 'TIMESTAMP WITH LOCAL TIME ZONE',
2320
+ :data_type => :timestamp_ltz,
2321
+ :charset_form => nil,
2322
+ :nullable? => true,
2323
+ :char_used? => false,
2324
+ :char_size => 0,
2325
+ :data_size => 11,
2326
+ :precision => :skip,
2327
+ :scale => 6,
2328
+ :fsprecision => 6,
2329
+ :lfprecision => :skip,
2330
+ :inspect => '#<OCI8::Metadata::Column: TIMESTAMP_LTZ_COL TIMESTAMP WITH LOCAL TIME ZONE>',
2331
+ }
2332
+ column_attrs_list << {
2333
+ :name => 'TIMESTAMP_9_LTZ_COL',
2334
+ :data_type_string => 'TIMESTAMP(9) WITH LOCAL TIME ZONE',
2335
+ :data_type => :timestamp_ltz,
2336
+ :charset_form => nil,
2337
+ :nullable? => true,
2338
+ :char_used? => false,
2339
+ :char_size => 0,
2340
+ :data_size => 11,
2341
+ :precision => :skip,
2342
+ :scale => 9,
2343
+ :fsprecision => 9,
2344
+ :lfprecision => :skip,
2345
+ :inspect => '#<OCI8::Metadata::Column: TIMESTAMP_9_LTZ_COL TIMESTAMP(9) WITH LOCAL TIME ZONE>',
2346
+ }
2347
+
2348
+ # Skip tsets for scale and fsprecision for INTERVAL YEAR TO MONTH
2349
+ # because their values depend on how they are described.
2350
+ #
2351
+ # Oracle 10g XE 10.2.0.1.0 on Linux:
2352
+ # +-------------------------------------------+-----------+-------------+
2353
+ # | | scale | fsprecision |
2354
+ # +------------------------------+------------+-----------+-------------+
2355
+ # | INTERVAL YEAR TO MONTH | implicitly | 0 | 0 |
2356
+ # | | explicitly | 2 | 2 |
2357
+ # +------------------------------+------------+-----------+-------------+
2358
+ # | INTERVAL YEAR(4) TO MONTH | implicitly | 0 | 0 |
2359
+ # | | explicitly | 4 | 4 |
2360
+ # +------------------------------+------------+-----------+-------------+
2361
+ column_attrs_list << {
2362
+ :name => 'INTERVAL_YM_COL',
2363
+ :data_type_string => 'INTERVAL YEAR TO MONTH',
2364
+ :data_type => :interval_ym,
2365
+ :charset_form => nil,
2366
+ :nullable? => true,
2367
+ :char_used? => false,
2368
+ :char_size => 0,
2369
+ :data_size => 5,
2370
+ :precision => 2,
2371
+ :scale => :skip,
2372
+ :fsprecision => :skip,
2373
+ :lfprecision => 2,
2374
+ :inspect => '#<OCI8::Metadata::Column: INTERVAL_YM_COL INTERVAL YEAR TO MONTH>',
2375
+ }
2376
+ column_attrs_list << {
2377
+ :name => 'INTERVAL_YM_4_COL',
2378
+ :data_type_string => 'INTERVAL YEAR(4) TO MONTH',
2379
+ :data_type => :interval_ym,
2380
+ :charset_form => nil,
2381
+ :nullable? => true,
2382
+ :char_used? => false,
2383
+ :char_size => 0,
2384
+ :data_size => 5,
2385
+ :precision => 4,
2386
+ :scale => :skip,
2387
+ :fsprecision => :skip,
2388
+ :lfprecision => 4,
2389
+ :inspect => '#<OCI8::Metadata::Column: INTERVAL_YM_4_COL INTERVAL YEAR(4) TO MONTH>',
2390
+ }
2391
+
2392
+ # Skip tests for precision and scale for INTERVAL DAY TO SECOND
2393
+ # because their values depend on how they are described.
2394
+ #
2395
+ # Oracle 10g XE 10.2.0.1.0 on Linux:
2396
+ # +-------------------------------------------+-----------+-----------+
2397
+ # | | precision | scale |
2398
+ # +------------------------------+------------+-----------+-----------+
2399
+ # | INTERVAL DAY TO SECOND | implicitly | 2 | 6 |
2400
+ # | | explicitly | 6 | 2 |
2401
+ # +------------------------------+------------+-----------+-----------+
2402
+ # | INTERVAL DAY(4) TO SECOND(9) | implicitly | 4 | 9 |
2403
+ # | | explicitly | 9 | 4 |
2404
+ # +------------------------------+------------+-----------+-----------+
2405
+ column_attrs_list << {
2406
+ :name => 'INTERVAL_DS_COL',
2407
+ :data_type_string => 'INTERVAL DAY TO SECOND',
2408
+ :data_type => :interval_ds,
2409
+ :charset_form => nil,
2410
+ :nullable? => true,
2411
+ :char_used? => false,
2412
+ :char_size => 0,
2413
+ :data_size => 11,
2414
+ :precision => :skip,
2415
+ :scale => :skip,
2416
+ :fsprecision => 6,
2417
+ :lfprecision => 2,
2418
+ :inspect => '#<OCI8::Metadata::Column: INTERVAL_DS_COL INTERVAL DAY TO SECOND>',
2419
+ }
2420
+ column_attrs_list << {
2421
+ :name => 'INTERVAL_DS_4_9_COL',
2422
+ :data_type_string => 'INTERVAL DAY(4) TO SECOND(9)',
2423
+ :data_type => :interval_ds,
2424
+ :charset_form => nil,
2425
+ :nullable? => true,
2426
+ :char_used? => false,
2427
+ :char_size => 0,
2428
+ :data_size => 11,
2429
+ :precision => :skip,
2430
+ :scale => :skip,
2431
+ :fsprecision => 9,
2432
+ :lfprecision => 4,
2433
+ :inspect => '#<OCI8::Metadata::Column: INTERVAL_DS_4_9_COL INTERVAL DAY(4) TO SECOND(9)>',
2434
+ }
1369
2435
 
1370
- coldef = @@column_test_data.find_all do |c|
1371
- c.available?(@conn)
2436
+ # Object Types
2437
+ if $oracle_version >= OCI8::ORAVER_10_1
2438
+ column_attrs_list << {
2439
+ :name => 'SDO_GEOMETRY_COL',
2440
+ :data_type_string => 'MDSYS.SDO_GEOMETRY',
2441
+ :data_type => :named_type,
2442
+ :charset_form => nil,
2443
+ :nullable? => true,
2444
+ :char_used? => false,
2445
+ :char_size => 0,
2446
+ :data_size => :skip, # 1 when explicitly, 2000 when implicitly.
2447
+ :precision => 0,
2448
+ :scale => 0,
2449
+ :fsprecision => 0,
2450
+ :lfprecision => 0,
2451
+ :inspect => '#<OCI8::Metadata::Column: SDO_GEOMETRY_COL MDSYS.SDO_GEOMETRY>',
2452
+ }
1372
2453
  end
1373
2454
 
1374
2455
  drop_table('test_table')
1375
2456
  sql = <<-EOS
1376
- CREATE TABLE test_table (#{idx = 0; coldef.collect do |c| idx += 1; "C#{idx} " + c.data_type_string; end.join(',')})
2457
+ CREATE TABLE test_table (#{column_attrs_list.collect do |c| c[:name] + " " + c[:data_type_string]; end.join(',')})
1377
2458
  STORAGE (
1378
2459
  INITIAL 100k
1379
2460
  NEXT 100k
@@ -1382,7 +2463,6 @@ STORAGE (
1382
2463
  PCTINCREASE 0)
1383
2464
  EOS
1384
2465
  @conn.exec(sql)
1385
-
1386
2466
  [
1387
2467
  @conn.describe_any('test_table').columns,
1388
2468
  @conn.describe_table('test_table').columns,
@@ -1391,44 +2471,36 @@ EOS
1391
2471
  end.columns,
1392
2472
  @conn.exec('select * from test_table').column_metadata,
1393
2473
  ].each do |columns|
1394
- columns.each_with_index do |column, i|
1395
- assert_equal("C#{i + 1}", column.name, "'#{coldef[i].data_type_string}': name")
1396
- DatatypeData.attributes.each do |attr|
1397
- expected_val = coldef[i].send(attr)
1398
- if expected_val != :skip
1399
- assert_equal(expected_val, column.send(attr), "'#{coldef[i].data_type_string}': #{attr})")
1400
- end
1401
- end
2474
+ column_attrs_list.each_with_index do |attrs, idx|
2475
+ check_attributes(attrs[:name], columns[idx], attrs)
1402
2476
  end
1403
2477
  end
1404
2478
  drop_table('test_table')
1405
2479
  end # test_column_metadata
1406
2480
 
1407
- def assert_sequence(sequence_name, desc)
1408
- # defined in OCI8::Metadata::Base
1409
- assert_object_id(sequence_name, desc.obj_id)
1410
- assert_equal(sequence_name, desc.obj_name, 'obj_name')
1411
- assert_equal(@conn.username, desc.obj_schema, 'obj_schema')
1412
- # defined in OCI8::Metadata::Sequence
1413
- assert_object_id(sequence_name, desc.objid)
2481
+ def assert_sequence(sequence_name, desc, msg)
1414
2482
  min, max, incr, cache, order = @conn.select_one(<<EOS, sequence_name)
1415
2483
  select min_value, max_value, increment_by, cache_size, order_flag
1416
2484
  from user_sequences
1417
2485
  where sequence_name = :1
1418
2486
  EOS
1419
- min = min.to_i
1420
- max = max.to_i
1421
- incr = incr.to_i
1422
- cache = cache.to_i
1423
- order = order == 'Y'
1424
2487
  currval = @conn.select_one("select cast(#{sequence_name}.currval as integer) from dual")[0]
1425
2488
 
1426
- assert_equal(min, desc.min, 'min')
1427
- assert_equal(max, desc.max, 'max')
1428
- assert_equal(incr, desc.incr, 'incr')
1429
- assert_equal(cache, desc.cache, 'cache')
1430
- assert_equal(order, desc.order?, 'order?')
1431
- assert_operator(currval, :<=, desc.hw_mark, 'hw_mark')
2489
+ attrs = {
2490
+ :class => OCI8::Metadata::Sequence,
2491
+ :obj_id => to_obj_id(@conn.username, sequence_name),
2492
+ :obj_name => sequence_name,
2493
+ :obj_schema => @conn.username,
2494
+ :objid => to_obj_id(@conn.username, sequence_name),
2495
+ :min => min.to_i,
2496
+ :max => max.to_i,
2497
+ :incr => incr.to_i,
2498
+ :cache => cache.to_i,
2499
+ :order? => order == 'Y',
2500
+ :hw_mark => Proc.new {|v| currval <= v},
2501
+ :inspect => /#<OCI8::Metadata::Sequence:\(\d+\) #{@conn.username}.#{sequence_name}/,
2502
+ }
2503
+ check_attributes(msg, desc, attrs)
1432
2504
  end
1433
2505
 
1434
2506
  def test_sequence
@@ -1448,13 +2520,13 @@ CREATE SEQUENCE TEST_SEQ_OCI8
1448
2520
  ORDER
1449
2521
  EOS
1450
2522
  @conn.select_one('select test_seq_oci8.nextval from dual')
1451
- assert_sequence('TEST_SEQ_OCI8', @conn.describe_any('test_seq_oci8'))
2523
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_any('test_seq_oci8'), "line: #{__LINE__}")
1452
2524
  @conn.select_one('select test_seq_oci8.nextval from dual')
1453
- assert_sequence('TEST_SEQ_OCI8', @conn.describe_sequence('test_seq_oci8'))
2525
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_sequence('test_seq_oci8'), "line: #{__LINE__}")
1454
2526
  @conn.select_one('select test_seq_oci8.nextval from dual')
1455
2527
  assert_sequence('TEST_SEQ_OCI8', @conn.describe_schema(@conn.username).objects.detect do |obj|
1456
2528
  obj.obj_name == 'TEST_SEQ_OCI8'
1457
- end)
2529
+ end, "line: #{__LINE__}")
1458
2530
 
1459
2531
  @conn.exec("DROP SEQUENCE TEST_SEQ_OCI8")
1460
2532
  @conn.exec(<<-EOS)
@@ -1471,15 +2543,131 @@ EOS
1471
2543
  # -999999999999999999999999999 on Oracle 11gR2
1472
2544
 
1473
2545
  @conn.select_one('select test_seq_oci8.nextval from dual')
1474
- assert_sequence('TEST_SEQ_OCI8', @conn.describe_any('test_seq_oci8'))
2546
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_any('test_seq_oci8'), "line: #{__LINE__}")
1475
2547
  @conn.select_one('select test_seq_oci8.nextval from dual')
1476
- assert_sequence('TEST_SEQ_OCI8', @conn.describe_sequence('test_seq_oci8'))
2548
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_sequence('test_seq_oci8'), "line: #{__LINE__}")
1477
2549
  @conn.select_one('select test_seq_oci8.nextval from dual')
1478
2550
  assert_sequence('TEST_SEQ_OCI8', @conn.describe_schema(@conn.username).objects.detect do |obj|
1479
2551
  obj.obj_name == 'TEST_SEQ_OCI8'
1480
- end)
2552
+ end, "line: #{__LINE__}")
1481
2553
 
1482
2554
  @conn.exec("DROP SEQUENCE TEST_SEQ_OCI8")
1483
2555
  end
1484
2556
 
2557
+ def test_synonym_metadata
2558
+ begin
2559
+ @conn.exec("DROP SYNONYM test_synonym")
2560
+ rescue OCIError
2561
+ raise if $!.code != 1434 # ORA-01434: private synonym to be dropped does not exist
2562
+ end
2563
+
2564
+ # private synonym
2565
+ begin
2566
+ [
2567
+ {
2568
+ :synonym_name => 'FOO.BAR@BAZ.QUZ',
2569
+ :attrs => {
2570
+ :class => OCI8::Metadata::Synonym,
2571
+ :obj_id => nil,
2572
+ :obj_name => 'TEST_SYNONYM',
2573
+ :obj_schema => @conn.username,
2574
+ :schema_name => 'FOO',
2575
+ :name => 'BAR',
2576
+ :link => 'BAZ.QUZ',
2577
+ :translated_name => 'FOO.BAR@BAZ.QUZ',
2578
+ :inspect => /#<OCI8::Metadata::Synonym:\(\d+\) #{@conn.username}.TEST_SYNONYM FOR FOO.BAR@BAZ.QUZ>/,
2579
+ },
2580
+ },
2581
+ {
2582
+ :synonym_name => 'BAR@BAZ.QUZ',
2583
+ :attrs => {
2584
+ :class => OCI8::Metadata::Synonym,
2585
+ :obj_id => nil,
2586
+ :obj_name => 'TEST_SYNONYM',
2587
+ :obj_schema => @conn.username,
2588
+ :schema_name => nil,
2589
+ :name => 'BAR',
2590
+ :link => 'BAZ.QUZ',
2591
+ :translated_name => 'BAR@BAZ.QUZ',
2592
+ :inspect => /#<OCI8::Metadata::Synonym:\(\d+\) #{@conn.username}.TEST_SYNONYM FOR BAR@BAZ.QUZ>/,
2593
+ },
2594
+ },
2595
+ {
2596
+ :synonym_name => 'FOO.BAR',
2597
+ :attrs => {
2598
+ :class => OCI8::Metadata::Synonym,
2599
+ :obj_id => nil,
2600
+ :obj_name => 'TEST_SYNONYM',
2601
+ :obj_schema => @conn.username,
2602
+ :schema_name => 'FOO',
2603
+ :name => 'BAR',
2604
+ :link => nil,
2605
+ :translated_name => 'FOO.BAR',
2606
+ :inspect => /#<OCI8::Metadata::Synonym:\(\d+\) #{@conn.username}.TEST_SYNONYM FOR FOO.BAR>/,
2607
+ },
2608
+ },
2609
+ {
2610
+ :synonym_name => 'BAR',
2611
+ :attrs => {
2612
+ :class => OCI8::Metadata::Synonym,
2613
+ :obj_id => nil,
2614
+ :obj_name => 'TEST_SYNONYM',
2615
+ :obj_schema => @conn.username,
2616
+ :schema_name => @conn.username,
2617
+ :name => 'BAR',
2618
+ :link => nil,
2619
+ :translated_name => "#{@conn.username}.BAR",
2620
+ :inspect => /#<OCI8::Metadata::Synonym:\(\d+\) #{@conn.username}.TEST_SYNONYM FOR #{@conn.username}.BAR>/,
2621
+ },
2622
+ },
2623
+ ].each do |test|
2624
+ synonym_name = test[:synonym_name]
2625
+ attrs = test[:attrs]
2626
+ @conn.exec("CREATE SYNONYM test_synonym FOR #{synonym_name}")
2627
+ [
2628
+ @conn.describe_any('test_synonym'),
2629
+ @conn.describe_synonym('Test_Synonym'),
2630
+ @conn.describe_any(@conn.username + '.test_synonym'),
2631
+ @conn.describe_synonym(@conn.username + '.Test_Synonym'),
2632
+ ].each do |desc|
2633
+ attrs[:obj_id] = to_obj_id(@conn.username, 'TEST_SYNONYM')
2634
+ check_attributes("private synonym #{synonym_name}", desc, attrs)
2635
+ end
2636
+ @conn.exec("DROP SYNONYM test_synonym")
2637
+ end
2638
+ rescue OCIError
2639
+ raise "grant create synonym privilege to user #{@conn.username} to pass tests." if $!.code == 1031 # ORA-01031: insufficient privileges
2640
+ raise
2641
+ end
2642
+
2643
+ # public synonym
2644
+ attrs = {
2645
+ :class => OCI8::Metadata::Synonym,
2646
+ :obj_id => to_obj_id('PUBLIC', 'SDO_GEOMETRY'),
2647
+ :obj_name => 'SDO_GEOMETRY',
2648
+ :obj_schema => 'PUBLIC',
2649
+ :schema_name => 'MDSYS',
2650
+ :name => 'SDO_GEOMETRY',
2651
+ :link => nil,
2652
+ :translated_name => 'MDSYS.SDO_GEOMETRY',
2653
+ :inspect => /#<OCI8::Metadata::Synonym:\(\d+\) PUBLIC.SDO_GEOMETRY FOR MDSYS.SDO_GEOMETRY>/,
2654
+ }
2655
+ [
2656
+ @conn.describe_any('sdo_geometry'),
2657
+ @conn.describe_synonym('sdo_geometry'),
2658
+ @conn.describe_any('public.sdo_geometry'),
2659
+ @conn.describe_synonym('PUBLIC.sdo_geometry'),
2660
+ ].each do |desc|
2661
+ check_attributes('public synonym', desc, attrs)
2662
+ end
2663
+
2664
+ end
2665
+
2666
+ def test_access_metadata_after_logoff
2667
+ metadata = @conn.describe_any('MDSYS.SDO_GEOMETRY')
2668
+ @conn.logoff
2669
+ @conn = nil
2670
+ metadata.inspect # This should not cause segmentation fault.
2671
+ end
2672
+
1485
2673
  end # TestMetadata