ruby-oci8 2.0.3 → 2.0.4

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