ruby-oci8 2.1.4 → 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,6 +38,8 @@ extern rb_pid_t rb_w32_getpid(void);
38
38
  static VALUE cOCI8;
39
39
  static VALUE cSession;
40
40
  static VALUE cServer;
41
+ static VALUE cEnvironment;
42
+ static VALUE cProcess;
41
43
  static ID id_at_session_handle;
42
44
  static ID id_at_server_handle;
43
45
 
@@ -48,7 +50,7 @@ static VALUE dummy_env_method_missing(int argc, VALUE *argv, VALUE self)
48
50
 
49
51
  if (self == obj) {
50
52
  oci8_base_t *base;
51
- obj = rb_obj_alloc(oci8_cOCIHandle);
53
+ obj = rb_obj_alloc(cEnvironment);
52
54
  base = DATA_PTR(obj);
53
55
  base->type = OCI_HTYPE_ENV;
54
56
  base->hp.ptr = oci8_envhp;
@@ -61,21 +63,16 @@ static VALUE dummy_env_method_missing(int argc, VALUE *argv, VALUE self)
61
63
  return rb_apply(obj, SYM2ID(method_id), args);
62
64
  }
63
65
 
64
- typedef struct oci8_svcctx_associate {
65
- oci8_base_t base;
66
- oci8_svcctx_t *svcctx;
67
- } oci8_svcctx_associate_t;
68
-
69
- static void oci8_svcctx_associate_free(oci8_base_t *base)
66
+ static void oci8_dont_free_handle_free(oci8_base_t *base)
70
67
  {
71
68
  base->type = 0;
72
69
  base->hp.ptr = NULL;
73
70
  }
74
71
 
75
- static oci8_base_vtable_t oci8_svcctx_associate_vtable = {
72
+ static oci8_base_vtable_t oci8_dont_free_handle_vtable = {
76
73
  NULL,
77
- oci8_svcctx_associate_free,
78
- sizeof(oci8_svcctx_associate_t),
74
+ oci8_dont_free_handle_free,
75
+ sizeof(oci8_base_t),
79
76
  };
80
77
 
81
78
  static void copy_session_handle(oci8_svcctx_t *svcctx)
@@ -163,8 +160,6 @@ static oci8_base_vtable_t oci8_svcctx_vtable = {
163
160
  };
164
161
 
165
162
  static VALUE oracle_client_vernum; /* Oracle client version number */
166
- static ID id_at_prefetch_rows;
167
- static ID id_set_prefetch_rows;
168
163
 
169
164
  static VALUE oci8_s_oracle_client_vernum(VALUE klass)
170
165
  {
@@ -776,23 +771,6 @@ static VALUE oci8_break(VALUE self)
776
771
  return Qtrue;
777
772
  }
778
773
 
779
- /*
780
- * call-seq:
781
- * prefetch_rows = number
782
- *
783
- * Sets the prefetch rows size. The default value is one.
784
- * When a select statement is executed, the OCI library allocate
785
- * prefetch buffer to reduce the number of network round trips by
786
- * retrieving specified number of rows in one round trip.
787
- *
788
- * Note: Active record adaptors set 100 by default.
789
- */
790
- static VALUE oci8_set_prefetch_rows(VALUE self, VALUE val)
791
- {
792
- rb_ivar_set(self, id_at_prefetch_rows, val);
793
- return val;
794
- }
795
-
796
774
  /*
797
775
  * call-seq:
798
776
  * oracle_server_vernum -> an integer
@@ -1124,8 +1102,10 @@ void Init_oci8(VALUE *out)
1124
1102
  cOCI8 = rb_define_class("OCI8", oci8_cOCIHandle);
1125
1103
  #endif
1126
1104
  cOCI8 = oci8_define_class("OCI8", &oci8_svcctx_vtable);
1127
- cSession = oci8_define_class_under(cOCI8, "Session", &oci8_svcctx_associate_vtable);
1128
- cServer = oci8_define_class_under(cOCI8, "Server", &oci8_svcctx_associate_vtable);
1105
+ cSession = oci8_define_class_under(cOCI8, "Session", &oci8_dont_free_handle_vtable);
1106
+ cServer = oci8_define_class_under(cOCI8, "Server", &oci8_dont_free_handle_vtable);
1107
+ cEnvironment = oci8_define_class_under(cOCI8, "Environment", &oci8_dont_free_handle_vtable);
1108
+ cProcess = oci8_define_class_under(cOCI8, "Process", &oci8_dont_free_handle_vtable);
1129
1109
  id_at_session_handle = rb_intern("@session_handle");
1130
1110
  id_at_server_handle = rb_intern("@server_handle");
1131
1111
 
@@ -1135,7 +1115,7 @@ void Init_oci8(VALUE *out)
1135
1115
  rb_cv_set(cOCI8, "@@environment_handle", obj);
1136
1116
 
1137
1117
  /* setup the process handle */
1138
- obj = rb_obj_alloc(oci8_cOCIHandle);
1118
+ obj = rb_obj_alloc(cProcess);
1139
1119
  base = DATA_PTR(obj);
1140
1120
  base->type = OCI_HTYPE_PROC;
1141
1121
  base->self = Qnil;
@@ -1148,9 +1128,6 @@ void Init_oci8(VALUE *out)
1148
1128
  oracle_client_vernum = INT2FIX(ORAVERNUM(major, minor, update, patch, port_update));
1149
1129
  }
1150
1130
 
1151
- id_at_prefetch_rows = rb_intern("@prefetch_rows");
1152
- id_set_prefetch_rows = rb_intern("prefetch_rows=");
1153
-
1154
1131
  rb_define_const(cOCI8, "VERSION", rb_obj_freeze(rb_usascii_str_new_cstr(OCI8LIB_VERSION)));
1155
1132
  rb_define_singleton_method_nodoc(cOCI8, "oracle_client_vernum", oci8_s_oracle_client_vernum, 0);
1156
1133
  rb_define_singleton_method(cOCI8, "__get_prop", oci8_s_get_prop, 1);
@@ -1171,7 +1148,6 @@ void Init_oci8(VALUE *out)
1171
1148
  rb_define_method(cOCI8, "long_read_len", oci8_long_read_len, 0);
1172
1149
  rb_define_method(cOCI8, "long_read_len=", oci8_set_long_read_len, 1);
1173
1150
  rb_define_method(cOCI8, "break", oci8_break, 0);
1174
- rb_define_method(cOCI8, "prefetch_rows=", oci8_set_prefetch_rows, 1);
1175
1151
  rb_define_private_method(cOCI8, "oracle_server_vernum", oci8_oracle_server_vernum, 0);
1176
1152
  rb_define_method(cOCI8, "ping", oci8_ping, 0);
1177
1153
  rb_define_method(cOCI8, "client_identifier=", oci8_set_client_identifier, 1);
@@ -1186,12 +1162,6 @@ oci8_svcctx_t *oci8_get_svcctx(VALUE obj)
1186
1162
  return (oci8_svcctx_t *)oci8_get_handle(obj, cOCI8);
1187
1163
  }
1188
1164
 
1189
- OCISvcCtx *oci8_get_oci_svcctx(VALUE obj)
1190
- {
1191
- oci8_svcctx_t *svcctx = oci8_get_svcctx(obj);
1192
- return svcctx->base.hp.svc;
1193
- }
1194
-
1195
1165
  OCISession *oci8_get_oci_session(VALUE obj)
1196
1166
  {
1197
1167
  oci8_svcctx_t *svcctx = oci8_get_svcctx(obj);
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  * oci8.h - part of ruby-oci8
4
4
  *
5
- * Copyright (C) 2002-2012 KUBO Takehiro <kubo@jiubao.org>
5
+ * Copyright (C) 2002-2013 Kubo Takehiro <kubo@jiubao.org>
6
6
  */
7
7
  #ifndef _RUBY_OCI_H_
8
8
  #define _RUBY_OCI_H_ 1
@@ -494,10 +494,8 @@ void Init_oci8_handle(void);
494
494
  void Init_oci8(VALUE *out);
495
495
  void oci8_do_parse_connect_string(VALUE conn_str, VALUE *user, VALUE *pass, VALUE *dbname, VALUE *mode);
496
496
  oci8_svcctx_t *oci8_get_svcctx(VALUE obj);
497
- OCISvcCtx *oci8_get_oci_svcctx(VALUE obj);
498
497
  OCISession *oci8_get_oci_session(VALUE obj);
499
498
  void oci8_check_pid_consistency(oci8_svcctx_t *svcctx);
500
- #define TO_SVCCTX oci8_get_oci_svcctx
501
499
  #define TO_SESSION oci8_get_oci_session
502
500
 
503
501
  /* connection_pool.c */
@@ -22,6 +22,14 @@ ID oci8_id_div_op;
22
22
  int oci8_in_finalizer = 0;
23
23
  VALUE oci8_cOCIHandle;
24
24
 
25
+ #if defined __sun && defined __i386 && defined __GNUC__
26
+ /* When a main function is invisible from Oracle instant
27
+ * client 11.2.0.3 for Solaris x86 (32-bit), OCIEnvCreate()
28
+ * fails by unknown reasons. We export it from ruby-oci8 instead
29
+ * of ruby itself.
30
+ */
31
+ int main() { return 0; }
32
+ #endif
25
33
 
26
34
  static VALUE mOCI8BindType;
27
35
  static VALUE cOCI8BindTypeBase;
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  * ocihandle.c
4
4
  *
5
- * Copyright (C) 2009-2012 KUBO Takehiro <kubo@jiubao.org>
5
+ * Copyright (C) 2009-2013 Kubo Takehiro <kubo@jiubao.org>
6
6
  *
7
7
  * implement OCIHandle
8
8
  *
@@ -103,243 +103,272 @@ static VALUE oci8_s_allocate(VALUE klass)
103
103
  return obj;
104
104
  }
105
105
 
106
+ enum datatype {
107
+ DATATYPE_UB1,
108
+ DATATYPE_UB2,
109
+ DATATYPE_UB4,
110
+ DATATYPE_UB8,
111
+ DATATYPE_SB1,
112
+ DATATYPE_SB2,
113
+ DATATYPE_SB4,
114
+ DATATYPE_SB8,
115
+ DATATYPE_BOOLEAN,
116
+ DATATYPE_STRING,
117
+ DATATYPE_BINARY,
118
+ DATATYPE_INTEGER,
119
+ DATATYPE_ORADATE,
120
+ };
121
+
122
+ static VALUE attr_get_common(int argc, VALUE *argv, VALUE self, enum datatype datatype)
123
+ {
124
+ oci8_base_t *base = DATA_PTR(self);
125
+ VALUE attr_type;
126
+ VALUE strict;
127
+ union {
128
+ ub1 ub1val;
129
+ ub2 ub2val;
130
+ ub4 ub4val;
131
+ ub8 ub8val;
132
+ sb1 sb1val;
133
+ sb2 sb2val;
134
+ sb4 sb4val;
135
+ sb8 sb8val;
136
+ boolean booleanval;
137
+ char *charptr;
138
+ ub1 *ub1ptr;
139
+ } v;
140
+ ub4 size = 0;
141
+ sword rv;
142
+
143
+ v.ub8val = MAGIC_NUMBER;
144
+ rb_scan_args(argc, argv, "11", &attr_type, &strict);
145
+ if (argc == 1) {
146
+ strict = Qtrue;
147
+ }
148
+ Check_Type(attr_type, T_FIXNUM);
149
+ rv = OCIAttrGet(base->hp.ptr, base->type, &v, &size, FIX2INT(attr_type), oci8_errhp);
150
+ if (!RTEST(strict)) {
151
+ if (rv == OCI_ERROR && oci8_get_error_code(oci8_errhp) == 24328) {
152
+ /* ignore ORA-24328: illegal attribute value */
153
+ return Qnil;
154
+ }
155
+ }
156
+ chker2(rv, base);
157
+ switch (datatype) {
158
+ OCINumber onum;
159
+ static VALUE cOraDate = Qnil;
160
+ case DATATYPE_UB1:
161
+ return INT2FIX(v.ub1val);
162
+ case DATATYPE_UB2:
163
+ return INT2FIX(v.ub2val);
164
+ case DATATYPE_UB4:
165
+ return UINT2NUM(v.ub4val);
166
+ case DATATYPE_UB8:
167
+ return ULL2NUM(v.ub8val);
168
+ case DATATYPE_SB1:
169
+ return INT2FIX(v.sb1val);
170
+ case DATATYPE_SB2:
171
+ return INT2FIX(v.sb2val);
172
+ case DATATYPE_SB4:
173
+ return INT2NUM(v.sb4val);
174
+ case DATATYPE_SB8:
175
+ return LL2NUM(v.sb8val);
176
+ case DATATYPE_BOOLEAN:
177
+ return v.booleanval ? Qtrue : Qfalse;
178
+ case DATATYPE_STRING:
179
+ if (size == 0 && !RTEST(strict)) {
180
+ return Qnil;
181
+ }
182
+ return rb_external_str_new_with_enc(v.charptr, size, oci8_encoding);
183
+ case DATATYPE_BINARY:
184
+ return rb_tainted_str_new(v.charptr, size);
185
+ case DATATYPE_INTEGER:
186
+ if (size > sizeof(onum.OCINumberPart) - 1) {
187
+ rb_raise(rb_eRuntimeError, "Too long size %u", size);
188
+ }
189
+ memset(&onum, 0, sizeof(onum));
190
+ onum.OCINumberPart[0] = size;
191
+ memcpy(&onum.OCINumberPart[1], v.ub1ptr, size);
192
+ return oci8_make_integer(&onum, oci8_errhp);
193
+ case DATATYPE_ORADATE:
194
+ if (NIL_P(cOraDate))
195
+ cOraDate = rb_eval_string("OraDate");
196
+ return rb_funcall(cOraDate, oci8_id_new, 6,
197
+ INT2FIX((v.ub1ptr[0] - 100) * 100 + (v.ub1ptr[1] - 100)),
198
+ INT2FIX(v.ub1ptr[2]),
199
+ INT2FIX(v.ub1ptr[3]),
200
+ INT2FIX(v.ub1ptr[4] - 1),
201
+ INT2FIX(v.ub1ptr[5] - 1),
202
+ INT2FIX(v.ub1ptr[6] - 1));
203
+ }
204
+ return Qnil;
205
+ }
206
+
106
207
  /*
107
208
  * call-seq:
108
- * attr_get_ub1(attr_type)
209
+ * attr_get_ub1(attr_type, strict = true)
109
210
  *
110
211
  * Gets the value of an attribute as `ub1' datatype.
111
212
  *
112
213
  * @param [Fixnum] attr_type
214
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
113
215
  * @return [Fixnum]
114
216
  *
115
217
  * @since 2.0.4
116
218
  * @private
117
219
  */
118
- static VALUE attr_get_ub1(VALUE self, VALUE attr_type)
220
+ static VALUE attr_get_ub1(int argc, VALUE *argv, VALUE self)
119
221
  {
120
- oci8_base_t *base = DATA_PTR(self);
121
- union {
122
- ub1 value;
123
- ub8 dummy; /* padding for incorrect attrtype to protect the stack */
124
- } v;
125
-
126
- v.dummy = MAGIC_NUMBER;
127
- Check_Type(attr_type, T_FIXNUM);
128
- chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
129
- return INT2FIX(v.value);
222
+ return attr_get_common(argc, argv, self, DATATYPE_UB1);
130
223
  }
131
224
 
132
225
  /*
133
226
  * call-seq:
134
- * attr_get_ub2(attr_type)
227
+ * attr_get_ub2(attr_type, strict = true)
135
228
  *
136
229
  * Gets the value of an attribute as `ub2' datatype.
137
230
  *
138
231
  * @param [Fixnum] attr_type
232
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
139
233
  * @return [Fixnum]
140
234
  *
141
235
  * @since 2.0.4
142
236
  * @private
143
237
  */
144
- static VALUE attr_get_ub2(VALUE self, VALUE attr_type)
238
+ static VALUE attr_get_ub2(int argc, VALUE *argv, VALUE self)
145
239
  {
146
- oci8_base_t *base = DATA_PTR(self);
147
- union {
148
- ub2 value;
149
- ub8 dummy; /* padding for incorrect attrtype to protect the stack */
150
- } v;
151
-
152
- v.dummy = MAGIC_NUMBER;
153
- Check_Type(attr_type, T_FIXNUM);
154
- chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
155
- return INT2FIX(v.value);
240
+ return attr_get_common(argc, argv, self, DATATYPE_UB2);
156
241
  }
157
242
 
158
243
  /*
159
244
  * call-seq:
160
- * attr_get_ub4(attr_type)
245
+ * attr_get_ub4(attr_type, strict = true)
161
246
  *
162
247
  * Gets the value of an attribute as `ub4' datatype.
163
248
  *
164
249
  * @param [Fixnum] attr_type
250
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
165
251
  * @return [Integer]
166
252
  *
167
253
  * @since 2.0.4
168
254
  * @private
169
255
  */
170
- static VALUE attr_get_ub4(VALUE self, VALUE attr_type)
256
+ static VALUE attr_get_ub4(int argc, VALUE *argv, VALUE self)
171
257
  {
172
- oci8_base_t *base = DATA_PTR(self);
173
- union {
174
- ub4 value;
175
- ub8 dummy; /* padding for incorrect attrtype to protect the stack */
176
- } v;
177
-
178
- v.dummy = MAGIC_NUMBER;
179
- Check_Type(attr_type, T_FIXNUM);
180
- chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
181
- return UINT2NUM(v.value);
258
+ return attr_get_common(argc, argv, self, DATATYPE_UB4);
182
259
  }
183
260
 
184
261
  /*
185
262
  * call-seq:
186
- * attr_get_ub8(attr_type)
263
+ * attr_get_ub8(attr_type, strict = true)
187
264
  *
188
265
  * Gets the value of an attribute as `ub8' datatype.
189
266
  *
190
267
  * @param [Fixnum] attr_type
268
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
191
269
  * @return [Integer]
192
270
  *
193
271
  * @since 2.0.4
194
272
  * @private
195
273
  */
196
- static VALUE attr_get_ub8(VALUE self, VALUE attr_type)
274
+ static VALUE attr_get_ub8(int argc, VALUE *argv, VALUE self)
197
275
  {
198
- oci8_base_t *base = DATA_PTR(self);
199
- union {
200
- ub8 value;
201
- ub8 dummy;
202
- } v;
203
-
204
- v.dummy = MAGIC_NUMBER;
205
- Check_Type(attr_type, T_FIXNUM);
206
- chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
207
- return ULL2NUM(v.value);
276
+ return attr_get_common(argc, argv, self, DATATYPE_UB8);
208
277
  }
209
278
 
210
279
  /*
211
280
  * call-seq:
212
- * attr_get_sb1(attr_type)
281
+ * attr_get_sb1(attr_type, strict = true)
213
282
  *
214
283
  * Gets the value of an attribute as `sb1' datatype.
215
284
  *
216
285
  * @param [Fixnum] attr_type
286
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
217
287
  * @return [Fixnum]
218
288
  *
219
289
  * @since 2.0.4
220
290
  * @private
221
291
  */
222
- static VALUE attr_get_sb1(VALUE self, VALUE attr_type)
292
+ static VALUE attr_get_sb1(int argc, VALUE *argv, VALUE self)
223
293
  {
224
- oci8_base_t *base = DATA_PTR(self);
225
- union {
226
- sb1 value;
227
- ub8 dummy; /* padding for incorrect attrtype to protect the stack */
228
- } v;
229
-
230
- v.dummy = MAGIC_NUMBER;
231
- Check_Type(attr_type, T_FIXNUM);
232
- chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
233
- return INT2FIX(v.value);
294
+ return attr_get_common(argc, argv, self, DATATYPE_SB1);
234
295
  }
235
296
 
236
297
  /*
237
298
  * call-seq:
238
- * attr_get_sb2(attr_type)
299
+ * attr_get_sb2(attr_type, strict = true)
239
300
  *
240
301
  * Gets the value of an attribute as `sb2' datatype.
241
302
  *
242
303
  * @param [Fixnum] attr_type
304
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
243
305
  * @return [Fixnum]
244
306
  *
245
307
  * @since 2.0.4
246
308
  * @private
247
309
  */
248
- static VALUE attr_get_sb2(VALUE self, VALUE attr_type)
310
+ static VALUE attr_get_sb2(int argc, VALUE *argv, VALUE self)
249
311
  {
250
- oci8_base_t *base = DATA_PTR(self);
251
- union {
252
- sb2 value;
253
- ub8 dummy; /* padding for incorrect attrtype to protect the stack */
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 INT2FIX(v.value);
312
+ return attr_get_common(argc, argv, self, DATATYPE_SB2);
260
313
  }
261
314
 
262
315
  /*
263
316
  * call-seq:
264
- * attr_get_sb4(attr_type)
317
+ * attr_get_sb4(attr_type, strict = true)
265
318
  *
266
319
  * Gets the value of an attribute as `sb4' datatype.
267
320
  *
268
321
  * @param [Fixnum] attr_type
322
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
269
323
  * @return [Integer]
270
324
  *
271
325
  * @since 2.0.4
272
326
  * @private
273
327
  */
274
- static VALUE attr_get_sb4(VALUE self, VALUE attr_type)
328
+ static VALUE attr_get_sb4(int argc, VALUE *argv, VALUE self)
275
329
  {
276
- oci8_base_t *base = DATA_PTR(self);
277
- union {
278
- sb4 value;
279
- ub8 dummy;
280
- } v;
281
-
282
- v.dummy = MAGIC_NUMBER;
283
- Check_Type(attr_type, T_FIXNUM);
284
- chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
285
- return INT2NUM(v.value);
330
+ return attr_get_common(argc, argv, self, DATATYPE_SB4);
286
331
  }
287
332
 
288
333
  /*
289
334
  * call-seq:
290
- * attr_get_sb8(attr_type)
335
+ * attr_get_sb8(attr_type, strict = true)
291
336
  *
292
337
  * Gets the value of an attribute as `sb8' datatype.
293
338
  *
294
339
  * @param [Fixnum] attr_type
340
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
295
341
  * @return [Integer]
296
342
  *
297
343
  * @since 2.0.4
298
344
  * @private
299
345
  */
300
- static VALUE attr_get_sb8(VALUE self, VALUE attr_type)
346
+ static VALUE attr_get_sb8(int argc, VALUE *argv, VALUE self)
301
347
  {
302
- oci8_base_t *base = DATA_PTR(self);
303
- union {
304
- sb8 value;
305
- ub8 dummy; /* padding for incorrect attrtype to protect the stack */
306
- } v;
307
-
308
- v.dummy = MAGIC_NUMBER;
309
- Check_Type(attr_type, T_FIXNUM);
310
- chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
311
- return LL2NUM(v.value);
348
+ return attr_get_common(argc, argv, self, DATATYPE_SB8);
312
349
  }
313
350
 
314
351
  /*
315
352
  * call-seq:
316
- * attr_get_boolean(attr_type)
353
+ * attr_get_boolean(attr_type, strict = true)
317
354
  *
318
355
  * Gets the value of an attribute as `boolean' datatype.
319
356
  *
320
357
  * @param [Fixnum] attr_type
358
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
321
359
  * @return [true of false]
322
360
  *
323
361
  * @since 2.0.4
324
362
  * @private
325
363
  */
326
- static VALUE attr_get_boolean(VALUE self, VALUE attr_type)
364
+ static VALUE attr_get_boolean(int argc, VALUE *argv, VALUE self)
327
365
  {
328
- oci8_base_t *base = DATA_PTR(self);
329
- union {
330
- boolean value;
331
- ub8 dummy; /* padding for incorrect attrtype to protect the stack */
332
- } v;
333
-
334
- v.dummy = MAGIC_NUMBER;
335
- Check_Type(attr_type, T_FIXNUM);
336
- chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
337
- return v.value ? Qtrue : Qfalse;
366
+ return attr_get_common(argc, argv, self, DATATYPE_BOOLEAN);
338
367
  }
339
368
 
340
369
  /*
341
370
  * call-seq:
342
- * attr_get_string(attr_type)
371
+ * attr_get_string(attr_type, strict = true)
343
372
  *
344
373
  * Gets the value of an attribute as `oratext *' datatype.
345
374
  * The return value is converted to Encoding.default_internal or
@@ -349,29 +378,20 @@ static VALUE attr_get_boolean(VALUE self, VALUE attr_type)
349
378
  * pointer type, it causes a segmentation fault.
350
379
  *
351
380
  * @param [Fixnum] attr_type
381
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
352
382
  * @return [String]
353
383
  *
354
384
  * @since 2.0.4
355
385
  * @private
356
386
  */
357
- static VALUE attr_get_string(VALUE self, VALUE attr_type)
387
+ static VALUE attr_get_string(int argc, VALUE *argv, VALUE self)
358
388
  {
359
- oci8_base_t *base = DATA_PTR(self);
360
- union {
361
- char *value;
362
- ub8 dummy; /* padding for incorrect attrtype to protect the stack */
363
- } v;
364
- ub4 size = 0;
365
-
366
- v.dummy = MAGIC_NUMBER;
367
- Check_Type(attr_type, T_FIXNUM);
368
- chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp), base);
369
- return rb_external_str_new_with_enc(v.value, size, oci8_encoding);
389
+ return attr_get_common(argc, argv, self, DATATYPE_STRING);
370
390
  }
371
391
 
372
392
  /*
373
393
  * call-seq:
374
- * attr_get_binary(attr_type)
394
+ * attr_get_binary(attr_type, strict = true)
375
395
  *
376
396
  * Gets the value of an attribute as `ub1 *' datatype.
377
397
  * The return value is tagged with ASCII-8BIT when the ruby version is 1.9.
@@ -380,29 +400,20 @@ static VALUE attr_get_string(VALUE self, VALUE attr_type)
380
400
  * pointer type, it causes a segmentation fault.
381
401
  *
382
402
  * @param [Fixnum] attr_type
403
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
383
404
  * @return [String]
384
405
  *
385
406
  * @since 2.0.4
386
407
  * @private
387
408
  */
388
- static VALUE attr_get_binary(VALUE self, VALUE attr_type)
409
+ static VALUE attr_get_binary(int argc, VALUE *argv, VALUE self)
389
410
  {
390
- oci8_base_t *base = DATA_PTR(self);
391
- union {
392
- char *value;
393
- ub8 dummy; /* padding for incorrect attrtype to protect the stack */
394
- } v;
395
- ub4 size = 0;
396
-
397
- v.dummy = 0;
398
- Check_Type(attr_type, T_FIXNUM);
399
- chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp), base);
400
- return rb_tainted_str_new(v.value, size);
411
+ return attr_get_common(argc, argv, self, DATATYPE_BINARY);
401
412
  }
402
413
 
403
414
  /*
404
415
  * call-seq:
405
- * attr_get_integer(attr_type) -> integer
416
+ * attr_get_integer(attr_type, strict = true)
406
417
  *
407
418
  * Gets the value of an attribute as `ub1 *' datatype.
408
419
  * The return value is converted to Integer from internal Oracle NUMBER format.
@@ -411,34 +422,20 @@ static VALUE attr_get_binary(VALUE self, VALUE attr_type)
411
422
  * pointer type, it causes a segmentation fault.
412
423
  *
413
424
  * @param [Fixnum] attr_type
425
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
414
426
  * @return [Fixnum]
415
427
  *
416
428
  * @since 2.0.4
417
429
  * @private
418
430
  */
419
- static VALUE attr_get_integer(VALUE self, VALUE attr_type)
431
+ static VALUE attr_get_integer(int argc, VALUE *argv, VALUE self)
420
432
  {
421
- oci8_base_t *base = DATA_PTR(self);
422
- OCINumber onum;
423
- union {
424
- void *value;
425
- ub8 dummy; /* padding for incorrect attrtype to protect the stack */
426
- } v;
427
- ub4 size = 0;
428
-
429
- v.dummy = 0;
430
- Check_Type(attr_type, T_FIXNUM);
431
- chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp), base);
432
-
433
- memset(&onum, 0, sizeof(onum));
434
- onum.OCINumberPart[0] = size;
435
- memcpy(&onum.OCINumberPart[1], v.value, size);
436
- return oci8_make_integer(&onum, oci8_errhp);
433
+ return attr_get_common(argc, argv, self, DATATYPE_INTEGER);
437
434
  }
438
435
 
439
436
  /*
440
437
  * call-seq:
441
- * attr_get_oradate(attr_type) -> an OraDate
438
+ * attr_get_oradate(attr_type, strict = true)
442
439
  *
443
440
  * Gets the value of an attribute as `ub1 *' datatype.
444
441
  * The return value is converted to OraDate.
@@ -447,33 +444,15 @@ static VALUE attr_get_integer(VALUE self, VALUE attr_type)
447
444
  * pointer type, it causes a segmentation fault.
448
445
  *
449
446
  * @param [Fixnum] attr_type
447
+ * @param [Boolean] strict If false, "ORA-24328: illegal attribute value" is ignored.
450
448
  * @return [OraDate]
451
449
  *
452
450
  * @since 2.0.4
453
451
  * @private
454
452
  */
455
- static VALUE attr_get_oradate(VALUE self, VALUE attr_type)
453
+ static VALUE attr_get_oradate(int argc, VALUE *argv, VALUE self)
456
454
  {
457
- oci8_base_t *base = DATA_PTR(self);
458
- union {
459
- ub1 *value;
460
- ub8 dummy; /* padding for incorrect attrtype to protect the stack */
461
- } v;
462
- ub4 size = 0;
463
- static VALUE cOraDate = Qnil;
464
-
465
- v.dummy = 0;
466
- Check_Type(attr_type, T_FIXNUM);
467
- chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp), base);
468
- if (NIL_P(cOraDate))
469
- cOraDate = rb_eval_string("OraDate");
470
- return rb_funcall(cOraDate, oci8_id_new, 6,
471
- INT2FIX((v.value[0] - 100) * 100 + (v.value[1] - 100)),
472
- INT2FIX(v.value[2]),
473
- INT2FIX(v.value[3]),
474
- INT2FIX(v.value[4] - 1),
475
- INT2FIX(v.value[5] - 1),
476
- INT2FIX(v.value[6] - 1));
455
+ return attr_get_common(argc, argv, self, DATATYPE_ORADATE);
477
456
  }
478
457
 
479
458
  /*
@@ -836,19 +815,19 @@ void Init_oci8_handle(void)
836
815
  rb_ivar_set(oci8_cOCIHandle, oci8_id_oci8_vtable, obj);
837
816
 
838
817
  /* methods to get attributes */
839
- rb_define_private_method(oci8_cOCIHandle, "attr_get_ub1", attr_get_ub1, 1);
840
- rb_define_private_method(oci8_cOCIHandle, "attr_get_ub2", attr_get_ub2, 1);
841
- rb_define_private_method(oci8_cOCIHandle, "attr_get_ub4", attr_get_ub4, 1);
842
- rb_define_private_method(oci8_cOCIHandle, "attr_get_ub8", attr_get_ub8, 1);
843
- rb_define_private_method(oci8_cOCIHandle, "attr_get_sb1", attr_get_sb1, 1);
844
- rb_define_private_method(oci8_cOCIHandle, "attr_get_sb2", attr_get_sb2, 1);
845
- rb_define_private_method(oci8_cOCIHandle, "attr_get_sb4", attr_get_sb4, 1);
846
- rb_define_private_method(oci8_cOCIHandle, "attr_get_sb8", attr_get_sb8, 1);
847
- rb_define_private_method(oci8_cOCIHandle, "attr_get_boolean", attr_get_boolean, 1);
848
- rb_define_private_method(oci8_cOCIHandle, "attr_get_string", attr_get_string, 1);
849
- rb_define_private_method(oci8_cOCIHandle, "attr_get_binary", attr_get_binary, 1);
850
- rb_define_private_method(oci8_cOCIHandle, "attr_get_integer", attr_get_integer, 1);
851
- rb_define_private_method(oci8_cOCIHandle, "attr_get_oradate", attr_get_oradate, 1);
818
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_ub1", attr_get_ub1, -1);
819
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_ub2", attr_get_ub2, -1);
820
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_ub4", attr_get_ub4, -1);
821
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_ub8", attr_get_ub8, -1);
822
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_sb1", attr_get_sb1, -1);
823
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_sb2", attr_get_sb2, -1);
824
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_sb4", attr_get_sb4, -1);
825
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_sb8", attr_get_sb8, -1);
826
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_boolean", attr_get_boolean, -1);
827
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_string", attr_get_string, -1);
828
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_binary", attr_get_binary, -1);
829
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_integer", attr_get_integer, -1);
830
+ rb_define_private_method(oci8_cOCIHandle, "attr_get_oradate", attr_get_oradate, -1);
852
831
 
853
832
  /* methods to set attributes */
854
833
  rb_define_private_method(oci8_cOCIHandle, "attr_set_ub1", attr_set_ub1, 2);