ruby-staci 2.2.9

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.
Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +14 -0
  3. data/COPYING +30 -0
  4. data/COPYING_old +64 -0
  5. data/ChangeLog +3826 -0
  6. data/Makefile +92 -0
  7. data/NEWS +1194 -0
  8. data/README.md +66 -0
  9. data/dist-files +113 -0
  10. data/docs/bind-array-to-in_cond.md +38 -0
  11. data/docs/conflicts-local-connections-and-processes.md +98 -0
  12. data/docs/hanging-after-inactivity.md +63 -0
  13. data/docs/install-binary-package.md +44 -0
  14. data/docs/install-full-client.md +111 -0
  15. data/docs/install-instant-client.md +194 -0
  16. data/docs/install-on-osx.md +133 -0
  17. data/docs/ldap-auth-and-function-interposition.md +123 -0
  18. data/docs/number-type-mapping.md +79 -0
  19. data/docs/osx-install-dev-tools.png +0 -0
  20. data/docs/platform-specific-issues.md +164 -0
  21. data/docs/report-installation-issue.md +50 -0
  22. data/docs/timeout-parameters.md +94 -0
  23. data/ext/oci8/.document +18 -0
  24. data/ext/oci8/MANIFEST +18 -0
  25. data/ext/oci8/apiwrap.c.tmpl +178 -0
  26. data/ext/oci8/apiwrap.h.tmpl +61 -0
  27. data/ext/oci8/apiwrap.rb +96 -0
  28. data/ext/oci8/apiwrap.yml +1322 -0
  29. data/ext/oci8/attr.c +57 -0
  30. data/ext/oci8/bind.c +838 -0
  31. data/ext/oci8/connection_pool.c +216 -0
  32. data/ext/oci8/encoding.c +196 -0
  33. data/ext/oci8/env.c +139 -0
  34. data/ext/oci8/error.c +385 -0
  35. data/ext/oci8/extconf.rb +219 -0
  36. data/ext/oci8/hook_funcs.c +407 -0
  37. data/ext/oci8/lob.c +1278 -0
  38. data/ext/oci8/metadata.c +279 -0
  39. data/ext/oci8/object.c +919 -0
  40. data/ext/oci8/oci8.c +1058 -0
  41. data/ext/oci8/oci8.h +556 -0
  42. data/ext/oci8/oci8lib.c +704 -0
  43. data/ext/oci8/ocidatetime.c +506 -0
  44. data/ext/oci8/ocihandle.c +852 -0
  45. data/ext/oci8/ocinumber.c +1922 -0
  46. data/ext/oci8/oraconf.rb +1145 -0
  47. data/ext/oci8/oradate.c +670 -0
  48. data/ext/oci8/oranumber_util.c +352 -0
  49. data/ext/oci8/oranumber_util.h +24 -0
  50. data/ext/oci8/plthook.h +66 -0
  51. data/ext/oci8/plthook_elf.c +702 -0
  52. data/ext/oci8/plthook_osx.c +505 -0
  53. data/ext/oci8/plthook_win32.c +391 -0
  54. data/ext/oci8/post-config.rb +5 -0
  55. data/ext/oci8/stmt.c +448 -0
  56. data/ext/oci8/thread_util.c +81 -0
  57. data/ext/oci8/thread_util.h +18 -0
  58. data/ext/oci8/util.c +71 -0
  59. data/ext/oci8/win32.c +117 -0
  60. data/lib/.document +1 -0
  61. data/lib/dbd/STACI.rb +591 -0
  62. data/lib/oci8/.document +8 -0
  63. data/lib/oci8/bindtype.rb +333 -0
  64. data/lib/oci8/check_load_error.rb +146 -0
  65. data/lib/oci8/compat.rb +117 -0
  66. data/lib/oci8/connection_pool.rb +179 -0
  67. data/lib/oci8/cursor.rb +605 -0
  68. data/lib/oci8/datetime.rb +605 -0
  69. data/lib/oci8/encoding-init.rb +45 -0
  70. data/lib/oci8/encoding.yml +537 -0
  71. data/lib/oci8/metadata.rb +2148 -0
  72. data/lib/oci8/object.rb +641 -0
  73. data/lib/oci8/oci8.rb +756 -0
  74. data/lib/oci8/ocihandle.rb +591 -0
  75. data/lib/oci8/oracle_version.rb +153 -0
  76. data/lib/oci8/properties.rb +196 -0
  77. data/lib/oci8/version.rb +3 -0
  78. data/lib/ruby-staci.rb +1 -0
  79. data/lib/staci.rb +190 -0
  80. data/metaconfig +142 -0
  81. data/pre-distclean.rb +7 -0
  82. data/ruby-aci.gemspec +83 -0
  83. data/setup.rb +1342 -0
  84. data/test/README.md +37 -0
  85. data/test/config.rb +201 -0
  86. data/test/setup_test_object.sql +199 -0
  87. data/test/setup_test_package.sql +59 -0
  88. data/test/test_all.rb +56 -0
  89. data/test/test_appinfo.rb +62 -0
  90. data/test/test_array_dml.rb +333 -0
  91. data/test/test_bind_array.rb +70 -0
  92. data/test/test_bind_boolean.rb +99 -0
  93. data/test/test_bind_integer.rb +47 -0
  94. data/test/test_bind_raw.rb +45 -0
  95. data/test/test_bind_string.rb +105 -0
  96. data/test/test_bind_time.rb +177 -0
  97. data/test/test_break.rb +124 -0
  98. data/test/test_clob.rb +86 -0
  99. data/test/test_connection_pool.rb +124 -0
  100. data/test/test_connstr.rb +220 -0
  101. data/test/test_datetime.rb +585 -0
  102. data/test/test_dbi.rb +365 -0
  103. data/test/test_dbi_clob.rb +53 -0
  104. data/test/test_encoding.rb +103 -0
  105. data/test/test_error.rb +87 -0
  106. data/test/test_metadata.rb +2674 -0
  107. data/test/test_object.rb +546 -0
  108. data/test/test_oci8.rb +624 -0
  109. data/test/test_oracle_version.rb +68 -0
  110. data/test/test_oradate.rb +255 -0
  111. data/test/test_oranumber.rb +786 -0
  112. data/test/test_package_type.rb +981 -0
  113. data/test/test_properties.rb +17 -0
  114. data/test/test_rowid.rb +32 -0
  115. metadata +158 -0
@@ -0,0 +1,670 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * oradate.c
4
+ *
5
+ * Copyright (C) 2002-2015 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
+ * OraDate is the ruby class compatible with Oracle <tt>DATE</tt> data type.
18
+ * The range is between 4712 B.C. and 9999 A.D.
19
+ */
20
+ struct ora_date {
21
+ unsigned char century;
22
+ unsigned char year;
23
+ unsigned char month;
24
+ unsigned char day;
25
+ unsigned char hour;
26
+ unsigned char minute;
27
+ unsigned char second;
28
+ };
29
+ typedef struct ora_date ora_date_t;
30
+
31
+ #define Set_year(od, y) (od)->century = y / 100 + 100, (od)->year = y % 100 + 100
32
+ #define Set_month(od, m) (od)->month = m
33
+ #define Set_day(od, d) (od)->day = d
34
+ #define Set_hour(od, h) (od)->hour = h + 1
35
+ #define Set_minute(od, m) (od)->minute = m + 1
36
+ #define Set_second(od, s) (od)->second = s + 1
37
+
38
+ #define Get_year(od) (((od)->century - 100) * 100 + ((od)->year - 100))
39
+ #define Get_month(od) ((od)->month)
40
+ #define Get_day(od) ((od)->day)
41
+ #define Get_hour(od) ((od)->hour - 1)
42
+ #define Get_minute(od) ((od)->minute - 1)
43
+ #define Get_second(od) ((od)->second - 1)
44
+
45
+ #define Check_year(year) \
46
+ if (year < -4712 || 9999 < year) \
47
+ rb_raise(rb_eRangeError, "Out of range for year %d (expect -4712 .. 9999)", year)
48
+ #define Check_month(month) \
49
+ if (month < 1 || 12 < month) \
50
+ rb_raise(rb_eRangeError, "Out of range for month %d (expect 1 .. 12)", month)
51
+ #define Check_day(day) \
52
+ if (day < 1 || 31 < day) \
53
+ rb_raise(rb_eRangeError, "Out of range for day %d (expect 1 .. 31)", day)
54
+ #define Check_hour(hour) \
55
+ if (hour < 0 || 23 < hour) \
56
+ rb_raise(rb_eRangeError, "Out of range for hour %d (expect 0 .. 24)", hour)
57
+ #define Check_minute(min) \
58
+ if (min < 0 || 59 < min) \
59
+ rb_raise(rb_eRangeError, "Out of range for minute %d (expect 0 .. 59)", min)
60
+ #define Check_second(sec) \
61
+ if (sec < 0 || 59 < sec) \
62
+ rb_raise(rb_eRangeError, "Out of range for second %d (expect 0 .. 59)", sec)
63
+
64
+ #ifdef HAVE_RB_DATA_TYPE_T_FUNCTION
65
+ #define check_oradate(obj) ((ora_date_t*)Check_TypedStruct((obj), &odate_data_type))
66
+ #else
67
+ static ora_date_t *check_oradate(VALUE obj)
68
+ {
69
+ if (!rb_obj_is_kind_of(obj, cOraDate)) {
70
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
71
+ rb_obj_classname(obj), rb_class2name(cOraDate));
72
+ }
73
+ return DATA_PTR(obj);
74
+ }
75
+ #endif
76
+
77
+ static size_t odate_memsize(const void *ptr)
78
+ {
79
+ return sizeof(ora_date_t);
80
+ }
81
+
82
+ static const rb_data_type_t odate_data_type = {
83
+ "OraDate",
84
+ {NULL, RUBY_DEFAULT_FREE, odate_memsize,},
85
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
86
+ NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
87
+ #endif
88
+ #ifdef RUBY_TYPED_WB_PROTECTED
89
+ | RUBY_TYPED_WB_PROTECTED
90
+ #endif
91
+ };
92
+
93
+ static void oci8_set_ora_date(ora_date_t *od, int year, int month, int day, int hour, int minute, int second)
94
+ {
95
+ Set_year(od, year);
96
+ Set_month(od, month);
97
+ Set_day(od, day);
98
+ Set_hour(od, hour);
99
+ Set_minute(od, minute);
100
+ Set_second(od, second);
101
+ }
102
+
103
+ static VALUE ora_date_s_allocate(VALUE klass)
104
+ {
105
+ ora_date_t *od;
106
+ return TypedData_Make_Struct(klass, ora_date_t, &odate_data_type, od);
107
+ }
108
+
109
+ /*
110
+ * @overload initialize(year = 1, month = 1, day = 1, hour = 0, min = 0, sec = 0)
111
+ *
112
+ * Returns an <code>OraDate</code> object initialized to the specified date and time.
113
+ *
114
+ * @example
115
+ * OraDate.new # => 0001-01-01 00:00:00
116
+ * OraDate.new(2012) # => 2012-01-01 00:00:00
117
+ * OraDate.new(2012, 3, 4) # => 2012-03-04 00:00:00
118
+ *
119
+ * @param [Integer] year year
120
+ * @param [Integer] month month
121
+ * @param [Integer] day day of month
122
+ * @param [Integer] hour hour
123
+ * @param [Integer] min minute
124
+ * @param [Integer] sec second
125
+ */
126
+ static VALUE ora_date_initialize(int argc, VALUE *argv, VALUE self)
127
+ {
128
+ VALUE vyear, vmonth, vday, vhour, vmin, vsec;
129
+ ora_date_t *od = check_oradate(self);
130
+ int year, month, day, hour, min, sec;
131
+
132
+ rb_scan_args(argc, argv, "06", &vyear, &vmonth, &vday, &vhour, &vmin, &vsec);
133
+ /* set year */
134
+ if (argc > 0) {
135
+ year = NUM2INT(vyear);
136
+ Check_year(year);
137
+ } else {
138
+ year = 1;
139
+ }
140
+ /* set month */
141
+ if (argc > 1) {
142
+ month = NUM2INT(vmonth);
143
+ Check_month(month);
144
+ } else {
145
+ month = 1;
146
+ }
147
+ /* set day */
148
+ if (argc > 2) {
149
+ day = NUM2INT(vday);
150
+ Check_day(day);
151
+ } else {
152
+ day = 1;
153
+ }
154
+ /* set hour */
155
+ if (argc > 3) {
156
+ hour = NUM2INT(vhour);
157
+ Check_hour(hour);
158
+ } else {
159
+ hour = 0;
160
+ }
161
+ /* set minute */
162
+ if (argc > 4) {
163
+ min = NUM2INT(vmin);
164
+ Check_minute(min);
165
+ } else {
166
+ min = 0;
167
+ }
168
+ /* set second */
169
+ if (argc > 5) {
170
+ sec = NUM2INT(vsec);
171
+ Check_second(sec);
172
+ } else {
173
+ sec = 0;
174
+ }
175
+
176
+ oci8_set_ora_date(od, year, month, day, hour, min, sec);
177
+ return Qnil;
178
+ }
179
+
180
+ /*
181
+ * @private
182
+ */
183
+ static VALUE ora_date_initialize_copy(VALUE lhs, VALUE rhs)
184
+ {
185
+ ora_date_t *l = check_oradate(lhs);
186
+ ora_date_t *r = check_oradate(rhs);
187
+
188
+ rb_call_super(1, &rhs);
189
+ memcpy(l, r, sizeof(ora_date_t));
190
+ return lhs;
191
+ }
192
+
193
+ /*
194
+ * @overload now
195
+ *
196
+ * Returns an <code>OraDate</code> object initialized to the
197
+ * current local time.
198
+ *
199
+ * @return [OraDate]
200
+ */
201
+ static VALUE ora_date_s_now(VALUE klass)
202
+ {
203
+ VALUE obj = ora_date_s_allocate(klass);
204
+ ora_date_t *od = check_oradate(obj);
205
+ time_t tm = time(0);
206
+ int year, month, day, hour, min, sec;
207
+ #ifdef HAVE_LOCALTIME_R
208
+ struct tm t;
209
+ localtime_r(&tm, &t);
210
+ #define tp (&t)
211
+ #else
212
+ struct tm *tp;
213
+ tp = localtime(&tm);
214
+ #endif
215
+ year = tp->tm_year + 1900;
216
+ month = tp->tm_mon + 1;
217
+ day = tp->tm_mday;
218
+ hour = tp->tm_hour;
219
+ min = tp->tm_min;
220
+ sec = tp->tm_sec;
221
+
222
+ oci8_set_ora_date(od, year, month, day, hour, min, sec);
223
+ return obj;
224
+ }
225
+
226
+ /*
227
+ * @overload to_s
228
+ *
229
+ * Returns a string representing <i>self</i>.
230
+ * The string format is 'yyyy/mm/dd hh:mi:ss'.
231
+ *
232
+ * @return [OraDate]
233
+ */
234
+ static VALUE ora_date_to_s(VALUE self)
235
+ {
236
+ ora_date_t *od = check_oradate(self);
237
+ char buf[30];
238
+
239
+ sprintf(buf, "%04d/%02d/%02d %02d:%02d:%02d", Get_year(od), Get_month(od),
240
+ Get_day(od), Get_hour(od), Get_minute(od), Get_second(od));
241
+ return rb_usascii_str_new_cstr(buf);
242
+ }
243
+
244
+ /*
245
+ * @overload to_a
246
+ *
247
+ * Returns a 6-element <i>array</i> of year, month, day, hour, minute and second.
248
+ *
249
+ * @return [Array]
250
+ */
251
+ static VALUE ora_date_to_a(VALUE self)
252
+ {
253
+ ora_date_t *od = check_oradate(self);
254
+ VALUE ary[6];
255
+
256
+ ary[0] = INT2FIX(Get_year(od));
257
+ ary[1] = INT2FIX(Get_month(od));
258
+ ary[2] = INT2FIX(Get_day(od));
259
+ ary[3] = INT2FIX(Get_hour(od));
260
+ ary[4] = INT2FIX(Get_minute(od));
261
+ ary[5] = INT2FIX(Get_second(od));
262
+ return rb_ary_new4(6, ary);
263
+ }
264
+
265
+ /*
266
+ * @overload year
267
+ *
268
+ * Returns the year field of <i>self</i>.
269
+ *
270
+ * @return [Integer]
271
+ */
272
+ static VALUE ora_date_year(VALUE self)
273
+ {
274
+ ora_date_t *od = check_oradate(self);
275
+
276
+ return INT2FIX(Get_year(od));
277
+ }
278
+
279
+ /*
280
+ * @overload year=num
281
+ *
282
+ * Assigns <i>num</i> to the year field of <i>self</i>.
283
+ *
284
+ * @param [Integer] num number between -4712 and 9999
285
+ */
286
+ static VALUE ora_date_set_year(VALUE self, VALUE val)
287
+ {
288
+ ora_date_t *od = check_oradate(self);
289
+ int v = NUM2INT(val);
290
+
291
+ Check_year(v);
292
+ Set_year(od, v);
293
+ return self;
294
+ }
295
+
296
+ /*
297
+ * @overload month
298
+ *
299
+ * Returns the month field of <i>self</i>.
300
+ * The month starts with one.
301
+ *
302
+ * @return [Integer]
303
+ */
304
+ static VALUE ora_date_month(VALUE self)
305
+ {
306
+ ora_date_t *od = check_oradate(self);
307
+
308
+ return INT2FIX(Get_month(od));
309
+ }
310
+
311
+ /*
312
+ * @overload month=num
313
+ *
314
+ * Assigns <i>num</i> to the month field of <i>self</i>.
315
+ * The month starts with one.
316
+ *
317
+ * @param [Integer] num number between 1 and 12
318
+ */
319
+ static VALUE ora_date_set_month(VALUE self, VALUE val)
320
+ {
321
+ ora_date_t *od = check_oradate(self);
322
+ int v = NUM2INT(val);
323
+
324
+ Check_month(v);
325
+ Set_month(od, v);
326
+ return self;
327
+ }
328
+
329
+ /*
330
+ * @overload day
331
+ *
332
+ * Returns the day of month field of <i>self</i>.
333
+ *
334
+ * @return [Integer]
335
+ */
336
+ static VALUE ora_date_day(VALUE self)
337
+ {
338
+ ora_date_t *od = check_oradate(self);
339
+
340
+ return INT2FIX(Get_day(od));
341
+ }
342
+
343
+ /*
344
+ * @overload day=num
345
+ *
346
+ * Assigns <i>num</i> to the day of month field of <i>self</i>.
347
+ *
348
+ * @param [Integer] num number between 1 and 31
349
+ */
350
+ static VALUE ora_date_set_day(VALUE self, VALUE val)
351
+ {
352
+ ora_date_t *od = check_oradate(self);
353
+ int v = NUM2INT(val);
354
+
355
+ Check_day(v);
356
+ Set_day(od, v);
357
+ return self;
358
+ }
359
+
360
+ /*
361
+ * @overload hour
362
+ *
363
+ * Returns the hour field of <i>self</i>.
364
+ *
365
+ * @return [Integer]
366
+ */
367
+ static VALUE ora_date_hour(VALUE self)
368
+ {
369
+ ora_date_t *od = check_oradate(self);
370
+
371
+ return INT2FIX(Get_hour(od));
372
+ }
373
+
374
+ /*
375
+ * @overload hour=num
376
+ *
377
+ * Assigns <i>num</i> to the hour field of <i>self</i>.
378
+ *
379
+ * @param [Integer] num number between 0 and 23
380
+ */
381
+ static VALUE ora_date_set_hour(VALUE self, VALUE val)
382
+ {
383
+ ora_date_t *od = check_oradate(self);
384
+ int v = NUM2INT(val);
385
+
386
+ Check_hour(v);
387
+ Set_hour(od, v);
388
+ return self;
389
+ }
390
+
391
+ /*
392
+ * @overload minute
393
+ *
394
+ * Returns the minute field of <i>self</i>.
395
+ *
396
+ * @return [Integer]
397
+ */
398
+ static VALUE ora_date_minute(VALUE self)
399
+ {
400
+ ora_date_t *od = check_oradate(self);
401
+
402
+ return INT2FIX(Get_minute(od));
403
+ }
404
+
405
+ /*
406
+ * @overload minute=num
407
+ *
408
+ * Assigns <i>num</i> to the minute field of <i>self</i>.
409
+ *
410
+ * @param [Integer] num number between 0 and 59
411
+ */
412
+ static VALUE ora_date_set_minute(VALUE self, VALUE val)
413
+ {
414
+ ora_date_t *od = check_oradate(self);
415
+ int v = NUM2INT(val);
416
+
417
+ Check_minute(v);
418
+ Set_minute(od, v);
419
+ return self;
420
+ }
421
+
422
+ /*
423
+ * @overload second
424
+ *
425
+ * Returns the second field of <i>self</i>.
426
+ *
427
+ * @return [Integer]
428
+ */
429
+ static VALUE ora_date_second(VALUE self)
430
+ {
431
+ ora_date_t *od = check_oradate(self);
432
+
433
+ return INT2FIX(Get_second(od));
434
+ }
435
+
436
+ /*
437
+ * @overload second=num
438
+ *
439
+ * Assigns <i>num</i> to the second field of <i>self</i>.
440
+ *
441
+ * @param [Integer] num number between 0 and 59
442
+ */
443
+ static VALUE ora_date_set_second(VALUE self, VALUE val)
444
+ {
445
+ ora_date_t *od = check_oradate(self);
446
+ int v;
447
+
448
+ v = NUM2INT(val);
449
+ Check_second(v);
450
+ Set_second(od, v);
451
+ return self;
452
+ }
453
+
454
+ /*
455
+ * @overload trunc
456
+ *
457
+ * Truncates hour, minute and second fields to zero.
458
+ *
459
+ * @example
460
+ * oradate = OraDate.now # => 2008/07/17 11:07:30
461
+ * oradate.trunc # => 2008/07/17 00:00:00
462
+ *
463
+ * @return [OraDate]
464
+ */
465
+ static VALUE ora_date_trunc(VALUE self)
466
+ {
467
+ ora_date_t *od = check_oradate(self);
468
+
469
+ od->hour = 1;
470
+ od->minute = 1;
471
+ od->second = 1;
472
+ return self;
473
+ }
474
+
475
+ /*
476
+ * @overload <=>(other)
477
+ *
478
+ * Returns -1, 0, or +1 depending on whether <i>self</i> is less than,
479
+ * equal to, or greater than <i>other</i>.
480
+ *
481
+ * @return [-1, 0, +1]
482
+ */
483
+ static VALUE ora_date_cmp(VALUE self, VALUE val)
484
+ {
485
+ ora_date_t *od1 = check_oradate(self);
486
+ ora_date_t *od2 = check_oradate(val);
487
+
488
+ if (od1->century < od2->century) return INT2FIX(-1);
489
+ if (od1->century > od2->century) return INT2FIX(1);
490
+ if (od1->year < od2->year) return INT2FIX(-1);
491
+ if (od1->year > od2->year) return INT2FIX(1);
492
+ if (od1->month < od2->month) return INT2FIX(-1);
493
+ if (od1->month > od2->month) return INT2FIX(1);
494
+ if (od1->day < od2->day) return INT2FIX(-1);
495
+ if (od1->day > od2->day) return INT2FIX(1);
496
+ if (od1->hour < od2->hour) return INT2FIX(-1);
497
+ if (od1->hour > od2->hour) return INT2FIX(1);
498
+ if (od1->minute < od2->minute) return INT2FIX(-1);
499
+ if (od1->minute > od2->minute) return INT2FIX(1);
500
+ if (od1->second < od2->second) return INT2FIX(-1);
501
+ if (od1->second > od2->second) return INT2FIX(1);
502
+ return INT2FIX(0);
503
+ }
504
+
505
+ /*
506
+ * @private
507
+ */
508
+ static VALUE ora_date_hash(VALUE self)
509
+ {
510
+ ora_date_t *od = check_oradate(self);
511
+ unsigned int v;
512
+
513
+ v = (od->century << 8)
514
+ + (od->year << 15)
515
+ + (od->month << 22)
516
+ + (od->day << 26)
517
+ + (od->hour << 12)
518
+ + (od->minute << 6)
519
+ + (od->second << 0);
520
+ return INT2FIX(v);
521
+ }
522
+
523
+ /*
524
+ * @overload _dump
525
+ *
526
+ * Serializes <i>self</i>.
527
+ * This method is called by Marshal.dump().
528
+ *
529
+ * @return [String] a byte stream
530
+ * @see OraDate._load
531
+ */
532
+ static VALUE ora_date_dump(int argc, VALUE *argv, VALUE self)
533
+ {
534
+ ora_date_t *od = check_oradate(self);
535
+
536
+ return rb_str_new((const char*)od, sizeof(ora_date_t)); /* ASCII-8BIT */
537
+ }
538
+
539
+ /*
540
+ * @overload _load(bytes)
541
+ *
542
+ * Restores a byte stream serialized by {OraDate#_dump}.
543
+ * This method is called by Marshal.load() to deserialize a byte stream
544
+ * created by Marshal.dump().
545
+ *
546
+ * @param [String] bytes a byte stream
547
+ * @return [OraDate] an deserialized object
548
+ */
549
+ static VALUE ora_date_s_load(VALUE klass, VALUE str)
550
+ {
551
+ ora_date_t *od;
552
+ VALUE obj;
553
+
554
+ Check_Type(str, T_STRING);
555
+ if (RSTRING_LEN(str) != sizeof(ora_date_t)) {
556
+ rb_raise(rb_eTypeError, "marshaled OraDate format differ");
557
+ }
558
+ obj = TypedData_Make_Struct(cOraDate, ora_date_t, &odate_data_type, od);
559
+ memcpy(od, RSTRING_PTR(str), sizeof(ora_date_t));
560
+ return obj;
561
+ }
562
+
563
+ /*
564
+ * Document-class: OCI8::BindType::OraDate
565
+ *
566
+ * This is a helper class to bind OraDate as Oracle's <tt>DATE</tt> datatype.
567
+ *
568
+ */
569
+ static VALUE bind_oradate_get(oci8_bind_t *obind, void *data, void *null_struct)
570
+ {
571
+ ora_date_t *od;
572
+
573
+ VALUE obj = TypedData_Make_Struct(cOraDate, ora_date_t, &odate_data_type, od);
574
+ memcpy(od, data, sizeof(ora_date_t));
575
+ return obj;
576
+ }
577
+
578
+ static void bind_oradate_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val)
579
+ {
580
+ ora_date_t *od = check_oradate(val);
581
+
582
+ memcpy(data, od, sizeof(ora_date_t));
583
+ }
584
+
585
+ static void bind_oradate_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
586
+ {
587
+ obind->value_sz = sizeof(ora_date_t);
588
+ obind->alloc_sz = sizeof(ora_date_t);
589
+ }
590
+
591
+ static void bind_oradate_init_elem(oci8_bind_t *obind, VALUE svc)
592
+ {
593
+ static const ora_date_t julian_day_0 = {100-47, 100-12, 1, 1, 1, 1, 1};
594
+ ub4 idx = 0;
595
+ do {
596
+ memcpy((ora_date_t*)obind->valuep + idx, &julian_day_0, sizeof(ora_date_t));
597
+ } while (++idx < obind->maxar_sz);
598
+ }
599
+
600
+ static const oci8_bind_data_type_t bind_oradate_data_type = {
601
+ {
602
+ {
603
+ "STACI::BindType::OraDate",
604
+ {
605
+ NULL,
606
+ oci8_handle_cleanup,
607
+ oci8_handle_size,
608
+ },
609
+ &oci8_bind_data_type.rb_data_type, NULL,
610
+ #ifdef RUBY_TYPED_WB_PROTECTED
611
+ RUBY_TYPED_WB_PROTECTED,
612
+ #endif
613
+ },
614
+ oci8_bind_free,
615
+ sizeof(oci8_bind_t)
616
+ },
617
+ bind_oradate_get,
618
+ bind_oradate_set,
619
+ bind_oradate_init,
620
+ bind_oradate_init_elem,
621
+ NULL,
622
+ SQLT_DAT,
623
+ };
624
+
625
+ static VALUE bind_oradate_alloc(VALUE klass)
626
+ {
627
+ return oci8_allocate_typeddata(klass, &bind_oradate_data_type.base);
628
+ }
629
+
630
+ void Init_ora_date(void)
631
+ {
632
+ cOraDate = rb_define_class("OraDate", rb_cObject);
633
+
634
+ rb_define_alloc_func(cOraDate, ora_date_s_allocate);
635
+ rb_define_method(cOraDate, "initialize", ora_date_initialize, -1);
636
+ rb_define_method(cOraDate, "initialize_copy", ora_date_initialize_copy, 1);
637
+ rb_define_singleton_method(cOraDate, "now", ora_date_s_now, 0);
638
+ rb_define_method(cOraDate, "to_s", ora_date_to_s, 0);
639
+ rb_define_method(cOraDate, "to_a", ora_date_to_a, 0);
640
+
641
+ rb_define_method(cOraDate, "year", ora_date_year, 0);
642
+ rb_define_method(cOraDate, "year=", ora_date_set_year, 1);
643
+
644
+ rb_define_method(cOraDate, "month", ora_date_month, 0);
645
+ rb_define_method(cOraDate, "month=", ora_date_set_month, 1);
646
+
647
+ rb_define_method(cOraDate, "day", ora_date_day, 0);
648
+ rb_define_method(cOraDate, "day=", ora_date_set_day, 1);
649
+
650
+ rb_define_method(cOraDate, "hour", ora_date_hour, 0);
651
+ rb_define_method(cOraDate, "hour=", ora_date_set_hour, 1);
652
+
653
+ rb_define_method(cOraDate, "minute", ora_date_minute, 0);
654
+ rb_define_method(cOraDate, "minute=", ora_date_set_minute, 1);
655
+
656
+ rb_define_method(cOraDate, "second", ora_date_second, 0);
657
+ rb_define_method(cOraDate, "second=", ora_date_set_second, 1);
658
+
659
+ rb_define_method(cOraDate, "trunc", ora_date_trunc, 0);
660
+
661
+ rb_define_method(cOraDate, "<=>", ora_date_cmp, 1);
662
+ rb_include_module(cOraDate, rb_mComparable);
663
+
664
+ rb_define_method(cOraDate, "hash", ora_date_hash, 0);
665
+
666
+ rb_define_method(cOraDate, "_dump", ora_date_dump, -1);
667
+ rb_define_singleton_method(cOraDate, "_load", ora_date_s_load, 1);
668
+
669
+ oci8_define_bind_class("OraDate", &bind_oradate_data_type, bind_oradate_alloc);
670
+ }