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