ruby-oci8 2.1.5.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +17 -0
  3. data/COPYING +30 -0
  4. data/COPYING_old +64 -0
  5. data/ChangeLog +2779 -0
  6. data/Makefile +92 -0
  7. data/NEWS +660 -0
  8. data/README.md +43 -0
  9. data/VERSION +1 -0
  10. data/dist-files +91 -0
  11. data/docs/install-binary-package.md +40 -0
  12. data/docs/install-full-client.md +116 -0
  13. data/docs/install-instant-client.md +167 -0
  14. data/docs/platform-specific-issues.md +197 -0
  15. data/docs/report-installation-issue.md +50 -0
  16. data/lib/.document +1 -0
  17. data/lib/dbd/OCI8.rb +591 -0
  18. data/lib/oci8.rb +147 -0
  19. data/lib/oci8.rb.in +147 -0
  20. data/lib/oci8/.document +8 -0
  21. data/lib/oci8/bindtype.rb +350 -0
  22. data/lib/oci8/compat.rb +113 -0
  23. data/lib/oci8/connection_pool.rb +108 -0
  24. data/lib/oci8/cursor.rb +564 -0
  25. data/lib/oci8/datetime.rb +605 -0
  26. data/lib/oci8/encoding-init.rb +79 -0
  27. data/lib/oci8/encoding.yml +537 -0
  28. data/lib/oci8/metadata.rb +2092 -0
  29. data/lib/oci8/object.rb +605 -0
  30. data/lib/oci8/oci8.rb +560 -0
  31. data/lib/oci8/ocihandle.rb +607 -0
  32. data/lib/oci8/oracle_version.rb +143 -0
  33. data/lib/oci8/properties.rb +134 -0
  34. data/lib/oci8lib_200.so +0 -0
  35. data/metaconfig +142 -0
  36. data/pre-distclean.rb +7 -0
  37. data/ruby-oci8.gemspec +80 -0
  38. data/setup.rb +1333 -0
  39. data/test/README +42 -0
  40. data/test/config.rb +184 -0
  41. data/test/setup_test_object.sql +171 -0
  42. data/test/test_all.rb +54 -0
  43. data/test/test_appinfo.rb +63 -0
  44. data/test/test_array_dml.rb +333 -0
  45. data/test/test_bind_raw.rb +46 -0
  46. data/test/test_bind_string.rb +106 -0
  47. data/test/test_bind_time.rb +178 -0
  48. data/test/test_break.rb +124 -0
  49. data/test/test_clob.rb +98 -0
  50. data/test/test_connection_pool.rb +125 -0
  51. data/test/test_connstr.rb +81 -0
  52. data/test/test_datetime.rb +581 -0
  53. data/test/test_dbi.rb +366 -0
  54. data/test/test_dbi_clob.rb +53 -0
  55. data/test/test_encoding.rb +104 -0
  56. data/test/test_error.rb +88 -0
  57. data/test/test_metadata.rb +1485 -0
  58. data/test/test_object.rb +462 -0
  59. data/test/test_oci8.rb +489 -0
  60. data/test/test_oracle_version.rb +70 -0
  61. data/test/test_oradate.rb +256 -0
  62. data/test/test_oranumber.rb +787 -0
  63. data/test/test_rowid.rb +33 -0
  64. metadata +109 -0
@@ -0,0 +1,81 @@
1
+ require 'oci8'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/config'
4
+
5
+ class TestConnStr < Test::Unit::TestCase
6
+ TEST_CASES =
7
+ [
8
+ # success cases:
9
+ # [ 'connect_string', expected result as an array]
10
+ # error cases:
11
+ # [ 'connect_string', ExceptionClass]
12
+ ["hr/hr@host/service_name", ["hr", "hr", "host/service_name", nil]],
13
+ ["sys/syspw@host/service_name AS SYSdba ", ["sys", "syspw", "host/service_name", :SYSDBA]],
14
+ ["sys/syspw@host:1521/service_name as sysdba", ["sys", "syspw", "host:1521/service_name", :SYSDBA]],
15
+ # error cases
16
+ ["service_name", ArgumentError],
17
+ ["", ArgumentError],
18
+ ["foo bar/baz", ArgumentError],
19
+ ["foo@bar/baz", ArgumentError],
20
+ # parse_connect_string doesn't check validity of privilege.
21
+ ["foo/bar as foo_bar", ["foo", "bar", nil, :FOO_BAR]],
22
+
23
+ ##
24
+ ## following test cases are contributed by Shiwei Zhang.
25
+ ##
26
+ #"username/password"
27
+ ["username/password", ["username", "password", nil, nil]],
28
+ #"username/password@[//]host[:port][/service_name]"
29
+ ["username/password@host", ["username", "password", "host", nil]],
30
+ ["username/password@host/service_name", ["username", "password", "host/service_name", nil]],
31
+ ["username/password@host:1521", ["username", "password", "host:1521", nil]],
32
+ ["username/password@host:1521/service_name", ["username", "password", "host:1521/service_name", nil]],
33
+ ["username/password@//host", ["username", "password", "//host", nil]],
34
+ ["username/password@//host/service_name", ["username", "password", "//host/service_name", nil]],
35
+ ["username/password@//host:1521", ["username", "password", "//host:1521", nil]],
36
+ ["username/password@//host:1521/service_name", ["username", "password", "//host:1521/service_name", nil]],
37
+ #"username/password as{sysoper|sysdba}"
38
+ ["username/password as sysoper", ["username", "password", nil, :SYSOPER]],
39
+ ["username/password as sysdba", ["username", "password", nil, :SYSDBA]],
40
+ #"username/password@[//]host[:port][/service_name] as {sysoper|sysdba}"
41
+ ["username/password@host as sysoper", ["username", "password", "host", :SYSOPER]],
42
+ ["username/password@host as sysdba", ["username", "password", "host", :SYSDBA]],
43
+ ["username/password@host/service_name as sysoper", ["username", "password", "host/service_name", :SYSOPER]],
44
+ ["username/password@host/service_name as sysdba", ["username", "password", "host/service_name", :SYSDBA]],
45
+ ["username/password@host:1521 as sysoper", ["username", "password", "host:1521", :SYSOPER]],
46
+ ["username/password@host:1521 as sysdba", ["username", "password", "host:1521", :SYSDBA]],
47
+ ["username/password@host:1521/service_name as sysoper", ["username", "password", "host:1521/service_name", :SYSOPER]],
48
+ ["username/password@host:1521/service_name as sysdba", ["username", "password", "host:1521/service_name", :SYSDBA]],
49
+ ["username/password@//host as sysoper", ["username", "password", "//host", :SYSOPER]],
50
+ ["username/password@//host as sysdba", ["username", "password", "//host", :SYSDBA]],
51
+ ["username/password@//host/service_name as sysoper", ["username", "password", "//host/service_name", :SYSOPER]],
52
+ ["username/password@//host/service_name as sysdba", ["username", "password", "//host/service_name", :SYSDBA]],
53
+ ["username/password@//host:1521 as sysoper", ["username", "password", "//host:1521", :SYSOPER]],
54
+ ["username/password@//host:1521 as sysdba", ["username", "password", "//host:1521", :SYSDBA]],
55
+ ["username/password@//host:1521/service_name as sysoper", ["username", "password", "//host:1521/service_name", :SYSOPER]],
56
+ ["username/password@//host:1521/service_name as sysdba", ["username", "password", "//host:1521/service_name", :SYSDBA]],
57
+ ["/passwd@192.168.19.19:1521/orcl as sysdba", ["", "passwd", "192.168.19.19:1521/orcl", :SYSDBA]],
58
+ ["/", [nil, nil, nil, nil]],
59
+ ["/ as sysdba", [nil, nil, nil, :SYSDBA]],
60
+ ]
61
+
62
+ def test_connstr
63
+ obj = OCI8.allocate # create an uninitialized object.
64
+ TEST_CASES.each do |test_case|
65
+ case test_case[1]
66
+ when Array
67
+ # use instance_eval to call a private method parse_connect_string.
68
+ result = obj.instance_eval { parse_connect_string(test_case[0]) }
69
+ assert_equal(test_case[1], result, test_case[0])
70
+ when Class
71
+ assert_raises(test_case[1]) do
72
+ result = obj.instance_eval { parse_connect_string(test_case[0]) }
73
+ end
74
+ else
75
+ raise "unsupported testcase"
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ Test::Unit::AutoRunner.run() if $0 == __FILE__
@@ -0,0 +1,581 @@
1
+ require 'oci8'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/config'
4
+ require 'scanf'
5
+
6
+ class TestDateTime < Test::Unit::TestCase
7
+
8
+ def timezone_string(tzh, tzm)
9
+ if tzh >= 0
10
+ format("+%02d:%02d", tzh, tzm)
11
+ else
12
+ format("-%02d:%02d", -tzh, -tzm)
13
+ end
14
+ end
15
+
16
+ def string_to_time(str)
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
20
+ 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)
22
+ end
23
+
24
+ def string_to_datetime(str)
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
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)
30
+ end
31
+
32
+ def setup
33
+ @conn = get_oci8_connection
34
+ end
35
+
36
+ def teardown
37
+ @conn.logoff
38
+ end
39
+
40
+ def test_date_select
41
+ ['2005-06-01 00:00:00',
42
+ '2005-12-31 23:59:59',
43
+ '2006-01-01 00:00:00'].each do |date|
44
+ @conn.exec(<<-EOS) do |row|
45
+ SELECT TO_DATE('#{date}', 'YYYY-MM-DD HH24:MI:SS') FROM dual
46
+ EOS
47
+ assert_equal(Time.local(*date.scanf("%d-%d-%d %d:%d:%d.%06d")), row[0])
48
+ end
49
+ end
50
+ end
51
+
52
+ def test_date_out_bind
53
+ cursor = @conn.parse(<<-EOS)
54
+ BEGIN
55
+ :out := TO_DATE(:in, 'YYYY-MM-DD HH24:MI:SS');
56
+ END;
57
+ EOS
58
+ cursor.bind_param(:out, nil, DateTime)
59
+ cursor.bind_param(:in, nil, String, 36)
60
+ ['2005-06-01 00:00:00',
61
+ '2005-12-31 23:59:59',
62
+ '2006-01-01 00:00:00'].each do |date|
63
+ cursor[:in] = date
64
+ cursor.exec
65
+ assert_equal(string_to_datetime(date), cursor[:out])
66
+ end
67
+ cursor.close
68
+ end
69
+
70
+ def test_date_in_bind
71
+ cursor = @conn.parse(<<-EOS)
72
+ DECLARE
73
+ dt date;
74
+ BEGIN
75
+ dt := :in;
76
+ :out := TO_CHAR(dt, 'YYYY-MM-DD HH24:MI:SS');
77
+ END;
78
+ EOS
79
+ cursor.bind_param(:out, nil, String, 33)
80
+ cursor.bind_param(:in, nil, DateTime)
81
+ ['2005-06-01 00:00:00',
82
+ '2005-12-31 23:59:59',
83
+ '2006-01-01 00:00:00'].each do |date|
84
+ cursor[:in] = string_to_datetime(date)
85
+ cursor.exec
86
+ assert_equal(date, cursor[:out])
87
+ end
88
+ cursor.close
89
+ end
90
+
91
+ def test_timestamp_select
92
+ ['2005-06-01 00:00:00.999999000',
93
+ '2005-12-31 23:59:59.999999000',
94
+ '2006-01-01 00:00:00.000000000'].each do |date|
95
+ @conn.exec(<<-EOS) do |row|
96
+ SELECT TO_TIMESTAMP('#{date}', 'YYYY-MM-DD HH24:MI:SS.FF') FROM dual
97
+ EOS
98
+ assert_equal(Time.local(*date.scanf("%d-%d-%d %d:%d:%d.%06d")), row[0])
99
+ end
100
+ end
101
+ end
102
+
103
+ def test_timestamp_out_bind
104
+ cursor = @conn.parse(<<-EOS)
105
+ BEGIN
106
+ :out := TO_TIMESTAMP(:in, 'YYYY-MM-DD HH24:MI:SS.FF');
107
+ END;
108
+ EOS
109
+ cursor.bind_param(:out, nil, DateTime)
110
+ cursor.bind_param(:in, nil, String, 36)
111
+ ['2005-06-01 00:00:00.999999000',
112
+ '2005-12-31 23:59:59.999999000',
113
+ '2006-01-01 00:00:00.000000000'].each do |date|
114
+ cursor[:in] = date
115
+ cursor.exec
116
+ assert_equal(string_to_datetime(date), cursor[:out])
117
+ end
118
+ cursor.close
119
+ end
120
+
121
+ def test_timestamp_in_bind
122
+ cursor = @conn.parse(<<-EOS)
123
+ BEGIN
124
+ :out := TO_CHAR(:in, 'YYYY-MM-DD HH24:MI:SS.FF');
125
+ END;
126
+ EOS
127
+ cursor.bind_param(:out, nil, String, 33)
128
+ cursor.bind_param(:in, nil, DateTime)
129
+ ['2005-06-01 00:00:00.999999000',
130
+ '2005-12-31 23:59:59.999999000',
131
+ '2006-01-01 00:00:00.000000000'].each do |date|
132
+ cursor[:in] = string_to_datetime(date)
133
+ cursor.exec
134
+ assert_equal(date, cursor[:out])
135
+ end
136
+ cursor.close
137
+ end
138
+
139
+ def test_timestamp_tz_select
140
+ ['2005-06-01 00:00:00.999999000 +00:00',
141
+ '2005-12-31 23:59:59.999999000 +08:30',
142
+ '2006-01-01 00:00:00.000000000 -08:30'].each do |date|
143
+ @conn.exec(<<-EOS) do |row|
144
+ SELECT TO_TIMESTAMP_TZ('#{date}', 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM') FROM dual
145
+ EOS
146
+ expected_val = begin
147
+ string_to_time(date)
148
+ rescue
149
+ string_to_datetime(date)
150
+ end
151
+ assert_equal(expected_val, row[0])
152
+ end
153
+ end
154
+ end
155
+
156
+ def test_timestamp_tz_out_bind
157
+ cursor = @conn.parse(<<-EOS)
158
+ BEGIN
159
+ :out := TO_TIMESTAMP_TZ(:in, 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM');
160
+ END;
161
+ EOS
162
+ cursor.bind_param(:out, nil, DateTime)
163
+ cursor.bind_param(:in, nil, String, 36)
164
+ ['2005-06-01 00:00:00.999999000 -08:30',
165
+ '2005-12-31 23:59:59.999999000 +00:00',
166
+ '2006-01-01 00:00:00.000000000 +08:30'].each do |date|
167
+ cursor[:in] = date
168
+ cursor.exec
169
+ assert_equal(string_to_datetime(date), cursor[:out])
170
+ end
171
+ cursor.close
172
+ end
173
+
174
+ def test_timestamp_tz_in_bind
175
+ cursor = @conn.parse(<<-EOS)
176
+ BEGIN
177
+ :out := TO_CHAR(:in, 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM');
178
+ END;
179
+ EOS
180
+ cursor.bind_param(:out, nil, String, 36)
181
+ cursor.bind_param(:in, nil, DateTime)
182
+ ['2005-06-01 00:00:00.999999999 +08:30',
183
+ '2005-12-31 23:59:59.999999000 -08:30',
184
+ '2006-01-01 00:00:00.000000000 +00:00'].each do |date|
185
+ cursor[:in] = string_to_datetime(date)
186
+ cursor.exec
187
+ assert_equal(date, cursor[:out])
188
+ end
189
+ cursor.close
190
+ end
191
+
192
+ def test_datetype_duck_typing
193
+ cursor = @conn.parse("BEGIN :out := :in; END;")
194
+ cursor.bind_param(:in, nil, DateTime)
195
+ cursor.bind_param(:out, nil, DateTime)
196
+ obj = Object.new
197
+ # test year, month, day
198
+ def obj.year; 2006; end
199
+ def obj.month; 12; end
200
+ def obj.day; 31; end
201
+ cursor[:in] = obj
202
+ cursor.exec
203
+ assert_equal(string_to_datetime('2006-12-31 00:00:00'), cursor[:out])
204
+ # test hour
205
+ def obj.hour; 23; end
206
+ cursor[:in] = obj
207
+ cursor.exec
208
+ assert_equal(string_to_datetime('2006-12-31 23:00:00'), cursor[:out])
209
+ # test min
210
+ def obj.min; 59; end
211
+ cursor[:in] = obj
212
+ cursor.exec
213
+ assert_equal(string_to_datetime('2006-12-31 23:59:00'), cursor[:out])
214
+ # test sec
215
+ def obj.sec; 59; end
216
+ cursor[:in] = obj
217
+ cursor.exec
218
+ assert_equal(string_to_datetime('2006-12-31 23:59:59'), cursor[:out])
219
+
220
+ # test sec_fraction
221
+ def obj.sec_fraction; DateTime.parse('0001-01-01 00:00:00.000001').sec_fraction * 999999 ; end
222
+ cursor[:in] = obj
223
+ cursor.exec
224
+ assert_equal(string_to_datetime('2006-12-31 23:59:59.999999'), cursor[:out])
225
+ # test utc_offset (Time)
226
+ def obj.utc_offset; @utc_offset; end
227
+ obj.instance_variable_set(:@utc_offset, 9 * 60 * 60)
228
+ cursor[:in] = obj
229
+ cursor.exec
230
+ assert_equal(string_to_datetime('2006-12-31 23:59:59.999999 +09:00'), cursor[:out])
231
+ obj.instance_variable_set(:@utc_offset, -5 * 60 * 60)
232
+ cursor[:in] = obj
233
+ cursor.exec
234
+ assert_equal(string_to_datetime('2006-12-31 23:59:59.999999 -05:00'), cursor[:out])
235
+ # test offset (DateTime)
236
+ def obj.offset; @offset; end
237
+ obj.instance_variable_set(:@offset, 9.to_r / 24)
238
+ cursor[:in] = obj
239
+ cursor.exec
240
+ assert_equal(string_to_datetime('2006-12-31 23:59:59.999999 +09:00'), cursor[:out])
241
+ obj.instance_variable_set(:@offset, -5.to_r / 24)
242
+ cursor[:in] = obj
243
+ cursor.exec
244
+ assert_equal(string_to_datetime('2006-12-31 23:59:59.999999 -05:00'), cursor[:out])
245
+ end
246
+
247
+ def test_timezone
248
+ begin
249
+ # temporarily change the mapping to test OCI8::BindType::Util.default_timezone.
250
+ assert_raise(ArgumentError) do
251
+ OCI8::BindType::Util.default_timezone = :invalid_value
252
+ end
253
+
254
+ =begin
255
+ [:local, :utc].each do |tz|
256
+ OCI8::BindType::Util.default_timezone = tz
257
+ @conn.exec("select sysdate, to_date('2008-01-02', 'yyyy-mm-dd') from dual") do |row|
258
+ row.each do |dt|
259
+ assert_kind_of(Time, dt)
260
+ assert_equal(tz, dt.utc? ? :utc : :local)
261
+ end
262
+ assert_equal(2008, row[1].year)
263
+ assert_equal(1, row[1].month)
264
+ assert_equal(2, row[1].day)
265
+ end
266
+ end
267
+ =end
268
+ ensure
269
+ OCI8::BindType::Util.default_timezone = :local
270
+ end
271
+
272
+ ses_tz = nil
273
+ @conn.exec('select sessiontimezone from dual') do |row|
274
+ ses_tz = row[0]
275
+ end
276
+
277
+ begin
278
+ ['+09:00', '+00:00', '-05:00'].each do |tz|
279
+ @conn.exec("alter session set time_zone = '#{tz}'")
280
+ @conn.exec("select current_timestamp, sysdate, to_timestamp('2008-01-02', 'yyyy-mm-dd') from dual") do |row|
281
+ row.each do |dt|
282
+ case dt
283
+ when Time
284
+ assert_equal(tz, timezone_string(*((dt.utc_offset / 60).divmod 60)))
285
+ when DateTime
286
+ tz = tz.gsub(/:/, '') if RUBY_VERSION <= '1.8.5'
287
+ assert_equal(tz, dt.zone)
288
+ else
289
+ flunk "unexpedted type #{dt.class}"
290
+ end
291
+ end
292
+ assert_equal(2008, row[2].year)
293
+ assert_equal(1, row[2].month)
294
+ assert_equal(2, row[2].day)
295
+ end
296
+ end
297
+ ensure
298
+ @conn.exec("alter session set time_zone = '#{ses_tz}'")
299
+ end
300
+ end
301
+
302
+ def test_interval_ym_select
303
+ [['2006-01-01', '2004-03-01'],
304
+ ['2006-01-01', '2005-03-01'],
305
+ ['2006-01-01', '2006-03-01'],
306
+ ['2006-01-01', '2007-03-01']
307
+ ].each do |date1, date2|
308
+ @conn.exec(<<-EOS) do |row|
309
+ SELECT (TO_TIMESTAMP('#{date1}', 'YYYY-MM-DD')
310
+ - TO_TIMESTAMP('#{date2}', 'YYYY-MM-DD')) YEAR TO MONTH
311
+ FROM dual
312
+ EOS
313
+ assert_equal(DateTime.parse(date1), DateTime.parse(date2) >> row[0])
314
+ end
315
+ end
316
+ end
317
+
318
+ def test_interval_ym_out_bind
319
+ cursor = @conn.parse(<<-EOS)
320
+ DECLARE
321
+ ts1 TIMESTAMP;
322
+ ts2 TIMESTAMP;
323
+ BEGIN
324
+ ts1 := TO_TIMESTAMP(:in1, 'YYYY-MM-DD');
325
+ ts2 := TO_TIMESTAMP(:in2, 'YYYY-MM-DD');
326
+ :out := (ts1 - ts2) YEAR TO MONTH;
327
+ END;
328
+ EOS
329
+ cursor.bind_param(:out, nil, :interval_ym)
330
+ cursor.bind_param(:in1, nil, String, 36)
331
+ cursor.bind_param(:in2, nil, String, 36)
332
+ [['2006-01-01', '2004-03-01'],
333
+ ['2006-01-01', '2005-03-01'],
334
+ ['2006-01-01', '2006-03-01'],
335
+ ['2006-01-01', '2007-03-01']
336
+ ].each do |date1, date2|
337
+ cursor[:in1] = date1
338
+ cursor[:in2] = date2
339
+ cursor.exec
340
+ assert_equal(DateTime.parse(date1), DateTime.parse(date2) >> cursor[:out])
341
+ end
342
+ cursor.close
343
+ end
344
+
345
+ def test_interval_ym_in_bind
346
+ cursor = @conn.parse(<<-EOS)
347
+ DECLARE
348
+ ts1 TIMESTAMP;
349
+ BEGIN
350
+ ts1 := TO_TIMESTAMP(:in1, 'YYYY-MM-DD');
351
+ :out := TO_CHAR(ts1 + :in2, 'YYYY-MM-DD');
352
+ END;
353
+ EOS
354
+ cursor.bind_param(:out, nil, String, 36)
355
+ cursor.bind_param(:in1, nil, String, 36)
356
+ cursor.bind_param(:in2, nil, :interval_ym)
357
+ [['2006-01-01', -25],
358
+ ['2006-01-01', -24],
359
+ ['2006-01-01', -23],
360
+ ['2006-01-01', -13],
361
+ ['2006-01-01', -12],
362
+ ['2006-01-01', -11],
363
+ ['2006-01-01', +2],
364
+ ['2006-01-01', -2],
365
+ ['2006-01-01', +12]
366
+ ].each do |date, interval|
367
+ cursor[:in1] = date
368
+ cursor[:in2] = interval
369
+ cursor.exec
370
+ assert_equal(DateTime.parse(date) >> interval, DateTime.parse(cursor[:out]))
371
+ end
372
+ cursor.close
373
+ end
374
+
375
+ def test_interval_ds_select
376
+ [['2006-01-01', '2004-03-01'],
377
+ ['2006-01-01', '2005-03-01'],
378
+ ['2006-01-01', '2006-03-01'],
379
+ ['2006-01-01', '2007-03-01'],
380
+ ['2006-01-01', '2006-01-01 23:00:00'],
381
+ ['2006-01-01', '2006-01-01 00:59:00'],
382
+ ['2006-01-01', '2006-01-01 00:00:59'],
383
+ ['2006-01-01', '2006-01-01 00:00:00.999999'],
384
+ ['2006-01-01', '2006-01-01 23:59:59.999999'],
385
+ ['2006-01-01', '2005-12-31 23:00:00'],
386
+ ['2006-01-01', '2005-12-31 00:59:00'],
387
+ ['2006-01-01', '2005-12-31 00:00:59'],
388
+ ['2006-01-01', '2005-12-31 00:00:00.999999'],
389
+ ['2006-01-01', '2005-12-31 23:59:59.999999']
390
+ ].each do |date1, date2|
391
+ @conn.exec(<<-EOS) do |row|
392
+ SELECT (TO_TIMESTAMP('#{date1}', 'YYYY-MM-DD HH24:MI:SS.FF')
393
+ - TO_TIMESTAMP('#{date2}', 'YYYY-MM-DD HH24:MI:SS.FF')) DAY(3) TO SECOND
394
+ FROM dual
395
+ EOS
396
+ assert_in_delta(string_to_time(date1) - string_to_time(date2), row[0], 0.0000000001)
397
+ end
398
+ end
399
+ end
400
+
401
+ def test_interval_ds_out_bind
402
+ cursor = @conn.parse(<<-EOS)
403
+ DECLARE
404
+ ts1 TIMESTAMP;
405
+ ts2 TIMESTAMP;
406
+ BEGIN
407
+ ts1 := TO_TIMESTAMP(:in1, 'YYYY-MM-DD HH24:MI:SS.FF');
408
+ ts2 := TO_TIMESTAMP(:in2, 'YYYY-MM-DD HH24:MI:SS.FF');
409
+ :out := (ts1 - ts2) DAY TO SECOND(9);
410
+ END;
411
+ EOS
412
+ cursor.bind_param(:out, nil, :interval_ds)
413
+ cursor.bind_param(:in1, nil, String, 36)
414
+ cursor.bind_param(:in2, nil, String, 36)
415
+ [['2006-01-01', '2004-03-01'],
416
+ ['2006-01-01', '2005-03-01'],
417
+ ['2006-01-01', '2006-03-01'],
418
+ ['2006-01-01', '2007-03-01'],
419
+ ['2006-01-01', '2006-01-01 23:00:00'],
420
+ ['2006-01-01', '2006-01-01 00:59:00'],
421
+ ['2006-01-01', '2006-01-01 00:00:59'],
422
+ ['2006-01-01', '2006-01-01 00:00:00.999999'],
423
+ ['2006-01-01', '2006-01-01 23:59:59.999999'],
424
+ ['2006-01-01', '2005-12-31 23:00:00'],
425
+ ['2006-01-01', '2005-12-31 00:59:00'],
426
+ ['2006-01-01', '2005-12-31 00:00:59'],
427
+ ['2006-01-01', '2005-12-31 00:00:00.999999'],
428
+ ['2006-01-01', '2005-12-31 23:59:59.999999']
429
+ ].each do |date1, date2|
430
+ cursor[:in1] = date1
431
+ cursor[:in2] = date2
432
+ cursor.exec
433
+ assert_in_delta(string_to_time(date1) - string_to_time(date2), cursor[:out], 0.0000000001)
434
+ end
435
+ cursor.close
436
+ end
437
+
438
+ def test_interval_ds_in_bind
439
+ cursor = @conn.parse(<<-EOS)
440
+ DECLARE
441
+ ts1 TIMESTAMP;
442
+ BEGIN
443
+ ts1 := TO_TIMESTAMP(:in1, 'YYYY-MM-DD HH24:MI:SS.FF');
444
+ :out := TO_CHAR(ts1 + :in2, 'YYYY-MM-DD HH24:MI:SS.FF');
445
+ END;
446
+ EOS
447
+ cursor.bind_param(:out, nil, String, 36)
448
+ cursor.bind_param(:in1, nil, String, 36)
449
+ cursor.bind_param(:in2, nil, :interval_ds)
450
+ [['2006-01-01', -22],
451
+ ['2006-01-01', -10],
452
+ ['2006-01-01', +2],
453
+ ['2006-01-01', +12],
454
+ ['2006-01-01', -1.to_r / 24], # one hour
455
+ ['2006-01-01', -1.to_r / (24*60)], # one minute
456
+ ['2006-01-01', -1.to_r / (24*60*60)], # one second
457
+ ['2006-01-01', -999999.to_r / (24*60*60*1000000)], # 0.999999 seconds
458
+ ['2006-01-01', +1.to_r / 24], # one hour
459
+ ['2006-01-01', +1.to_r / (24*60)], # one minute
460
+ ['2006-01-01', +1.to_r / (24*60*60)], # one second
461
+ ['2006-01-01', +999999.to_r / (24*60*60*1000000)] # 0.999999 seconds
462
+ ].each do |date, interval|
463
+ interval *= 86400
464
+ cursor[:in1] = date
465
+ cursor[:in2] = interval
466
+ cursor.exec
467
+ assert_equal(string_to_time(date) + interval, string_to_time(cursor[:out]))
468
+ end
469
+ cursor.close
470
+ end
471
+
472
+ def test_days_interval_ds_select
473
+ [['2006-01-01', '2004-03-01'],
474
+ ['2006-01-01', '2005-03-01'],
475
+ ['2006-01-01', '2006-03-01'],
476
+ ['2006-01-01', '2007-03-01'],
477
+ ['2006-01-01', '2006-01-01 23:00:00'],
478
+ ['2006-01-01', '2006-01-01 00:59:00'],
479
+ ['2006-01-01', '2006-01-01 00:00:59'],
480
+ ['2006-01-01', '2006-01-01 00:00:00.999999'],
481
+ ['2006-01-01', '2006-01-01 23:59:59.999999'],
482
+ ['2006-01-01', '2005-12-31 23:00:00'],
483
+ ['2006-01-01', '2005-12-31 00:59:00'],
484
+ ['2006-01-01', '2005-12-31 00:00:59'],
485
+ ['2006-01-01', '2005-12-31 00:00:00.999999'],
486
+ ['2006-01-01', '2005-12-31 23:59:59.999999']
487
+ ].each do |date1, date2|
488
+ begin
489
+ OCI8::BindType::IntervalDS.unit = :day
490
+ @conn.exec(<<-EOS) do |row|
491
+ SELECT (TO_TIMESTAMP('#{date1}', 'YYYY-MM-DD HH24:MI:SS.FF')
492
+ - TO_TIMESTAMP('#{date2}', 'YYYY-MM-DD HH24:MI:SS.FF')) DAY(3) TO SECOND
493
+ FROM dual
494
+ EOS
495
+ assert_equal(DateTime.parse(date1) - DateTime.parse(date2), row[0])
496
+ end
497
+ ensure
498
+ OCI8::BindType::IntervalDS.unit = :second
499
+ end
500
+ end
501
+ end
502
+
503
+ def test_days_interval_ds_out_bind
504
+ cursor = @conn.parse(<<-EOS)
505
+ DECLARE
506
+ ts1 TIMESTAMP;
507
+ ts2 TIMESTAMP;
508
+ BEGIN
509
+ ts1 := TO_TIMESTAMP(:in1, 'YYYY-MM-DD HH24:MI:SS.FF');
510
+ ts2 := TO_TIMESTAMP(:in2, 'YYYY-MM-DD HH24:MI:SS.FF');
511
+ :out := (ts1 - ts2) DAY TO SECOND(9);
512
+ END;
513
+ EOS
514
+ cursor.bind_param(:out, nil, :interval_ds)
515
+ cursor.bind_param(:in1, nil, String, 36)
516
+ cursor.bind_param(:in2, nil, String, 36)
517
+ [['2006-01-01', '2004-03-01'],
518
+ ['2006-01-01', '2005-03-01'],
519
+ ['2006-01-01', '2006-03-01'],
520
+ ['2006-01-01', '2007-03-01'],
521
+ ['2006-01-01', '2006-01-01 23:00:00'],
522
+ ['2006-01-01', '2006-01-01 00:59:00'],
523
+ ['2006-01-01', '2006-01-01 00:00:59'],
524
+ ['2006-01-01', '2006-01-01 00:00:00.999999'],
525
+ ['2006-01-01', '2006-01-01 23:59:59.999999'],
526
+ ['2006-01-01', '2005-12-31 23:00:00'],
527
+ ['2006-01-01', '2005-12-31 00:59:00'],
528
+ ['2006-01-01', '2005-12-31 00:00:59'],
529
+ ['2006-01-01', '2005-12-31 00:00:00.999999'],
530
+ ['2006-01-01', '2005-12-31 23:59:59.999999']
531
+ ].each do |date1, date2|
532
+ begin
533
+ OCI8::BindType::IntervalDS.unit = :day
534
+ cursor[:in1] = date1
535
+ cursor[:in2] = date2
536
+ cursor.exec
537
+ assert_equal(DateTime.parse(date1) - DateTime.parse(date2), cursor[:out])
538
+ ensure
539
+ OCI8::BindType::IntervalDS.unit = :second
540
+ end
541
+ end
542
+ cursor.close
543
+ end
544
+
545
+ def test_days_interval_ds_in_bind
546
+ cursor = @conn.parse(<<-EOS)
547
+ DECLARE
548
+ ts1 TIMESTAMP;
549
+ BEGIN
550
+ ts1 := TO_TIMESTAMP(:in1, 'YYYY-MM-DD');
551
+ :out := TO_CHAR(ts1 + :in2, 'YYYY-MM-DD HH24:MI:SS.FF');
552
+ END;
553
+ EOS
554
+ cursor.bind_param(:out, nil, String, 36)
555
+ cursor.bind_param(:in1, nil, String, 36)
556
+ cursor.bind_param(:in2, nil, :interval_ds)
557
+ [['2006-01-01', -22],
558
+ ['2006-01-01', -10],
559
+ ['2006-01-01', +2],
560
+ ['2006-01-01', +12],
561
+ ['2006-01-01', -1.to_r / 24], # one hour
562
+ ['2006-01-01', -1.to_r / (24*60)], # one minute
563
+ ['2006-01-01', -1.to_r / (24*60*60)], # one second
564
+ ['2006-01-01', -999999.to_r / (24*60*60*1000000)], # 0.999999 seconds
565
+ ['2006-01-01', +1.to_r / 24], # one hour
566
+ ['2006-01-01', +1.to_r / (24*60)], # one minute
567
+ ['2006-01-01', +1.to_r / (24*60*60)], # one second
568
+ ['2006-01-01', +999999.to_r / (24*60*60*1000000)] # 0.999999 seconds
569
+ ].each do |date, interval|
570
+ begin
571
+ OCI8::BindType::IntervalDS.unit = :day
572
+ cursor[:in1] = date
573
+ cursor[:in2] = interval
574
+ cursor.exec
575
+ assert_equal(DateTime.parse(date) + interval, DateTime.parse(cursor[:out]))
576
+ ensure
577
+ OCI8::BindType::IntervalDS.unit = :second
578
+ end
579
+ end
580
+ end
581
+ end # TestOCI8