ruby-oci8 2.1.2-x86-mingw32 → 2.1.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -34,6 +34,7 @@ EOS
34
34
  s.has_rdoc = 'yard'
35
35
  s.authors = ['KUBO Takehiro']
36
36
  s.platform = gem_platform
37
+ s.license = '2-clause BSD-style license'
37
38
  files = File.read('dist-files').split("\n")
38
39
  if gem_platform == Gem::Platform::RUBY
39
40
  s.extensions << 'ext/oci8/extconf.rb'
data/setup.rb CHANGED
@@ -99,6 +99,8 @@ else
99
99
  require 'rbconfig'
100
100
  end
101
101
 
102
+ RbConfig = Config unless defined? RbConfig
103
+
102
104
  def multipackage_install?
103
105
  FileTest.directory?(File.dirname($0) + '/packages')
104
106
  end
@@ -106,7 +108,7 @@ end
106
108
 
107
109
  class ConfigTable
108
110
 
109
- c = ::Config::CONFIG
111
+ c = ::RbConfig::CONFIG
110
112
 
111
113
  rubypath = c['bindir'] + '/' + c['ruby_install_name']
112
114
 
@@ -1217,7 +1219,7 @@ class Installer
1217
1219
  raise InstallError, "no ruby extention exists: 'ruby #{$0} setup' first"
1218
1220
  end
1219
1221
 
1220
- DLEXT = /\.#{ ::Config::CONFIG['DLEXT'] }\z/
1222
+ DLEXT = /\.#{ ::RbConfig::CONFIG['DLEXT'] }\z/
1221
1223
 
1222
1224
  def _ruby_extentions(dir)
1223
1225
  Dir.open(dir) {|d|
@@ -44,6 +44,70 @@ else
44
44
  $test_clob = true
45
45
  end
46
46
 
47
+ begin
48
+ Time.new(2001, 1, 1, 0, 0, 0, '+00:00')
49
+ # ruby 1.9.2 or later
50
+ def convert_to_time(year, month, day, hour, minute, sec, subsec, timezone)
51
+ subsec ||= 0
52
+ if timezone
53
+ # with time zone
54
+ Time.new(year, month, day, hour, minute, sec + subsec, timezone)
55
+ else
56
+ # without time zone
57
+ Time.local(year, month, day, hour, minute, sec, subsec * 1000000)
58
+ end
59
+ end
60
+ rescue
61
+ # ruby 1.9.1 or former
62
+ def convert_to_time(year, month, day, hour, minute, sec, subsec, timezone)
63
+ subsec ||= 0
64
+ if timezone
65
+ # with time zone
66
+ /([+-])(\d+):(\d+)/ =~ timezone
67
+ offset = ($1 + '1').to_i * ($2.to_i * 60 + $3.to_i)
68
+ if offset == 0
69
+ Time.utc(year, month, day, hour, minute, sec, subsec * 1000000)
70
+ else
71
+ tm = Time.local(year, month, day, hour, minute, sec, subsec * 1000000)
72
+ raise "Failed to convert #{str} to Time" if tm.utc_offset != offset * 60
73
+ tm
74
+ end
75
+ else
76
+ # without time zone
77
+ Time.local(year, month, day, hour, minute, sec, subsec * 1000000)
78
+ end
79
+ end
80
+ end
81
+
82
+ def convert_to_datetime(year, month, day, hour, minute, sec, subsec, timezone)
83
+ subsec ||= 0
84
+ utc_offset = if timezone
85
+ # with time zone
86
+ /([+-])(\d+):(\d+)/ =~ timezone
87
+ ($1 + '1').to_i * ($2.to_i * 60 + $3.to_i) * 60
88
+ else
89
+ Time.local(year, month, day, hour, minute, sec).utc_offset
90
+ end
91
+ begin
92
+ DateTime.civil(year, month, day, hour, minute, sec + subsec, utc_offset.to_r / 86400)
93
+ rescue ArgumentError
94
+ raise $! if $!.to_s != 'invalid date'
95
+ # for ruby 1.8.6.
96
+ # convert to a DateTime via a String as a workaround.
97
+ if utc_offset >= 0
98
+ sign = ?+
99
+ else
100
+ sign = ?-
101
+ utc_offset = - utc_offset;
102
+ end
103
+ tz_min = utc_offset / 60
104
+ tz_hour, tz_min = tz_min.divmod 60
105
+ time_str = format("%04d-%02d-%02dT%02d:%02d:%02d.%09d%c%02d:%02d",
106
+ year, month, day, hour, minute, sec, (subsec * 1000_000_000).to_i, sign, tz_hour, tz_min)
107
+ ::DateTime.parse(time_str)
108
+ end
109
+ end
110
+
47
111
  module Test
48
112
  module Unit
49
113
  class TestCase
@@ -0,0 +1,171 @@
1
+ drop table rb_test_obj_tab1 purge
2
+ /
3
+ drop table rb_test_obj_tab2 purge
4
+ /
5
+ drop type rb_test_obj
6
+ /
7
+ drop type rb_test_obj_elem_ary_of_ary
8
+ /
9
+ drop type rb_test_obj_elem_array
10
+ /
11
+ drop type rb_test_obj_elem
12
+ /
13
+ create type rb_test_obj_elem as object (
14
+ x integer,
15
+ y integer
16
+ )
17
+ /
18
+ create or replace type rb_test_int_array as array(50) of integer
19
+ /
20
+ create or replace type rb_test_flt_array as array(50) of float
21
+ /
22
+ create or replace type rb_test_num_array as array(50) of number(10,1)
23
+ /
24
+ create or replace type rb_test_bdbl_array as array(50) of binary_double
25
+ /
26
+ create or replace type rb_test_bflt_array as array(50) of binary_float
27
+ /
28
+ create or replace type rb_test_str_array as array(50) of varchar2(50)
29
+ /
30
+ create or replace type rb_test_raw_array as array(50) of raw(50)
31
+ /
32
+ create or replace type rb_test_obj_elem_array as array(50) of rb_test_obj_elem
33
+ /
34
+ create or replace type rb_test_obj_elem_ary_of_ary as array(50) of rb_test_obj_elem_array
35
+ /
36
+ --create or replace type rb_test_date_array as array(50) of date
37
+ --/
38
+ create type rb_test_obj as object (
39
+ int_val integer,
40
+ flt_val float,
41
+ num_val number(10,1),
42
+ bdbl_val binary_double,
43
+ bflt_val binary_float,
44
+ str_val varchar2(50),
45
+ raw_val raw(50),
46
+ clob_val clob,
47
+ nclob_val nclob,
48
+ blob_val blob,
49
+ obj_val rb_test_obj_elem,
50
+ int_array_val rb_test_int_array,
51
+ flt_array_val rb_test_flt_array,
52
+ num_array_val rb_test_num_array,
53
+ bdbl_array_val rb_test_bdbl_array,
54
+ bflt_array_val rb_test_bflt_array,
55
+ str_array_val rb_test_str_array,
56
+ raw_array_val rb_test_raw_array,
57
+ obj_array_val rb_test_obj_elem_array,
58
+ obj_ary_of_ary_val rb_test_obj_elem_ary_of_ary,
59
+ date_val date,
60
+ -- date_array_val rb_test_date_array,
61
+
62
+ constructor function rb_test_obj(n number) return self as result,
63
+ static function test_object_version return integer,
64
+ static function class_func(n number) return rb_test_obj,
65
+ static procedure class_proc1(obj out rb_test_obj, n number),
66
+ static procedure class_proc2(obj in out rb_test_obj),
67
+ member function member_func return integer,
68
+ member procedure member_proc(n in integer)
69
+ )
70
+ /
71
+ create or replace type body rb_test_obj is
72
+
73
+ constructor function rb_test_obj(n number) return self as result is
74
+ function to_test_date(n number) return date is
75
+ begin
76
+ return to_date(to_char(1990 + n, 'FM0000') ||
77
+ to_char(mod(round(n) * 5, 12) + 1, 'FM00') ||
78
+ to_char(mod(round(n) * 7, 27) + 1, 'FM00') ||
79
+ to_char(mod(round(n) * 9, 24), 'FM00') ||
80
+ to_char(mod(round(n) * 11, 60), 'FM00') ||
81
+ to_char(mod(round(n) * 13, 60), 'FM00'), 'yyyymmddhh24miss');
82
+ end;
83
+ begin
84
+ self.int_val := n;
85
+ self.flt_val := n;
86
+ self.num_val := n;
87
+ self.bdbl_val := n;
88
+ self.bflt_val := n;
89
+ self.str_val := to_char(n);
90
+ self.raw_val := utl_raw.cast_to_raw(to_char(n));
91
+ self.clob_val := to_clob(n);
92
+ self.nclob_val := to_clob(n);
93
+ self.blob_val := to_blob(utl_raw.cast_to_raw(to_char(n)));
94
+ self.obj_val := rb_test_obj_elem(n, n + 1);
95
+ self.date_val := to_test_date(n);
96
+ if self.int_val != 1 then
97
+ self.int_array_val := rb_test_int_array(n, n + 1, n + 2);
98
+ self.flt_array_val := rb_test_flt_array(n, n + 1, n + 2);
99
+ self.num_array_val := rb_test_num_array(n, n + 1, n + 2);
100
+ self.bdbl_array_val := rb_test_bdbl_array(n, n + 1, n + 2);
101
+ self.bflt_array_val := rb_test_bflt_array(n, n + 1, n + 2);
102
+ self.str_array_val := rb_test_str_array(to_char(n), to_char(n + 1), to_char(n + 2));
103
+ self.raw_array_val := rb_test_raw_array(utl_raw.cast_to_raw(to_char(n)),
104
+ utl_raw.cast_to_raw(to_char(n + 1)),
105
+ utl_raw.cast_to_raw(to_char(n + 2)));
106
+ self.obj_array_val := rb_test_obj_elem_array(rb_test_obj_elem(n + 0, n + 1),
107
+ rb_test_obj_elem(n + 1, n + 2),
108
+ rb_test_obj_elem(n + 2, n + 3));
109
+ self.obj_ary_of_ary_val := rb_test_obj_elem_ary_of_ary(self.obj_array_val);
110
+ -- self.date_array_val := rb_test_date_array(to_test_date(n),
111
+ -- to_test_date(n + 1),
112
+ -- to_test_date(n + 2));
113
+ end if;
114
+ return;
115
+ end;
116
+
117
+ static function test_object_version return integer is
118
+ begin
119
+ return 2;
120
+ end;
121
+
122
+ static function class_func(n number) return rb_test_obj is
123
+ begin
124
+ return rb_test_obj(n);
125
+ end;
126
+
127
+ static procedure class_proc1(obj out rb_test_obj, n number) is
128
+ begin
129
+ obj := rb_test_obj(n);
130
+ end;
131
+
132
+ static procedure class_proc2(obj in out rb_test_obj) is
133
+ begin
134
+ obj.int_val := obj.int_val + 1;
135
+ end;
136
+
137
+ member function member_func return integer is
138
+ begin
139
+ return int_val;
140
+ end;
141
+
142
+ member procedure member_proc(n in integer) is
143
+ begin
144
+ self.int_val := n;
145
+ end;
146
+ end;
147
+ /
148
+ create table rb_test_obj_tab1 (
149
+ n number primary key,
150
+ obj rb_test_obj
151
+ )
152
+ /
153
+ create table rb_test_obj_tab2 of rb_test_obj (
154
+ int_val primary key
155
+ )
156
+ /
157
+ declare
158
+ n number := 0;
159
+ obj rb_test_obj;
160
+ begin
161
+ loop
162
+ n := n + 1.2;
163
+ exit when n > 20;
164
+ obj := rb_test_obj(n);
165
+ insert into rb_test_obj_tab1 values (n, obj);
166
+ insert into rb_test_obj_tab2 values (obj);
167
+ end loop;
168
+ end;
169
+ /
170
+ commit
171
+ /
@@ -24,6 +24,7 @@ require "#{srcdir}/test_appinfo"
24
24
  require "#{srcdir}/test_oracle_version"
25
25
  require "#{srcdir}/test_error"
26
26
  require "#{srcdir}/test_connection_pool"
27
+ require "#{srcdir}/test_object"
27
28
 
28
29
  if OCI8.respond_to? :encoding
29
30
  require "#{srcdir}/test_encoding"
@@ -62,7 +62,15 @@ class TestBreak < Test::Unit::TestCase
62
62
  expect = []
63
63
  expect[PLSQL_DONE] = TIME_IN_PLSQL
64
64
  expect[OCIBREAK] = "Invalid status"
65
- expect[SEND_BREAK] = TIME_IN_PLSQL + TIME_TO_BREAK
65
+ if defined? Rubinius and Rubinius::VERSION >= "2.0"
66
+ # Rubinius 2.0.0.
67
+ # DBMS_LOCK.SLEEP blocks ruby threads which try to call C-API.
68
+ expect[SEND_BREAK] = TIME_TO_BREAK
69
+ else
70
+ # MRI and Rubinius 1.2.4.
71
+ # DBMS_LOCK.SLEEP blocks all ruby threads.
72
+ expect[SEND_BREAK] = TIME_IN_PLSQL + TIME_TO_BREAK
73
+ end
66
74
  do_test_ocibreak(@conn, expect)
67
75
  end
68
76
 
@@ -91,7 +99,15 @@ class TestBreak < Test::Unit::TestCase
91
99
  def test_timeout
92
100
  @conn.non_blocking = true
93
101
  start_time = Time.now
94
- assert_raise(Timeout::Error) do
102
+
103
+ if defined? Rubinius and Rubinius::VERSION < "2.0"
104
+ # Rubinius 1.2.4
105
+ expected = OCIBreak
106
+ else
107
+ # MRI and Rubinius 2.0.0
108
+ expected = Timeout::Error
109
+ end
110
+ assert_raise(expected) do
95
111
  Timeout.timeout(1) do
96
112
  @conn.exec("BEGIN DBMS_LOCK.SLEEP(5); END;")
97
113
  end
@@ -18,8 +18,8 @@ class TestCLob < Test::Unit::TestCase
18
18
  cursor = @conn.exec("SELECT content FROM test_table WHERE filename = :1 FOR UPDATE", filename)
19
19
  lob = cursor.fetch[0]
20
20
  open($lobfile) do |f|
21
- while f.gets()
22
- lob.write($_)
21
+ while s = f.read(1000)
22
+ lob.write(s)
23
23
  end
24
24
  end
25
25
  lob.close
@@ -33,8 +33,8 @@ class TestCLob < Test::Unit::TestCase
33
33
  lob = cursor.fetch[0]
34
34
  lob.sync = false
35
35
  open($lobfile) do |f|
36
- while f.gets()
37
- lob.write($_)
36
+ while s = f.read(1000)
37
+ lob.write(s)
38
38
  end
39
39
  end
40
40
  lob.flush
@@ -13,59 +13,20 @@ class TestDateTime < Test::Unit::TestCase
13
13
  end
14
14
  end
15
15
 
16
- @@time_new_accepts_timezone = begin
17
- Time.new(2001, 1, 1, 0, 0, 0, '+00:00')
18
- true
19
- rescue
20
- false
21
- end
22
-
23
16
  def string_to_time(str)
24
- /(\d+)-(\d+)-(\d+) ?(?:(\d+):(\d+):(\d+))?(?:\.(\d+))? ?(([+-])(\d+):(\d+))?/ =~ str
25
- args = []
26
- args << $1.to_i # year
27
- args << $2.to_i # month
28
- args << $3.to_i # day
29
- args << $4.to_i if $4 # hour
30
- args << $5.to_i if $5 # minute
31
- if $8 and @@time_new_accepts_timezone
32
- args << $6.to_i + $7.to_i.to_r / ('1' + '0' * ($7.length)).to_i
33
- args << $8
34
- Time.new(*args)
35
- else
36
- if $6
37
- args << $6.to_i
38
- end
39
- if $7
40
- args << $7.to_i.to_r * 1000000 / ('1' + '0' * ($7.length)).to_i
41
- end
42
- if $8
43
- # with time zone
44
- offset = ($9 + '1').to_i * ($10.to_i * 60 + $11.to_i)
45
- if offset == 0
46
- Time.utc(*args)
47
- else
48
- tm = Time.local(*args)
49
- raise "Failed to convert #{str} to Time" if tm.utc_offset != offset * 60
50
- tm
51
- end
52
- else
53
- # without time zone
54
- Time.local(*args)
55
- end
17
+ /(\d+)-(\d+)-(\d+) ?(?:(\d+):(\d+):(\d+))?(?:\.(\d+))? ?([+-]\d+:\d+)?/ =~ str
18
+ if $7
19
+ subsec = $7.to_i.to_r / ('1' + '0' * ($7.length)).to_i
56
20
  end
57
- #Time.local(*str.split(/[- :\.]/).collect do |n| n.to_i; end)
21
+ convert_to_time($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, subsec, $8)
58
22
  end
59
23
 
60
24
  def string_to_datetime(str)
61
- /(\d+-\d+-\d+ ?(?:\d+:\d+:\d+)?(?:\.\d+)?) ?([+-]\d+:\d+)?/ =~ str
62
- if $2
63
- # with time zone
64
- DateTime.parse(str)
65
- else
66
- tm = string_to_time(str)
67
- DateTime.parse(str + timezone_string(*((tm.utc_offset / 60).divmod 60)))
25
+ /(\d+)-(\d+)-(\d+) ?(?:(\d+):(\d+):(\d+))?(?:\.(\d+))? ?([+-]\d+:\d+)?/ =~ str
26
+ if $7
27
+ subsec = $7.to_i.to_r / ('1' + '0' * ($7.length)).to_i
68
28
  end
29
+ convert_to_datetime($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, subsec, $8)
69
30
  end
70
31
 
71
32
  def setup
@@ -1406,4 +1406,82 @@ EOS
1406
1406
  drop_table('test_table')
1407
1407
  end # test_column_metadata
1408
1408
 
1409
+ def assert_sequence(sequence_name, desc)
1410
+ # defined in OCI8::Metadata::Base
1411
+ assert_object_id(sequence_name, desc.obj_id)
1412
+ assert_equal(sequence_name, desc.obj_name, 'obj_name')
1413
+ assert_equal(@conn.username, desc.obj_schema, 'obj_schema')
1414
+ # defined in OCI8::Metadata::Sequence
1415
+ assert_object_id(sequence_name, desc.objid)
1416
+ min, max, incr, cache, order = @conn.select_one(<<EOS, sequence_name)
1417
+ select min_value, max_value, increment_by, cache_size, order_flag
1418
+ from user_sequences
1419
+ where sequence_name = :1
1420
+ EOS
1421
+ min = min.to_i
1422
+ max = max.to_i
1423
+ incr = incr.to_i
1424
+ cache = cache.to_i
1425
+ order = order == 'Y'
1426
+ currval = @conn.select_one("select cast(#{sequence_name}.currval as integer) from dual")[0]
1427
+
1428
+ assert_equal(min, desc.min, 'min')
1429
+ assert_equal(max, desc.max, 'max')
1430
+ assert_equal(incr, desc.incr, 'incr')
1431
+ assert_equal(cache, desc.cache, 'cache')
1432
+ assert_equal(order, desc.order?, 'order?')
1433
+ assert_operator(currval, :<=, desc.hw_mark, 'hw_mark')
1434
+ end
1435
+
1436
+ def test_sequence
1437
+ begin
1438
+ @conn.exec("DROP SEQUENCE TEST_SEQ_OCI8")
1439
+ rescue OCIError
1440
+ raise if $!.code != 2289 # ORA-02289: sequence does not exist
1441
+ end
1442
+ @conn.exec(<<-EOS)
1443
+ CREATE SEQUENCE TEST_SEQ_OCI8
1444
+ INCREMENT BY 2
1445
+ START WITH 998
1446
+ MAXVALUE 1000
1447
+ MINVALUE 10
1448
+ CYCLE
1449
+ CACHE 5
1450
+ ORDER
1451
+ EOS
1452
+ @conn.select_one('select test_seq_oci8.nextval from dual')
1453
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_any('test_seq_oci8'))
1454
+ @conn.select_one('select test_seq_oci8.nextval from dual')
1455
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_sequence('test_seq_oci8'))
1456
+ @conn.select_one('select test_seq_oci8.nextval from dual')
1457
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_schema(@conn.username).objects.detect do |obj|
1458
+ obj.obj_name == 'TEST_SEQ_OCI8'
1459
+ end)
1460
+
1461
+ @conn.exec("DROP SEQUENCE TEST_SEQ_OCI8")
1462
+ @conn.exec(<<-EOS)
1463
+ CREATE SEQUENCE TEST_SEQ_OCI8
1464
+ INCREMENT BY -1
1465
+ NOMAXVALUE
1466
+ NOMINVALUE
1467
+ NOCYCLE
1468
+ NOCACHE
1469
+ NOORDER
1470
+ EOS
1471
+ # @conn.describe_any('test_seq_oci8').min is:
1472
+ # -99999999999999999999999999 on Oracle 10gR2
1473
+ # -999999999999999999999999999 on Oracle 11gR2
1474
+
1475
+ @conn.select_one('select test_seq_oci8.nextval from dual')
1476
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_any('test_seq_oci8'))
1477
+ @conn.select_one('select test_seq_oci8.nextval from dual')
1478
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_sequence('test_seq_oci8'))
1479
+ @conn.select_one('select test_seq_oci8.nextval from dual')
1480
+ assert_sequence('TEST_SEQ_OCI8', @conn.describe_schema(@conn.username).objects.detect do |obj|
1481
+ obj.obj_name == 'TEST_SEQ_OCI8'
1482
+ end)
1483
+
1484
+ @conn.exec("DROP SEQUENCE TEST_SEQ_OCI8")
1485
+ end
1486
+
1409
1487
  end # TestMetadata