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,852 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * ocihandle.c
4
+ *
5
+ * Copyright (C) 2009-2015 Kubo Takehiro <kubo@jiubao.org>
6
+ *
7
+ * implement OCIHandle
8
+ *
9
+ */
10
+ #include "oci8.h"
11
+
12
+ #define TO_HANDLE(obj) ((oci8_base_t*)oci8_check_typeddata((obj), &oci8_handle_data_type, 1))
13
+
14
+ #ifdef _MSC_VER
15
+ #define MAGIC_NUMBER 0xDEAFBEAFDEAFBEAFui64;
16
+ #else
17
+ #define MAGIC_NUMBER 0xDEAFBEAFDEAFBEAFull;
18
+ #endif
19
+
20
+ static long check_data_range(VALUE val, long min, long max, const char *type)
21
+ {
22
+ long lval = NUM2LONG(val);
23
+ if (lval < min || max < lval) {
24
+ rb_raise(rb_eRangeError, "integer %ld too %s to convert to `%s'",
25
+ lval, lval < 0 ? "small" : "big", type);
26
+ }
27
+ return lval;
28
+ }
29
+
30
+ const oci8_handle_data_type_t oci8_handle_data_type = {
31
+ {
32
+ "OCIHandle",
33
+ {
34
+ NULL,
35
+ oci8_handle_cleanup,
36
+ oci8_handle_size,
37
+ },
38
+ NULL, NULL,
39
+ #ifdef RUBY_TYPED_WB_PROTECTED
40
+ RUBY_TYPED_WB_PROTECTED,
41
+ #endif
42
+ },
43
+ NULL,
44
+ sizeof(oci8_base_t),
45
+ };
46
+
47
+ static VALUE oci8_handle_initialize(VALUE self)
48
+ {
49
+ rb_raise(rb_eNameError, "private method `new' called for %s:Class", rb_class2name(CLASS_OF(self)));
50
+ }
51
+
52
+ /*
53
+ * Clears the object internal structure and its dependents.
54
+ *
55
+ * @since 2.0.0
56
+ * @private
57
+ */
58
+ static VALUE oci8_handle_free(VALUE self)
59
+ {
60
+ oci8_base_t *base = DATA_PTR(self);
61
+
62
+ oci8_base_free(base);
63
+ return self;
64
+ }
65
+
66
+ void oci8_handle_cleanup(void *ptr)
67
+ {
68
+ oci8_base_t *base = (oci8_base_t *)ptr;
69
+ if (oci8_in_finalizer) {
70
+ /* Do nothing when the program exits.
71
+ * The first two words of memory addressed by VALUE datatype is
72
+ * changed in finalizer. If a ruby function which access it such
73
+ * as rb_obj_is_kind_of is called, it may cause SEGV.
74
+ */
75
+ return;
76
+ }
77
+ oci8_base_free(base);
78
+ xfree(base);
79
+ }
80
+
81
+ size_t oci8_handle_size(const void *ptr)
82
+ {
83
+ const oci8_base_t *base = (const oci8_base_t *)ptr;
84
+ const oci8_bind_t *bind = (const oci8_bind_t *)ptr;
85
+ size_t size = base->data_type->size;
86
+
87
+ if (base->hp.ptr != NULL) {
88
+ size += 256; /* I don't know the real size. Use 256 for now. */
89
+ }
90
+ switch (base->type) {
91
+ case OCI_HTYPE_DEFINE:
92
+ case OCI_HTYPE_BIND:
93
+ size += bind->alloc_sz * (bind->maxar_sz ? bind->maxar_sz : 1);
94
+ }
95
+ return size;
96
+ }
97
+
98
+ static VALUE oci8_s_allocate(VALUE klass)
99
+ {
100
+ return oci8_allocate_typeddata(klass, &oci8_handle_data_type);
101
+ }
102
+
103
+ VALUE oci8_allocate_typeddata(VALUE klass, const oci8_handle_data_type_t *data_type)
104
+ {
105
+ oci8_base_t *base;
106
+ VALUE obj;
107
+
108
+ base = xmalloc(data_type->size);
109
+ memset(base, 0, data_type->size);
110
+
111
+ obj = TypedData_Wrap_Struct(klass, &data_type->rb_data_type, base);
112
+ base->self = obj;
113
+ base->data_type = data_type;
114
+ base->parent = NULL;
115
+ base->next = base;
116
+ base->prev = base;
117
+ base->children = NULL;
118
+ return obj;
119
+ }
120
+
121
+ enum datatype {
122
+ DATATYPE_UB1,
123
+ DATATYPE_UB2,
124
+ DATATYPE_UB4,
125
+ DATATYPE_UB8,
126
+ DATATYPE_SB1,
127
+ DATATYPE_SB2,
128
+ DATATYPE_SB4,
129
+ DATATYPE_SB8,
130
+ DATATYPE_BOOLEAN,
131
+ DATATYPE_STRING,
132
+ DATATYPE_BINARY,
133
+ DATATYPE_INTEGER,
134
+ DATATYPE_ORADATE,
135
+ };
136
+
137
+ static VALUE attr_get_common(int argc, VALUE *argv, VALUE self, enum datatype datatype)
138
+ {
139
+ oci8_base_t *base = oci8_check_typeddata(self, &oci8_handle_data_type, 0);
140
+ VALUE attr_type;
141
+ VALUE strict;
142
+ VALUE args[6];
143
+ union {
144
+ ub1 ub1val;
145
+ ub2 ub2val;
146
+ ub4 ub4val;
147
+ ub8 ub8val;
148
+ sb1 sb1val;
149
+ sb2 sb2val;
150
+ sb4 sb4val;
151
+ sb8 sb8val;
152
+ boolean booleanval;
153
+ char *charptr;
154
+ ub1 *ub1ptr;
155
+ } v;
156
+ ub4 size = 0;
157
+ sword rv;
158
+
159
+ if (base->closed) {
160
+ /* Returns nil when the backtrace includes `inspect'.
161
+ * Otherwise, raises an exception.
162
+ * IMO, `inspect' should not raise an exception.
163
+ */
164
+ volatile VALUE backtrace = rb_funcall(rb_cObject, rb_intern("caller"), 0);
165
+ if (TYPE(backtrace) == T_ARRAY) {
166
+ int i;
167
+ for (i = 0; i < RARRAY_LEN(backtrace); i++) {
168
+ volatile VALUE elem = RARRAY_AREF(backtrace, i);
169
+ char *s = StringValueCStr(elem);
170
+ if (strstr(s, "inspect") != NULL) {
171
+ return Qnil;
172
+ }
173
+ }
174
+ }
175
+ /* check again just to raise an exception. */
176
+ oci8_check_typeddata(self, &oci8_handle_data_type, 1);
177
+ }
178
+
179
+ v.ub8val = MAGIC_NUMBER;
180
+ rb_scan_args(argc, argv, "11", &attr_type, &strict);
181
+ if (argc == 1) {
182
+ strict = Qtrue;
183
+ }
184
+ Check_Type(attr_type, T_FIXNUM);
185
+ rv = OCIAttrGet(base->hp.ptr, base->type, &v, &size, FIX2INT(attr_type), oci8_errhp);
186
+ if (!RTEST(strict)) {
187
+ if (rv == OCI_ERROR && oci8_get_error_code(oci8_errhp) == 24328) {
188
+ /* ignore ORA-24328: illegal attribute value */
189
+ return Qnil;
190
+ }
191
+ }
192
+ chker2(rv, base);
193
+ switch (datatype) {
194
+ OCINumber onum;
195
+ static VALUE cOraDate = Qnil;
196
+ case DATATYPE_UB1:
197
+ return INT2FIX(v.ub1val);
198
+ case DATATYPE_UB2:
199
+ return INT2FIX(v.ub2val);
200
+ case DATATYPE_UB4:
201
+ return UINT2NUM(v.ub4val);
202
+ case DATATYPE_UB8:
203
+ return ULL2NUM(v.ub8val);
204
+ case DATATYPE_SB1:
205
+ return INT2FIX(v.sb1val);
206
+ case DATATYPE_SB2:
207
+ return INT2FIX(v.sb2val);
208
+ case DATATYPE_SB4:
209
+ return INT2NUM(v.sb4val);
210
+ case DATATYPE_SB8:
211
+ return LL2NUM(v.sb8val);
212
+ case DATATYPE_BOOLEAN:
213
+ return v.booleanval ? Qtrue : Qfalse;
214
+ case DATATYPE_STRING:
215
+ if (size == 0 && !RTEST(strict)) {
216
+ return Qnil;
217
+ }
218
+ return rb_external_str_new_with_enc(v.charptr, size, oci8_encoding);
219
+ case DATATYPE_BINARY:
220
+ return rb_tainted_str_new(v.charptr, size);
221
+ case DATATYPE_INTEGER:
222
+ if (size > sizeof(onum.OCINumberPart) - 1) {
223
+ rb_raise(rb_eRuntimeError, "Too long size %u", size);
224
+ }
225
+ memset(&onum, 0, sizeof(onum));
226
+ onum.OCINumberPart[0] = size;
227
+ memcpy(&onum.OCINumberPart[1], v.ub1ptr, size);
228
+ return oci8_make_integer(&onum, oci8_errhp);
229
+ case DATATYPE_ORADATE:
230
+ if (NIL_P(cOraDate))
231
+ cOraDate = rb_eval_string("OraDate");
232
+ args[0] = INT2FIX((v.ub1ptr[0] - 100) * 100 + (v.ub1ptr[1] - 100));
233
+ args[1] = INT2FIX(v.ub1ptr[2]);
234
+ args[2] = INT2FIX(v.ub1ptr[3]);
235
+ args[3] = INT2FIX(v.ub1ptr[4] - 1);
236
+ args[4] = INT2FIX(v.ub1ptr[5] - 1);
237
+ args[5] = INT2FIX(v.ub1ptr[6] - 1);
238
+ return rb_class_new_instance(6, args, cOraDate);
239
+ }
240
+ return Qnil;
241
+ }
242
+
243
+ /*
244
+ * @overload attr_get_ub1(attr_type, strict = true)
245
+ *
246
+ * Gets the value of an attribute as `ub1' datatype.
247
+ *
248
+ * @param [Integer] attr_type
249
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
250
+ * @return [Integer]
251
+ *
252
+ * @since 2.0.4
253
+ * @private
254
+ */
255
+ static VALUE attr_get_ub1(int argc, VALUE *argv, VALUE self)
256
+ {
257
+ return attr_get_common(argc, argv, self, DATATYPE_UB1);
258
+ }
259
+
260
+ /*
261
+ * @overload attr_get_ub2(attr_type, strict = true)
262
+ *
263
+ * Gets the value of an attribute as `ub2' datatype.
264
+ *
265
+ * @param [Integer] attr_type
266
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
267
+ * @return [Integer]
268
+ *
269
+ * @since 2.0.4
270
+ * @private
271
+ */
272
+ static VALUE attr_get_ub2(int argc, VALUE *argv, VALUE self)
273
+ {
274
+ return attr_get_common(argc, argv, self, DATATYPE_UB2);
275
+ }
276
+
277
+ /*
278
+ * @overload attr_get_ub4(attr_type, strict = true)
279
+ *
280
+ * Gets the value of an attribute as `ub4' datatype.
281
+ *
282
+ * @param [Integer] attr_type
283
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
284
+ * @return [Integer]
285
+ *
286
+ * @since 2.0.4
287
+ * @private
288
+ */
289
+ static VALUE attr_get_ub4(int argc, VALUE *argv, VALUE self)
290
+ {
291
+ return attr_get_common(argc, argv, self, DATATYPE_UB4);
292
+ }
293
+
294
+ /*
295
+ * @overload attr_get_ub8(attr_type, strict = true)
296
+ *
297
+ * Gets the value of an attribute as `ub8' datatype.
298
+ *
299
+ * @param [Integer] attr_type
300
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
301
+ * @return [Integer]
302
+ *
303
+ * @since 2.0.4
304
+ * @private
305
+ */
306
+ static VALUE attr_get_ub8(int argc, VALUE *argv, VALUE self)
307
+ {
308
+ return attr_get_common(argc, argv, self, DATATYPE_UB8);
309
+ }
310
+
311
+ /*
312
+ * @overload attr_get_sb1(attr_type, strict = true)
313
+ *
314
+ * Gets the value of an attribute as `sb1' datatype.
315
+ *
316
+ * @param [Integer] attr_type
317
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
318
+ * @return [Integer]
319
+ *
320
+ * @since 2.0.4
321
+ * @private
322
+ */
323
+ static VALUE attr_get_sb1(int argc, VALUE *argv, VALUE self)
324
+ {
325
+ return attr_get_common(argc, argv, self, DATATYPE_SB1);
326
+ }
327
+
328
+ /*
329
+ * @overload attr_get_sb2(attr_type, strict = true)
330
+ *
331
+ * Gets the value of an attribute as `sb2' datatype.
332
+ *
333
+ * @param [Integer] attr_type
334
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
335
+ * @return [Integer]
336
+ *
337
+ * @since 2.0.4
338
+ * @private
339
+ */
340
+ static VALUE attr_get_sb2(int argc, VALUE *argv, VALUE self)
341
+ {
342
+ return attr_get_common(argc, argv, self, DATATYPE_SB2);
343
+ }
344
+
345
+ /*
346
+ * @overload attr_get_sb4(attr_type, strict = true)
347
+ *
348
+ * Gets the value of an attribute as `sb4' datatype.
349
+ *
350
+ * @param [Integer] attr_type
351
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
352
+ * @return [Integer]
353
+ *
354
+ * @since 2.0.4
355
+ * @private
356
+ */
357
+ static VALUE attr_get_sb4(int argc, VALUE *argv, VALUE self)
358
+ {
359
+ return attr_get_common(argc, argv, self, DATATYPE_SB4);
360
+ }
361
+
362
+ /*
363
+ * @overload attr_get_sb8(attr_type, strict = true)
364
+ *
365
+ * Gets the value of an attribute as `sb8' datatype.
366
+ *
367
+ * @param [Integer] attr_type
368
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
369
+ * @return [Integer]
370
+ *
371
+ * @since 2.0.4
372
+ * @private
373
+ */
374
+ static VALUE attr_get_sb8(int argc, VALUE *argv, VALUE self)
375
+ {
376
+ return attr_get_common(argc, argv, self, DATATYPE_SB8);
377
+ }
378
+
379
+ /*
380
+ * @overload attr_get_boolean(attr_type, strict = true)
381
+ *
382
+ * Gets the value of an attribute as `boolean' datatype.
383
+ *
384
+ * @param [Integer] attr_type
385
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
386
+ * @return [true of false]
387
+ *
388
+ * @since 2.0.4
389
+ * @private
390
+ */
391
+ static VALUE attr_get_boolean(int argc, VALUE *argv, VALUE self)
392
+ {
393
+ return attr_get_common(argc, argv, self, DATATYPE_BOOLEAN);
394
+ }
395
+
396
+ /*
397
+ * @overload attr_get_string(attr_type, strict = true)
398
+ *
399
+ * Gets the value of an attribute as `oratext *' datatype.
400
+ * The return value is converted to Encoding.default_internal or
401
+ * tagged with {STACI.encoding} when the ruby version is 1.9.
402
+ *
403
+ * @note If the specified attr_type's datatype is not a
404
+ * pointer type, it causes a segmentation fault.
405
+ *
406
+ * @param [Integer] attr_type
407
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
408
+ * @return [String]
409
+ *
410
+ * @since 2.0.4
411
+ * @private
412
+ */
413
+ static VALUE attr_get_string(int argc, VALUE *argv, VALUE self)
414
+ {
415
+ return attr_get_common(argc, argv, self, DATATYPE_STRING);
416
+ }
417
+
418
+ /*
419
+ * @overload attr_get_binary(attr_type, strict = true)
420
+ *
421
+ * Gets the value of an attribute as `ub1 *' datatype.
422
+ * The return value is tagged with ASCII-8BIT when the ruby version is 1.9.
423
+ *
424
+ * @note If the specified attr_type's datatype is not a
425
+ * pointer type, it causes a segmentation fault.
426
+ *
427
+ * @param [Integer] attr_type
428
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
429
+ * @return [String]
430
+ *
431
+ * @since 2.0.4
432
+ * @private
433
+ */
434
+ static VALUE attr_get_binary(int argc, VALUE *argv, VALUE self)
435
+ {
436
+ return attr_get_common(argc, argv, self, DATATYPE_BINARY);
437
+ }
438
+
439
+ /*
440
+ * @overload attr_get_integer(attr_type, strict = true)
441
+ *
442
+ * Gets the value of an attribute as `ub1 *' datatype.
443
+ * The return value is converted to Integer from internal Oracle NUMBER format.
444
+ *
445
+ * @note If the specified attr_type's datatype is not a
446
+ * pointer type, it causes a segmentation fault.
447
+ *
448
+ * @param [Integer] attr_type
449
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
450
+ * @return [Integer]
451
+ *
452
+ * @since 2.0.4
453
+ * @private
454
+ */
455
+ static VALUE attr_get_integer(int argc, VALUE *argv, VALUE self)
456
+ {
457
+ return attr_get_common(argc, argv, self, DATATYPE_INTEGER);
458
+ }
459
+
460
+ /*
461
+ * @overload attr_get_oradate(attr_type, strict = true)
462
+ *
463
+ * Gets the value of an attribute as `ub1 *' datatype.
464
+ * The return value is converted to OraDate.
465
+ *
466
+ * @note If the specified attr_type's datatype is not a
467
+ * pointer type, it causes a segmentation fault.
468
+ *
469
+ * @param [Integer] attr_type
470
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
471
+ * @return [OraDate]
472
+ *
473
+ * @since 2.0.4
474
+ * @private
475
+ */
476
+ static VALUE attr_get_oradate(int argc, VALUE *argv, VALUE self)
477
+ {
478
+ return attr_get_common(argc, argv, self, DATATYPE_ORADATE);
479
+ }
480
+
481
+ /*
482
+ * @overload attr_set_ub1(attr_type, attr_value)
483
+ *
484
+ * Sets the value of an attribute as `ub1' datatype.
485
+ *
486
+ * @note If the specified attr_type's datatype is a
487
+ * pointer type, it causes a segmentation fault.
488
+ *
489
+ * @param [Integer] attr_type
490
+ * @param [Integer] attr_value
491
+ * @return [self]
492
+ *
493
+ * @since 2.0.4
494
+ * @private
495
+ */
496
+ static VALUE attr_set_ub1(VALUE self, VALUE attr_type, VALUE val)
497
+ {
498
+ oci8_base_t *base = TO_HANDLE(self);
499
+ ub1 value;
500
+
501
+ /* validate arguments */
502
+ Check_Type(attr_type, T_FIXNUM);
503
+ value = (ub1)check_data_range(val, 0, UCHAR_MAX, "ub1");
504
+ /* set attribute */
505
+ chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
506
+ return self;
507
+ }
508
+
509
+ /*
510
+ * @overload attr_set_ub2(attr_type, attr_value)
511
+ *
512
+ * Sets the value of an attribute as `ub2' datatype.
513
+ *
514
+ * @note If the specified attr_type's datatype is a
515
+ * pointer type, it causes a segmentation fault.
516
+ *
517
+ * @param [Integer] attr_type
518
+ * @param [Integer] attr_value
519
+ * @return [self]
520
+ *
521
+ * @since 2.0.4
522
+ * @private
523
+ */
524
+ static VALUE attr_set_ub2(VALUE self, VALUE attr_type, VALUE val)
525
+ {
526
+ oci8_base_t *base = TO_HANDLE(self);
527
+ ub2 value;
528
+
529
+ /* validate arguments */
530
+ Check_Type(attr_type, T_FIXNUM);
531
+ value = (ub2)check_data_range(val, 0, USHRT_MAX, "ub2");
532
+ /* set attribute */
533
+ chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
534
+ return self;
535
+ }
536
+
537
+ /*
538
+ * @overload attr_set_ub4(attr_type, attr_value)
539
+ *
540
+ * Sets the value of an attribute as `ub4' datatype.
541
+ *
542
+ * @note If the specified attr_type's datatype is a
543
+ * pointer type, it causes a segmentation fault.
544
+ *
545
+ * @param [Integer] attr_type
546
+ * @param [Integer] attr_value
547
+ * @return [self]
548
+ *
549
+ * @since 2.0.4
550
+ * @private
551
+ */
552
+ static VALUE attr_set_ub4(VALUE self, VALUE attr_type, VALUE val)
553
+ {
554
+ oci8_base_t *base = TO_HANDLE(self);
555
+ ub4 value;
556
+
557
+ /* validate arguments */
558
+ Check_Type(attr_type, T_FIXNUM);
559
+ value = NUM2UINT(val);
560
+ /* set attribute */
561
+ chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
562
+ return self;
563
+ }
564
+
565
+ /*
566
+ * @overload attr_set_ub8(attr_type, attr_value)
567
+ *
568
+ * Sets the value of an attribute as `ub8' datatype.
569
+ *
570
+ * @note If the specified attr_type's datatype is a
571
+ * pointer type, it causes a segmentation fault.
572
+ *
573
+ * @param [Integer] attr_type
574
+ * @param [Integer] attr_value
575
+ * @return [self]
576
+ *
577
+ * @since 2.0.4
578
+ * @private
579
+ */
580
+ static VALUE attr_set_ub8(VALUE self, VALUE attr_type, VALUE val)
581
+ {
582
+ oci8_base_t *base = TO_HANDLE(self);
583
+ ub8 value;
584
+
585
+ /* validate arguments */
586
+ Check_Type(attr_type, T_FIXNUM);
587
+ value = NUM2ULL(val);
588
+ /* set attribute */
589
+ chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
590
+ return self;
591
+ }
592
+
593
+ /*
594
+ * @overload attr_set_sb1(attr_type, attr_value)
595
+ *
596
+ * Sets the value of an attribute as `sb1' datatype.
597
+ *
598
+ * @note If the specified attr_type's datatype is a
599
+ * pointer type, it causes a segmentation fault.
600
+ *
601
+ * @param [Integer] attr_type
602
+ * @param [Integer] attr_value
603
+ * @return [self]
604
+ *
605
+ * @since 2.0.4
606
+ * @private
607
+ */
608
+ static VALUE attr_set_sb1(VALUE self, VALUE attr_type, VALUE val)
609
+ {
610
+ oci8_base_t *base = TO_HANDLE(self);
611
+ sb1 value;
612
+
613
+ /* validate arguments */
614
+ Check_Type(attr_type, T_FIXNUM);
615
+ value = (sb1)check_data_range(val, CHAR_MIN, CHAR_MAX, "sb1");
616
+ /* set attribute */
617
+ chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
618
+ return self;
619
+ }
620
+
621
+ /*
622
+ * @overload attr_set_sb2(attr_type, attr_value)
623
+ *
624
+ * Sets the value of an attribute as `sb2' datatype.
625
+ *
626
+ * @note If the specified attr_type's datatype is a
627
+ * pointer type, it causes a segmentation fault.
628
+ *
629
+ * @param [Integer] attr_type
630
+ * @param [Integer] attr_value
631
+ * @return [self]
632
+ *
633
+ * @since 2.0.4
634
+ * @private
635
+ */
636
+ static VALUE attr_set_sb2(VALUE self, VALUE attr_type, VALUE val)
637
+ {
638
+ oci8_base_t *base = TO_HANDLE(self);
639
+ sb2 value;
640
+
641
+ /* validate arguments */
642
+ Check_Type(attr_type, T_FIXNUM);
643
+ value = (sb2)check_data_range(val, SHRT_MIN, SHRT_MAX, "sb2");
644
+ /* set attribute */
645
+ chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
646
+ return self;
647
+ }
648
+
649
+ /*
650
+ * @overload attr_set_sb4(attr_type, attr_value)
651
+ *
652
+ * Sets the value of an attribute as `sb4' datatype.
653
+ *
654
+ * @note If the specified attr_type's datatype is a
655
+ * pointer type, it causes a segmentation fault.
656
+ *
657
+ * @param [Integer] attr_type
658
+ * @param [Integer] attr_value
659
+ * @return [self]
660
+ *
661
+ * @since 2.0.4
662
+ * @private
663
+ */
664
+ static VALUE attr_set_sb4(VALUE self, VALUE attr_type, VALUE val)
665
+ {
666
+ oci8_base_t *base = TO_HANDLE(self);
667
+ sb4 value;
668
+
669
+ /* validate arguments */
670
+ Check_Type(attr_type, T_FIXNUM);
671
+ value = NUM2INT(val);
672
+ /* set attribute */
673
+ chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
674
+ return self;
675
+ }
676
+
677
+ /*
678
+ * @overload attr_set_sb8(attr_type, attr_value)
679
+ *
680
+ * Sets the value of an attribute as `sb8' datatype.
681
+ *
682
+ * @note If the specified attr_type's datatype is a
683
+ * pointer type, it causes a segmentation fault.
684
+ *
685
+ * @param [Integer] attr_type
686
+ * @param [Integer] attr_value
687
+ * @return [self]
688
+ *
689
+ * @since 2.0.4
690
+ * @private
691
+ */
692
+ static VALUE attr_set_sb8(VALUE self, VALUE attr_type, VALUE val)
693
+ {
694
+ oci8_base_t *base = TO_HANDLE(self);
695
+ sb8 value;
696
+
697
+ /* validate arguments */
698
+ Check_Type(attr_type, T_FIXNUM);
699
+ value = NUM2LL(val);
700
+ /* set attribute */
701
+ chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
702
+ return self;
703
+ }
704
+
705
+ /*
706
+ * @overload attr_set_boolean(attr_type, attr_value)
707
+ *
708
+ * Sets the value of an attribute as `boolean' datatype.
709
+ *
710
+ * @note If the specified attr_type's datatype is a
711
+ * pointer type, it causes a segmentation fault.
712
+ *
713
+ * @param [Integer] attr_type
714
+ * @param [true or false] attr_value
715
+ * @return [self]
716
+ *
717
+ * @since 2.0.4
718
+ * @private
719
+ */
720
+ static VALUE attr_set_boolean(VALUE self, VALUE attr_type, VALUE val)
721
+ {
722
+ oci8_base_t *base = TO_HANDLE(self);
723
+ boolean value;
724
+
725
+ /* validate arguments */
726
+ Check_Type(attr_type, T_FIXNUM);
727
+ value = RTEST(val) ? TRUE : FALSE;
728
+ /* set attribute */
729
+ chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
730
+ return self;
731
+ }
732
+
733
+ /*
734
+ * @overload attr_set_string(attr_type, attr_value)
735
+ *
736
+ * Sets the value of an attribute as `oratext *' datatype.
737
+ * +attr_value+ is converted to {STACI.encoding} before it is set
738
+ * when the ruby version is 1.9.
739
+ *
740
+ * @param [Integer] attr_type
741
+ * @param [String] attr_value
742
+ * @return [self]
743
+ *
744
+ * @since 2.0.4
745
+ * @private
746
+ */
747
+ static VALUE attr_set_string(VALUE self, VALUE attr_type, VALUE val)
748
+ {
749
+ oci8_base_t *base = TO_HANDLE(self);
750
+
751
+ /* validate arguments */
752
+ Check_Type(attr_type, T_FIXNUM);
753
+ OCI8SafeStringValue(val);
754
+ /* set attribute */
755
+ chker2(OCIAttrSet(base->hp.ptr, base->type, RSTRING_PTR(val), RSTRING_LEN(val), FIX2INT(attr_type), oci8_errhp), base);
756
+ return self;
757
+ }
758
+
759
+ /*
760
+ * @overload attr_set_binary(attr_type, attr_value)
761
+ *
762
+ * Sets the value of an attribute as `ub1 *' datatype.
763
+ *
764
+ * @param [Integer] attr_type
765
+ * @param [String] attr_value
766
+ * @return [self]
767
+ *
768
+ * @since 2.0.4
769
+ * @private
770
+ */
771
+ static VALUE attr_set_binary(VALUE self, VALUE attr_type, VALUE val)
772
+ {
773
+ oci8_base_t *base = TO_HANDLE(self);
774
+
775
+ /* validate arguments */
776
+ Check_Type(attr_type, T_FIXNUM);
777
+ SafeStringValue(val);
778
+ /* set attribute */
779
+ chker2(OCIAttrSet(base->hp.ptr, base->type, RSTRING_PTR(val), RSTRING_LEN(val), FIX2INT(attr_type), oci8_errhp), base);
780
+ return self;
781
+ }
782
+
783
+ /*
784
+ * @overload attr_set_integer(attr_type, number)
785
+ *
786
+ * Sets the value of an attribute as `ub1 *' datatype.
787
+ * +number+ is converted to internal Oracle NUMBER format before
788
+ * it is set.
789
+ *
790
+ * @param [Integer] attr_type
791
+ * @param [Numeric] number
792
+ * @return [self]
793
+ *
794
+ * @since 2.0.4
795
+ * @private
796
+ */
797
+ static VALUE attr_set_integer(VALUE self, VALUE attr_type, VALUE val)
798
+ {
799
+ oci8_base_t *base = TO_HANDLE(self);
800
+ OCINumber value;
801
+
802
+ /* validate arguments */
803
+ Check_Type(attr_type, T_FIXNUM);
804
+ oci8_set_integer(&value, val, oci8_errhp);
805
+ /* set attribute */
806
+ chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
807
+ return self;
808
+ }
809
+
810
+ void Init_oci8_handle(void)
811
+ {
812
+ /*
813
+ * OCIHandle is the abstract base class of OCI handles and
814
+ * OCI descriptors; opaque data types of Oracle Call Interface.
815
+ * Don't use constants and methods defined in the class.
816
+ *
817
+ * @since 2.0.0
818
+ */
819
+ oci8_cOCIHandle = rb_define_class("OCIHandle", rb_cObject);
820
+ rb_define_alloc_func(oci8_cOCIHandle, oci8_s_allocate);
821
+ rb_define_method_nodoc(oci8_cOCIHandle, "initialize", oci8_handle_initialize, 0);
822
+ rb_define_private_method(oci8_cOCIHandle, "free", oci8_handle_free, 0);
823
+
824
+ /* methods to get attributes */
825
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_ub1", attr_get_ub1, -1);
826
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_ub2", attr_get_ub2, -1);
827
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_ub4", attr_get_ub4, -1);
828
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_ub8", attr_get_ub8, -1);
829
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_sb1", attr_get_sb1, -1);
830
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_sb2", attr_get_sb2, -1);
831
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_sb4", attr_get_sb4, -1);
832
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_sb8", attr_get_sb8, -1);
833
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_boolean", attr_get_boolean, -1);
834
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_string", attr_get_string, -1);
835
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_binary", attr_get_binary, -1);
836
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_integer", attr_get_integer, -1);
837
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_oradate", attr_get_oradate, -1);
838
+
839
+ /* methods to set attributes */
840
+ rb_define_private_method(oci8_cOCIHandle, "attr_set_ub1", attr_set_ub1, 2);
841
+ rb_define_private_method(oci8_cOCIHandle, "attr_set_ub2", attr_set_ub2, 2);
842
+ rb_define_private_method(oci8_cOCIHandle, "attr_set_ub4", attr_set_ub4, 2);
843
+ rb_define_private_method(oci8_cOCIHandle, "attr_set_ub8", attr_set_ub8, 2);
844
+ rb_define_private_method(oci8_cOCIHandle, "attr_set_sb1", attr_set_sb1, 2);
845
+ rb_define_private_method(oci8_cOCIHandle, "attr_set_sb2", attr_set_sb2, 2);
846
+ rb_define_private_method(oci8_cOCIHandle, "attr_set_sb4", attr_set_sb4, 2);
847
+ rb_define_private_method(oci8_cOCIHandle, "attr_set_sb8", attr_set_sb8, 2);
848
+ rb_define_private_method(oci8_cOCIHandle, "attr_set_boolean", attr_set_boolean, 2);
849
+ rb_define_private_method(oci8_cOCIHandle, "attr_set_string", attr_set_string, 2);
850
+ rb_define_private_method(oci8_cOCIHandle, "attr_set_binary", attr_set_binary, 2);
851
+ rb_define_private_method(oci8_cOCIHandle, "attr_set_integer", attr_set_integer, 2);
852
+ }