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