ruby-oci8-master 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +2321 -0
- data/Makefile +88 -0
- data/NEWS +303 -0
- data/README +76 -0
- data/VERSION +1 -0
- data/dist-files +83 -0
- data/doc/api.en.html +527 -0
- data/doc/api.en.rd +554 -0
- data/doc/api.ja.html +525 -0
- data/doc/api.ja.rd +557 -0
- data/doc/manual.css +35 -0
- data/ext/oci8/.document +18 -0
- data/ext/oci8/MANIFEST +18 -0
- data/ext/oci8/apiwrap.c.tmpl +182 -0
- data/ext/oci8/apiwrap.h.tmpl +61 -0
- data/ext/oci8/apiwrap.rb +91 -0
- data/ext/oci8/apiwrap.yml +1455 -0
- data/ext/oci8/attr.c +105 -0
- data/ext/oci8/bind.c +366 -0
- data/ext/oci8/connection_pool.c +199 -0
- data/ext/oci8/encoding.c +289 -0
- data/ext/oci8/env.c +178 -0
- data/ext/oci8/error.c +378 -0
- data/ext/oci8/extconf.rb +179 -0
- data/ext/oci8/lob.c +805 -0
- data/ext/oci8/metadata.c +232 -0
- data/ext/oci8/object.c +727 -0
- data/ext/oci8/oci8.c +1156 -0
- data/ext/oci8/oci8.h +574 -0
- data/ext/oci8/oci8lib.c +527 -0
- data/ext/oci8/ocidatetime.c +484 -0
- data/ext/oci8/ocihandle.c +751 -0
- data/ext/oci8/ocinumber.c +1612 -0
- data/ext/oci8/oraconf.rb +1119 -0
- data/ext/oci8/oradate.c +611 -0
- data/ext/oci8/oranumber_util.c +352 -0
- data/ext/oci8/oranumber_util.h +24 -0
- data/ext/oci8/post-config.rb +5 -0
- data/ext/oci8/stmt.c +673 -0
- data/ext/oci8/thread_util.c +85 -0
- data/ext/oci8/thread_util.h +30 -0
- data/ext/oci8/win32.c +137 -0
- data/lib/.document +1 -0
- data/lib/dbd/OCI8.rb +591 -0
- data/lib/oci8.rb.in +94 -0
- data/lib/oci8/.document +8 -0
- data/lib/oci8/bindtype.rb +349 -0
- data/lib/oci8/compat.rb +113 -0
- data/lib/oci8/connection_pool.rb +99 -0
- data/lib/oci8/datetime.rb +611 -0
- data/lib/oci8/encoding-init.rb +74 -0
- data/lib/oci8/encoding.yml +537 -0
- data/lib/oci8/metadata.rb +2132 -0
- data/lib/oci8/object.rb +581 -0
- data/lib/oci8/oci8.rb +721 -0
- data/lib/oci8/ocihandle.rb +425 -0
- data/lib/oci8/oracle_version.rb +144 -0
- data/lib/oci8/properties.rb +73 -0
- data/metaconfig +142 -0
- data/pre-distclean.rb +7 -0
- data/ruby-oci8.gemspec +63 -0
- data/setup.rb +1331 -0
- data/test/README +4 -0
- data/test/config.rb +122 -0
- data/test/test_all.rb +51 -0
- data/test/test_appinfo.rb +63 -0
- data/test/test_array_dml.rb +333 -0
- data/test/test_bind_raw.rb +46 -0
- data/test/test_bind_time.rb +178 -0
- data/test/test_break.rb +96 -0
- data/test/test_clob.rb +82 -0
- data/test/test_connstr.rb +81 -0
- data/test/test_datetime.rb +582 -0
- data/test/test_dbi.rb +366 -0
- data/test/test_dbi_clob.rb +53 -0
- data/test/test_encoding.rb +100 -0
- data/test/test_error.rb +88 -0
- data/test/test_metadata.rb +1399 -0
- data/test/test_oci8.rb +434 -0
- data/test/test_oracle_version.rb +70 -0
- data/test/test_oradate.rb +256 -0
- data/test/test_oranumber.rb +746 -0
- data/test/test_rowid.rb +33 -0
- metadata +137 -0
data/ext/oci8/oradate.c
ADDED
@@ -0,0 +1,611 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* oradate.c
|
4
|
+
*
|
5
|
+
* Copyright (C) 2002-2008 KUBO Takehiro <kubo@jiubao.org>
|
6
|
+
*
|
7
|
+
* date and time between 4712 B.C. and 9999 A.D.
|
8
|
+
*/
|
9
|
+
#include "oci8.h"
|
10
|
+
#include <time.h>
|
11
|
+
|
12
|
+
static VALUE cOraDate;
|
13
|
+
|
14
|
+
/*
|
15
|
+
* Document-class: OraDate
|
16
|
+
*
|
17
|
+
* ruby class compatible with Oracle <tt>DATE</tt> data type.
|
18
|
+
* Date and time between 4712 B.C. and 9999 A.D.
|
19
|
+
*
|
20
|
+
*/
|
21
|
+
struct ora_date {
|
22
|
+
unsigned char century;
|
23
|
+
unsigned char year;
|
24
|
+
unsigned char month;
|
25
|
+
unsigned char day;
|
26
|
+
unsigned char hour;
|
27
|
+
unsigned char minute;
|
28
|
+
unsigned char second;
|
29
|
+
};
|
30
|
+
typedef struct ora_date ora_date_t;
|
31
|
+
|
32
|
+
#define Set_year(od, y) (od)->century = y / 100 + 100, (od)->year = y % 100 + 100
|
33
|
+
#define Set_month(od, m) (od)->month = m
|
34
|
+
#define Set_day(od, d) (od)->day = d
|
35
|
+
#define Set_hour(od, h) (od)->hour = h + 1
|
36
|
+
#define Set_minute(od, m) (od)->minute = m + 1
|
37
|
+
#define Set_second(od, s) (od)->second = s + 1
|
38
|
+
|
39
|
+
#define Get_year(od) (((od)->century - 100) * 100 + ((od)->year - 100))
|
40
|
+
#define Get_month(od) ((od)->month)
|
41
|
+
#define Get_day(od) ((od)->day)
|
42
|
+
#define Get_hour(od) ((od)->hour - 1)
|
43
|
+
#define Get_minute(od) ((od)->minute - 1)
|
44
|
+
#define Get_second(od) ((od)->second - 1)
|
45
|
+
|
46
|
+
#define Check_year(year) \
|
47
|
+
if (year < -4712 || 9999 < year) \
|
48
|
+
rb_raise(rb_eRangeError, "Out of range for year %d (expect -4712 .. 9999)", year)
|
49
|
+
#define Check_month(month) \
|
50
|
+
if (month < 1 || 12 < month) \
|
51
|
+
rb_raise(rb_eRangeError, "Out of range for month %d (expect 1 .. 12)", month)
|
52
|
+
#define Check_day(day) \
|
53
|
+
if (day < 1 || 31 < day) \
|
54
|
+
rb_raise(rb_eRangeError, "Out of range for day %d (expect 1 .. 31)", day)
|
55
|
+
#define Check_hour(hour) \
|
56
|
+
if (hour < 0 || 23 < hour) \
|
57
|
+
rb_raise(rb_eRangeError, "Out of range for hour %d (expect 0 .. 24)", hour)
|
58
|
+
#define Check_minute(min) \
|
59
|
+
if (min < 0 || 59 < min) \
|
60
|
+
rb_raise(rb_eRangeError, "Out of range for minute %d (expect 0 .. 59)", min)
|
61
|
+
#define Check_second(sec) \
|
62
|
+
if (sec < 0 || 59 < sec) \
|
63
|
+
rb_raise(rb_eRangeError, "Out of range for second %d (expect 0 .. 59)", sec)
|
64
|
+
|
65
|
+
static void oci8_set_ora_date(ora_date_t *od, int year, int month, int day, int hour, int minute, int second)
|
66
|
+
{
|
67
|
+
Set_year(od, year);
|
68
|
+
Set_month(od, month);
|
69
|
+
Set_day(od, day);
|
70
|
+
Set_hour(od, hour);
|
71
|
+
Set_minute(od, minute);
|
72
|
+
Set_second(od, second);
|
73
|
+
}
|
74
|
+
|
75
|
+
static VALUE ora_date_s_allocate(VALUE klass)
|
76
|
+
{
|
77
|
+
ora_date_t *od;
|
78
|
+
return Data_Make_Struct(klass, ora_date_t, NULL, xfree, od);
|
79
|
+
}
|
80
|
+
|
81
|
+
/*
|
82
|
+
* call-seq:
|
83
|
+
* OraDate.new(year = 1, month = 1, day = 1, hour = 0, min = 0, sec = 0) -> oradate
|
84
|
+
*
|
85
|
+
* Returns an <code>OraDate</code> object initialized to the specified date and time.
|
86
|
+
*/
|
87
|
+
static VALUE ora_date_initialize(int argc, VALUE *argv, VALUE self)
|
88
|
+
{
|
89
|
+
VALUE vyear, vmonth, vday, vhour, vmin, vsec;
|
90
|
+
ora_date_t *od = DATA_PTR(self);
|
91
|
+
int year, month, day, hour, min, sec;
|
92
|
+
|
93
|
+
rb_scan_args(argc, argv, "06", &vyear, &vmonth, &vday, &vhour, &vmin, &vsec);
|
94
|
+
/* set year */
|
95
|
+
if (argc > 0) {
|
96
|
+
year = NUM2INT(vyear);
|
97
|
+
Check_year(year);
|
98
|
+
} else {
|
99
|
+
year = 1;
|
100
|
+
}
|
101
|
+
/* set month */
|
102
|
+
if (argc > 1) {
|
103
|
+
month = NUM2INT(vmonth);
|
104
|
+
Check_month(month);
|
105
|
+
} else {
|
106
|
+
month = 1;
|
107
|
+
}
|
108
|
+
/* set day */
|
109
|
+
if (argc > 2) {
|
110
|
+
day = NUM2INT(vday);
|
111
|
+
Check_day(day);
|
112
|
+
} else {
|
113
|
+
day = 1;
|
114
|
+
}
|
115
|
+
/* set hour */
|
116
|
+
if (argc > 3) {
|
117
|
+
hour = NUM2INT(vhour);
|
118
|
+
Check_hour(hour);
|
119
|
+
} else {
|
120
|
+
hour = 0;
|
121
|
+
}
|
122
|
+
/* set minute */
|
123
|
+
if (argc > 4) {
|
124
|
+
min = NUM2INT(vmin);
|
125
|
+
Check_minute(min);
|
126
|
+
} else {
|
127
|
+
min = 0;
|
128
|
+
}
|
129
|
+
/* set second */
|
130
|
+
if (argc > 5) {
|
131
|
+
sec = NUM2INT(vsec);
|
132
|
+
Check_second(sec);
|
133
|
+
} else {
|
134
|
+
sec = 0;
|
135
|
+
}
|
136
|
+
|
137
|
+
oci8_set_ora_date(od, year, month, day, hour, min, sec);
|
138
|
+
return Qnil;
|
139
|
+
}
|
140
|
+
|
141
|
+
/* :nodoc: */
|
142
|
+
static VALUE ora_date_initialize_copy(VALUE lhs, VALUE rhs)
|
143
|
+
{
|
144
|
+
ora_date_t *l, *r;
|
145
|
+
|
146
|
+
rb_call_super(1, &rhs);
|
147
|
+
Data_Get_Struct(lhs, ora_date_t, l);
|
148
|
+
Data_Get_Struct(rhs, ora_date_t, r);
|
149
|
+
memcpy(l, r, sizeof(ora_date_t));
|
150
|
+
return lhs;
|
151
|
+
}
|
152
|
+
|
153
|
+
/*
|
154
|
+
* call-seq:
|
155
|
+
* OraDate.now() -> oradate
|
156
|
+
*
|
157
|
+
* Returns an <code>OraDate</code> object initialized to the
|
158
|
+
* current local time.
|
159
|
+
*/
|
160
|
+
static VALUE ora_date_s_now(int argc, VALUE *argv, VALUE klass)
|
161
|
+
{
|
162
|
+
VALUE obj = ora_date_s_allocate(klass);
|
163
|
+
ora_date_t *od = DATA_PTR(obj);
|
164
|
+
time_t tm = time(0);
|
165
|
+
int year, month, day, hour, min, sec;
|
166
|
+
#ifdef HAVE_LOCALTIME_R
|
167
|
+
struct tm t;
|
168
|
+
localtime_r(&tm, &t);
|
169
|
+
#define tp (&t)
|
170
|
+
#else
|
171
|
+
struct tm *tp;
|
172
|
+
tp = localtime(&tm);
|
173
|
+
#endif
|
174
|
+
year = tp->tm_year + 1900;
|
175
|
+
month = tp->tm_mon + 1;
|
176
|
+
day = tp->tm_mday;
|
177
|
+
hour = tp->tm_hour;
|
178
|
+
min = tp->tm_min;
|
179
|
+
sec = tp->tm_sec;
|
180
|
+
|
181
|
+
oci8_set_ora_date(od, year, month, day, hour, min, sec);
|
182
|
+
return obj;
|
183
|
+
}
|
184
|
+
|
185
|
+
/*
|
186
|
+
* call-seq:
|
187
|
+
* oradate.to_s -> string
|
188
|
+
*
|
189
|
+
* Returns a string representing <i>oradate</i>.
|
190
|
+
* The string format is 'yyyy/mm/dd hh:mi:ss'.
|
191
|
+
*/
|
192
|
+
static VALUE ora_date_to_s(VALUE self)
|
193
|
+
{
|
194
|
+
ora_date_t *od;
|
195
|
+
char buf[30];
|
196
|
+
|
197
|
+
Data_Get_Struct(self, ora_date_t, od);
|
198
|
+
sprintf(buf, "%04d/%02d/%02d %02d:%02d:%02d", Get_year(od), Get_month(od),
|
199
|
+
Get_day(od), Get_hour(od), Get_minute(od), Get_second(od));
|
200
|
+
return rb_usascii_str_new_cstr(buf);
|
201
|
+
}
|
202
|
+
|
203
|
+
/*
|
204
|
+
* call-seq:
|
205
|
+
* oradate.to_a -> array
|
206
|
+
*
|
207
|
+
* Returns a 6-element <i>array</i> of values for <i>oradate</i>:
|
208
|
+
* {<code>[year, month, day, hour, minute, second]</code>}.
|
209
|
+
*/
|
210
|
+
static VALUE ora_date_to_a(VALUE self)
|
211
|
+
{
|
212
|
+
ora_date_t *od;
|
213
|
+
VALUE ary[6];
|
214
|
+
|
215
|
+
Data_Get_Struct(self, ora_date_t, od);
|
216
|
+
ary[0] = INT2FIX(Get_year(od));
|
217
|
+
ary[1] = INT2FIX(Get_month(od));
|
218
|
+
ary[2] = INT2FIX(Get_day(od));
|
219
|
+
ary[3] = INT2FIX(Get_hour(od));
|
220
|
+
ary[4] = INT2FIX(Get_minute(od));
|
221
|
+
ary[5] = INT2FIX(Get_second(od));
|
222
|
+
return rb_ary_new4(6, ary);
|
223
|
+
}
|
224
|
+
|
225
|
+
/*
|
226
|
+
* call-seq:
|
227
|
+
* oradate.year -> fixnum
|
228
|
+
*
|
229
|
+
* Returns the year (-4712..9999) for <i>oradate</i>.
|
230
|
+
*/
|
231
|
+
static VALUE ora_date_year(VALUE self)
|
232
|
+
{
|
233
|
+
ora_date_t *od;
|
234
|
+
|
235
|
+
Data_Get_Struct(self, ora_date_t, od);
|
236
|
+
return INT2FIX(Get_year(od));
|
237
|
+
}
|
238
|
+
|
239
|
+
/*
|
240
|
+
* call-seq:
|
241
|
+
* oradate.year = fixnum
|
242
|
+
*
|
243
|
+
* Sets the year (-4712..9999) for <i>oradate</i>.
|
244
|
+
*/
|
245
|
+
static VALUE ora_date_set_year(VALUE self, VALUE val)
|
246
|
+
{
|
247
|
+
ora_date_t *od;
|
248
|
+
int v;
|
249
|
+
|
250
|
+
v = NUM2INT(val);
|
251
|
+
Check_year(v);
|
252
|
+
Data_Get_Struct(self, ora_date_t, od);
|
253
|
+
Set_year(od, v);
|
254
|
+
return self;
|
255
|
+
}
|
256
|
+
|
257
|
+
/*
|
258
|
+
* call-seq:
|
259
|
+
* oradate.month -> fixnum
|
260
|
+
*
|
261
|
+
* Returns the month of the year (1..12) for <i>oradate</i>.
|
262
|
+
*/
|
263
|
+
static VALUE ora_date_month(VALUE self)
|
264
|
+
{
|
265
|
+
ora_date_t *od;
|
266
|
+
|
267
|
+
Data_Get_Struct(self, ora_date_t, od);
|
268
|
+
return INT2FIX(Get_month(od));
|
269
|
+
}
|
270
|
+
|
271
|
+
/*
|
272
|
+
* call-seq:
|
273
|
+
* oradate.month = fixnum
|
274
|
+
*
|
275
|
+
* Sets the month of the year (1..12) for <i>oradate</i>.
|
276
|
+
*/
|
277
|
+
static VALUE ora_date_set_month(VALUE self, VALUE val)
|
278
|
+
{
|
279
|
+
ora_date_t *od;
|
280
|
+
int v;
|
281
|
+
|
282
|
+
v = NUM2INT(val);
|
283
|
+
Check_month(v);
|
284
|
+
Data_Get_Struct(self, ora_date_t, od);
|
285
|
+
Set_month(od, v);
|
286
|
+
return self;
|
287
|
+
}
|
288
|
+
|
289
|
+
/*
|
290
|
+
* call-seq:
|
291
|
+
* oradate.day -> fixnum
|
292
|
+
*
|
293
|
+
* Returns the day of the month (1..31) for <i>oradate</i>.
|
294
|
+
*/
|
295
|
+
static VALUE ora_date_day(VALUE self)
|
296
|
+
{
|
297
|
+
ora_date_t *od;
|
298
|
+
|
299
|
+
Data_Get_Struct(self, ora_date_t, od);
|
300
|
+
return INT2FIX(Get_day(od));
|
301
|
+
}
|
302
|
+
|
303
|
+
/*
|
304
|
+
* call-seq:
|
305
|
+
* oradate.day = fixnum
|
306
|
+
*
|
307
|
+
* Sets the day of the month (1..31) for <i>oradate</i>.
|
308
|
+
*/
|
309
|
+
static VALUE ora_date_set_day(VALUE self, VALUE val)
|
310
|
+
{
|
311
|
+
ora_date_t *od;
|
312
|
+
int v;
|
313
|
+
|
314
|
+
v = NUM2INT(val);
|
315
|
+
Check_day(v);
|
316
|
+
Data_Get_Struct(self, ora_date_t, od);
|
317
|
+
Set_day(od, v);
|
318
|
+
return self;
|
319
|
+
}
|
320
|
+
|
321
|
+
/*
|
322
|
+
* call-seq:
|
323
|
+
* oradate.hour -> fixnum
|
324
|
+
*
|
325
|
+
* Returns the hour of the day (0..23) for <i>oradate</i>.
|
326
|
+
*/
|
327
|
+
static VALUE ora_date_hour(VALUE self)
|
328
|
+
{
|
329
|
+
ora_date_t *od;
|
330
|
+
|
331
|
+
Data_Get_Struct(self, ora_date_t, od);
|
332
|
+
return INT2FIX(Get_hour(od));
|
333
|
+
}
|
334
|
+
|
335
|
+
/*
|
336
|
+
* call-seq:
|
337
|
+
* oradate.hour = fixnum
|
338
|
+
*
|
339
|
+
* Sets the hour of the day (0..23) for <i>oradate</i>.
|
340
|
+
*/
|
341
|
+
static VALUE ora_date_set_hour(VALUE self, VALUE val)
|
342
|
+
{
|
343
|
+
ora_date_t *od;
|
344
|
+
int v;
|
345
|
+
|
346
|
+
v = NUM2INT(val);
|
347
|
+
Check_hour(v);
|
348
|
+
Data_Get_Struct(self, ora_date_t, od);
|
349
|
+
Set_hour(od, v);
|
350
|
+
return self;
|
351
|
+
}
|
352
|
+
|
353
|
+
/*
|
354
|
+
* call-seq:
|
355
|
+
* oradate.minute -> fixnum
|
356
|
+
*
|
357
|
+
* Returns the minute of the hour (0..59) for <i>oradate</i>.
|
358
|
+
*/
|
359
|
+
static VALUE ora_date_minute(VALUE self)
|
360
|
+
{
|
361
|
+
ora_date_t *od;
|
362
|
+
|
363
|
+
Data_Get_Struct(self, ora_date_t, od);
|
364
|
+
return INT2FIX(Get_minute(od));
|
365
|
+
}
|
366
|
+
|
367
|
+
/*
|
368
|
+
* call-seq:
|
369
|
+
* oradate.minute = fixnum
|
370
|
+
*
|
371
|
+
* Sets the minute of the hour (0..59) for <i>oradate</i>.
|
372
|
+
*/
|
373
|
+
static VALUE ora_date_set_minute(VALUE self, VALUE val)
|
374
|
+
{
|
375
|
+
ora_date_t *od;
|
376
|
+
int v;
|
377
|
+
|
378
|
+
v = NUM2INT(val);
|
379
|
+
Check_minute(v);
|
380
|
+
Data_Get_Struct(self, ora_date_t, od);
|
381
|
+
Set_minute(od, v);
|
382
|
+
return self;
|
383
|
+
}
|
384
|
+
|
385
|
+
/*
|
386
|
+
* call-seq:
|
387
|
+
* oradate.second -> fixnum
|
388
|
+
*
|
389
|
+
* Returns the second of the minute (0..59) for <i>oradate</i>.
|
390
|
+
*/
|
391
|
+
static VALUE ora_date_second(VALUE self)
|
392
|
+
{
|
393
|
+
ora_date_t *od;
|
394
|
+
|
395
|
+
Data_Get_Struct(self, ora_date_t, od);
|
396
|
+
return INT2FIX(Get_second(od));
|
397
|
+
}
|
398
|
+
|
399
|
+
/*
|
400
|
+
* call-seq:
|
401
|
+
* oradate.second = fixnum
|
402
|
+
*
|
403
|
+
* Sets the second of the minute (0..59) for <i>oradate</i>.
|
404
|
+
*/
|
405
|
+
static VALUE ora_date_set_second(VALUE self, VALUE val)
|
406
|
+
{
|
407
|
+
ora_date_t *od;
|
408
|
+
int v;
|
409
|
+
|
410
|
+
v = NUM2INT(val);
|
411
|
+
Check_second(v);
|
412
|
+
Data_Get_Struct(self, ora_date_t, od);
|
413
|
+
Set_second(od, v);
|
414
|
+
return self;
|
415
|
+
}
|
416
|
+
|
417
|
+
/*
|
418
|
+
* call-seq:
|
419
|
+
* oradate.trunc
|
420
|
+
*
|
421
|
+
* Truncates hour, minute and second to zero for <i>oradate</i>.
|
422
|
+
*
|
423
|
+
* oradate = OraDate.now # 2008/07/17 11:07:30
|
424
|
+
* oradate.trunc # 2008/07/17 00:00:00
|
425
|
+
*/
|
426
|
+
static VALUE ora_date_trunc(VALUE self)
|
427
|
+
{
|
428
|
+
ora_date_t *od;
|
429
|
+
|
430
|
+
Data_Get_Struct(self, ora_date_t, od);
|
431
|
+
od->hour = 1;
|
432
|
+
od->minute = 1;
|
433
|
+
od->second = 1;
|
434
|
+
return self;
|
435
|
+
}
|
436
|
+
|
437
|
+
/*
|
438
|
+
* call-seq:
|
439
|
+
* oradate1 <=> oradate2 -> -1, 0, +1
|
440
|
+
*
|
441
|
+
* Comparison---Compares <i>oradate1</i> with <i>oradate2</i>.
|
442
|
+
* Other comparison operators are available because
|
443
|
+
* <code>Comparable</code> module is included.
|
444
|
+
*/
|
445
|
+
static VALUE ora_date_cmp(VALUE self, VALUE val)
|
446
|
+
{
|
447
|
+
ora_date_t *od1, *od2;
|
448
|
+
Data_Get_Struct(self, ora_date_t, od1);
|
449
|
+
Check_Object(val, cOraDate);
|
450
|
+
Data_Get_Struct(val, ora_date_t, od2);
|
451
|
+
if (od1->century < od2->century) return INT2FIX(-1);
|
452
|
+
if (od1->century > od2->century) return INT2FIX(1);
|
453
|
+
if (od1->year < od2->year) return INT2FIX(-1);
|
454
|
+
if (od1->year > od2->year) return INT2FIX(1);
|
455
|
+
if (od1->month < od2->month) return INT2FIX(-1);
|
456
|
+
if (od1->month > od2->month) return INT2FIX(1);
|
457
|
+
if (od1->day < od2->day) return INT2FIX(-1);
|
458
|
+
if (od1->day > od2->day) return INT2FIX(1);
|
459
|
+
if (od1->hour < od2->hour) return INT2FIX(-1);
|
460
|
+
if (od1->hour > od2->hour) return INT2FIX(1);
|
461
|
+
if (od1->minute < od2->minute) return INT2FIX(-1);
|
462
|
+
if (od1->minute > od2->minute) return INT2FIX(1);
|
463
|
+
if (od1->second < od2->second) return INT2FIX(-1);
|
464
|
+
if (od1->second > od2->second) return INT2FIX(1);
|
465
|
+
return INT2FIX(0);
|
466
|
+
}
|
467
|
+
|
468
|
+
/* :nodoc: */
|
469
|
+
static VALUE ora_date_hash(VALUE self)
|
470
|
+
{
|
471
|
+
ora_date_t *od;
|
472
|
+
unsigned int v;
|
473
|
+
|
474
|
+
Data_Get_Struct(self, ora_date_t, od);
|
475
|
+
v = (od->century << 8)
|
476
|
+
+ (od->year << 15)
|
477
|
+
+ (od->month << 22)
|
478
|
+
+ (od->day << 26)
|
479
|
+
+ (od->hour << 12)
|
480
|
+
+ (od->minute << 6)
|
481
|
+
+ (od->second << 0);
|
482
|
+
return INT2FIX(v);
|
483
|
+
}
|
484
|
+
|
485
|
+
/*
|
486
|
+
* call-seq:
|
487
|
+
* oradate._dump -> string
|
488
|
+
*
|
489
|
+
* Dumps <i>oradate</i> for marshaling.
|
490
|
+
*/
|
491
|
+
static VALUE ora_date_dump(int argc, VALUE *argv, VALUE self)
|
492
|
+
{
|
493
|
+
ora_date_t *od;
|
494
|
+
Data_Get_Struct(self, ora_date_t, od);
|
495
|
+
return rb_str_new((const char*)od, sizeof(ora_date_t)); /* ASCII-8BIT */
|
496
|
+
}
|
497
|
+
|
498
|
+
/*
|
499
|
+
* call-seq:
|
500
|
+
* OraDate._load(string) -> oradate
|
501
|
+
*
|
502
|
+
* Unmarshals a dumped <code>OraDate</code> object.
|
503
|
+
*/
|
504
|
+
static VALUE ora_date_s_load(VALUE klass, VALUE str)
|
505
|
+
{
|
506
|
+
ora_date_t *od;
|
507
|
+
VALUE obj;
|
508
|
+
|
509
|
+
Check_Type(str, T_STRING);
|
510
|
+
if (RSTRING_LEN(str) != sizeof(ora_date_t)) {
|
511
|
+
rb_raise(rb_eTypeError, "marshaled OraDate format differ");
|
512
|
+
}
|
513
|
+
obj = Data_Make_Struct(cOraDate, ora_date_t, NULL, xfree, od);
|
514
|
+
memcpy(od, RSTRING_PTR(str), sizeof(ora_date_t));
|
515
|
+
return obj;
|
516
|
+
}
|
517
|
+
|
518
|
+
/*
|
519
|
+
* Document-class: OCI8::BindType::OraDate
|
520
|
+
*
|
521
|
+
* This is a helper class to bind OraDate as Oracle's <tt>DATE</tt> datatype.
|
522
|
+
*
|
523
|
+
*/
|
524
|
+
static VALUE bind_oradate_get(oci8_bind_t *obind, void *data, void *null_struct)
|
525
|
+
{
|
526
|
+
ora_date_t *od;
|
527
|
+
|
528
|
+
VALUE obj = Data_Make_Struct(cOraDate, ora_date_t, NULL, xfree, od);
|
529
|
+
memcpy(od, data, sizeof(ora_date_t));
|
530
|
+
return obj;
|
531
|
+
}
|
532
|
+
|
533
|
+
static void bind_oradate_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val)
|
534
|
+
{
|
535
|
+
ora_date_t *od;
|
536
|
+
|
537
|
+
Check_Object(val, cOraDate);
|
538
|
+
Data_Get_Struct(val, ora_date_t, od);
|
539
|
+
memcpy(data, od, sizeof(ora_date_t));
|
540
|
+
}
|
541
|
+
|
542
|
+
static void bind_oradate_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
|
543
|
+
{
|
544
|
+
obind->value_sz = sizeof(ora_date_t);
|
545
|
+
obind->alloc_sz = sizeof(ora_date_t);
|
546
|
+
}
|
547
|
+
|
548
|
+
static void bind_oradate_init_elem(oci8_bind_t *obind, VALUE svc)
|
549
|
+
{
|
550
|
+
static const ora_date_t julian_day_0 = {100-47, 100-12, 1, 1, 1, 1, 1};
|
551
|
+
ub4 idx = 0;
|
552
|
+
do {
|
553
|
+
memcpy((ora_date_t*)obind->valuep + idx, &julian_day_0, sizeof(ora_date_t));
|
554
|
+
} while (++idx < obind->maxar_sz);
|
555
|
+
}
|
556
|
+
|
557
|
+
static const oci8_bind_vtable_t bind_oradate_vtable = {
|
558
|
+
{
|
559
|
+
NULL,
|
560
|
+
oci8_bind_free,
|
561
|
+
sizeof(oci8_bind_t)
|
562
|
+
},
|
563
|
+
bind_oradate_get,
|
564
|
+
bind_oradate_set,
|
565
|
+
bind_oradate_init,
|
566
|
+
bind_oradate_init_elem,
|
567
|
+
NULL,
|
568
|
+
SQLT_DAT,
|
569
|
+
};
|
570
|
+
|
571
|
+
void Init_ora_date(void)
|
572
|
+
{
|
573
|
+
cOraDate = rb_define_class("OraDate", rb_cObject);
|
574
|
+
|
575
|
+
rb_define_alloc_func(cOraDate, ora_date_s_allocate);
|
576
|
+
rb_define_method(cOraDate, "initialize", ora_date_initialize, -1);
|
577
|
+
rb_define_method(cOraDate, "initialize_copy", ora_date_initialize_copy, 1);
|
578
|
+
rb_define_singleton_method(cOraDate, "now", ora_date_s_now, 0);
|
579
|
+
rb_define_method(cOraDate, "to_s", ora_date_to_s, 0);
|
580
|
+
rb_define_method(cOraDate, "to_a", ora_date_to_a, 0);
|
581
|
+
|
582
|
+
rb_define_method(cOraDate, "year", ora_date_year, 0);
|
583
|
+
rb_define_method(cOraDate, "year=", ora_date_set_year, 1);
|
584
|
+
|
585
|
+
rb_define_method(cOraDate, "month", ora_date_month, 0);
|
586
|
+
rb_define_method(cOraDate, "month=", ora_date_set_month, 1);
|
587
|
+
|
588
|
+
rb_define_method(cOraDate, "day", ora_date_day, 0);
|
589
|
+
rb_define_method(cOraDate, "day=", ora_date_set_day, 1);
|
590
|
+
|
591
|
+
rb_define_method(cOraDate, "hour", ora_date_hour, 0);
|
592
|
+
rb_define_method(cOraDate, "hour=", ora_date_set_hour, 1);
|
593
|
+
|
594
|
+
rb_define_method(cOraDate, "minute", ora_date_minute, 0);
|
595
|
+
rb_define_method(cOraDate, "minute=", ora_date_set_minute, 1);
|
596
|
+
|
597
|
+
rb_define_method(cOraDate, "second", ora_date_second, 0);
|
598
|
+
rb_define_method(cOraDate, "second=", ora_date_set_second, 1);
|
599
|
+
|
600
|
+
rb_define_method(cOraDate, "trunc", ora_date_trunc, 0);
|
601
|
+
|
602
|
+
rb_define_method(cOraDate, "<=>", ora_date_cmp, 1);
|
603
|
+
rb_include_module(cOraDate, rb_mComparable);
|
604
|
+
|
605
|
+
rb_define_method(cOraDate, "hash", ora_date_hash, 0);
|
606
|
+
|
607
|
+
rb_define_method(cOraDate, "_dump", ora_date_dump, -1);
|
608
|
+
rb_define_singleton_method(cOraDate, "_load", ora_date_s_load, 1);
|
609
|
+
|
610
|
+
oci8_define_bind_class("OraDate", &bind_oradate_vtable);
|
611
|
+
}
|