ruby-oci8 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- oci8.h - part of ruby-oci8
4
-
5
- Copyright (C) 2002-2009 KUBO Takehiro <kubo@jiubao.org>
6
- */
3
+ * oci8.h - part of ruby-oci8
4
+ *
5
+ * Copyright (C) 2002-2009 KUBO Takehiro <kubo@jiubao.org>
6
+ */
7
7
  #ifndef _RUBY_OCI_H_
8
8
  #define _RUBY_OCI_H_ 1
9
9
 
@@ -49,7 +49,46 @@ extern "C"
49
49
  #include <ruby/encoding.h>
50
50
  #endif
51
51
 
52
- #if ACTUAL_ORACLE_CLIENT_VERSION < ORAVER_10_2
52
+ #ifndef OCI_TEMP_CLOB
53
+ #define OCI_TEMP_CLOB 1
54
+ #endif
55
+ #ifndef OCI_TEMP_BLOB
56
+ #define OCI_TEMP_BLOB 2
57
+ #endif
58
+
59
+ #ifndef ORAXB8_DEFINED
60
+ #if SIZEOF_LONG == 8
61
+ typedef unsigned long oraub8;
62
+ typedef signed long orasb8;
63
+ #elif SIZEOF_LONG_LONG == 8
64
+ typedef unsigned long long oraub8;
65
+ typedef signed long long orasb8;
66
+ #elif SIZEOF___INT64 == 8
67
+ typedef unsigned __int64 oraub8;
68
+ typedef signed __int64 orasb8;
69
+ #endif
70
+ #endif /* ORAXB8_DEFINED */
71
+
72
+ #ifndef HAVE_TYPE_ORATEXT
73
+ typedef unsigned char oratext;
74
+ #endif
75
+ #ifndef HAVE_TYPE_OCIDATETIME_
76
+ typedef struct OCIDateTime OCIDateTime;
77
+ #endif
78
+ #ifndef HAVE_TYPE_OCIINTERVAL_
79
+ typedef struct OCIInterval OCIInterval;
80
+ #endif
81
+ #ifndef HAVE_TYPE_OCICALLBACKLOBREAD2
82
+ typedef sb4 (*OCICallbackLobRead2)(dvoid *ctxp, CONST dvoid *bufp, oraub8 len,
83
+ ub1 piece, dvoid **changed_bufpp,
84
+ oraub8 *changed_lenp);
85
+ #endif
86
+ #ifndef HAVE_TYPE_OCICALLBACKLOBWRITE2
87
+ typedef sb4 (*OCICallbackLobWrite2)(dvoid *ctxp, dvoid *bufp, oraub8 *lenp,
88
+ ub1 *piece, dvoid **changed_bufpp,
89
+ oraub8 *changed_lenp);
90
+ #endif
91
+ #ifndef HAVE_TYPE_OCIADMIN_
53
92
  typedef struct OCIAdmin OCIAdmin;
54
93
  #endif
55
94
 
@@ -78,6 +117,9 @@ typedef struct OCIAdmin OCIAdmin;
78
117
  #ifndef RFLOAT_VALUE
79
118
  #define RFLOAT_VALUE(obj) RFLOAT(obj)->value
80
119
  #endif
120
+ #ifndef STRINGIZE
121
+ #define STRINGIZE(name) #name
122
+ #endif
81
123
 
82
124
  /* new functions in ruby 1.9.
83
125
  * define compatible macros for ruby 1.8 or lower.
@@ -305,12 +347,24 @@ typedef struct {
305
347
  #define UB4_TO_NUM UINT2NUM
306
348
  #endif
307
349
 
308
- /* env.c */
309
- extern OCIEnv *oci8_envhp;
350
+ /* The folloiwng macros oci8_envhp and oci8_errhp are used
351
+ * as if they are defined as follows:
352
+ *
353
+ * extern OCIEnv *oci8_envhp;
354
+ * extern OCIError *oci8_errhp;
355
+ */
356
+ #define oci8_envhp (LIKELY(oci8_global_envhp != NULL) ? oci8_global_envhp : oci8_make_envhp())
310
357
  #ifdef RUBY_VM
311
- /* oci8_errhp is a thread local object in ruby 1.9. */
312
358
  #define oci8_errhp oci8_get_errhp()
359
+ #else
360
+ #define oci8_errhp (LIKELY(oci8_global_errhp != NULL) ? oci8_global_errhp : oci8_make_errhp())
361
+ #endif
313
362
 
363
+ /* env.c */
364
+ extern ub4 oci8_env_mode;
365
+ extern OCIEnv *oci8_global_envhp;
366
+ OCIEnv *oci8_make_envhp(void);
367
+ #ifdef RUBY_VM
314
368
  extern oci8_tls_key_t oci8_tls_key; /* native thread key */
315
369
  OCIError *oci8_make_errhp(void);
316
370
 
@@ -321,8 +375,8 @@ static inline OCIError *oci8_get_errhp()
321
375
  }
322
376
 
323
377
  #else
324
- /* oci8_errhp is global in ruby 1.8. */
325
- extern OCIError *oci8_errhp;
378
+ extern OCIError *oci8_global_errhp;
379
+ OCIError *oci8_make_errhp(void);
326
380
  #endif
327
381
  void Init_oci8_env(void);
328
382
 
@@ -395,13 +449,13 @@ VALUE oci8_make_bfile(oci8_svcctx_t *svcctx, OCILobLocator *s);
395
449
  void Init_ora_date(void);
396
450
 
397
451
  /* ocinumber.c */
398
- void Init_oci_number(VALUE mOCI);
452
+ void Init_oci_number(VALUE mOCI, OCIError *errhp);
399
453
  OCINumber *oci8_get_ocinumber(VALUE num);
400
- VALUE oci8_make_ocinumber(OCINumber *s);
401
- VALUE oci8_make_integer(OCINumber *s);
402
- VALUE oci8_make_float(OCINumber *s);
403
- OCINumber *oci8_set_ocinumber(OCINumber *result, VALUE self);
404
- OCINumber *oci8_set_integer(OCINumber *result, VALUE self);
454
+ VALUE oci8_make_ocinumber(OCINumber *s, OCIError *errhp);
455
+ VALUE oci8_make_integer(OCINumber *s, OCIError *errhp);
456
+ VALUE oci8_make_float(OCINumber *s, OCIError *errhp);
457
+ OCINumber *oci8_set_ocinumber(OCINumber *result, VALUE self, OCIError *errhp);
458
+ OCINumber *oci8_set_integer(OCINumber *result, VALUE self, OCIError *errhp);
405
459
 
406
460
  /* ocidatetim.c */
407
461
  void Init_oci_datetime(void);
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2002-2008 KUBO Takehiro <kubo@jiubao.org>
3
+ * Copyright (C) 2002-2009 KUBO Takehiro <kubo@jiubao.org>
4
4
  */
5
5
 
6
6
  #include "oci8.h"
@@ -66,7 +66,7 @@ static void oci8_handle_mark(oci8_base_t *base)
66
66
  static void oci8_handle_cleanup(oci8_base_t *base)
67
67
  {
68
68
  oci8_base_free(base);
69
- free(base);
69
+ xfree(base);
70
70
  }
71
71
 
72
72
  static VALUE oci8_s_allocate(VALUE klass)
@@ -108,6 +108,9 @@ Init_oci8lib()
108
108
  {
109
109
  VALUE cOCI8;
110
110
  VALUE obj;
111
+ OCIEnv *envhp;
112
+ OCIError *errhp;
113
+ sword rv;
111
114
 
112
115
  #ifdef RUNTIME_API_CHECK
113
116
  Init_oci8_apiwrap();
@@ -154,8 +157,35 @@ Init_oci8lib()
154
157
  Init_oci8_metadata(cOCI8);
155
158
  Init_oci8_lob(cOCI8);
156
159
 
160
+ /* allocate a temporary errhp to pass Init_oci_number() */
161
+ if (have_OCIEnvCreate) {
162
+ rv = OCIEnvCreate(&envhp, oci8_env_mode, NULL, NULL, NULL, NULL, 0, NULL);
163
+ if (rv != OCI_SUCCESS) {
164
+ oci8_raise_init_error();
165
+ }
166
+ } else {
167
+ rv = OCIInitialize(oci8_env_mode, NULL, NULL, NULL, NULL);
168
+ if (rv != OCI_SUCCESS) {
169
+ oci8_raise_init_error();
170
+ }
171
+ rv = OCIEnvInit(&envhp, OCI_DEFAULT, 0, NULL);
172
+ if (rv != OCI_SUCCESS) {
173
+ oci8_raise_init_error();
174
+ }
175
+ }
176
+ rv = OCIHandleAlloc(envhp, (dvoid *)&errhp, OCI_HTYPE_ERROR, 0, NULL);
177
+ if (rv != OCI_SUCCESS)
178
+ oci8_env_raise(envhp, rv);
179
+ Init_oci_number(cOCI8, errhp);
180
+ OCIHandleFree(errhp, OCI_HTYPE_ERROR);
181
+ if (have_OCIEnvCreate) {
182
+ OCIHandleFree(envhp, OCI_HTYPE_ENV);
183
+ } else {
184
+ /* Delayed OCIEnv initialization cannot be used on Oracle 8.0. */
185
+ oci8_global_envhp = envhp;
186
+ }
187
+
157
188
  Init_ora_date();
158
- Init_oci_number(cOCI8);
159
189
  Init_oci_datetime();
160
190
  Init_oci_object(cOCI8);
161
191
  Init_oci_xmldb();
@@ -167,6 +197,10 @@ Init_oci8lib()
167
197
  #ifdef DEBUG_CORE_FILE
168
198
  signal(SIGSEGV, SIG_DFL);
169
199
  #endif
200
+
201
+ if (have_OCIEnvCreate && oci8_global_envhp != NULL) {
202
+ rb_raise(rb_eRuntimeError, "Internal Error: OCIEnv should not be initialized here.");
203
+ }
170
204
  }
171
205
 
172
206
  VALUE oci8_define_class(const char *name, oci8_base_class_t *base_class)
@@ -3,7 +3,7 @@
3
3
  * ocidatetime.c
4
4
  *
5
5
  * $Author: kubo $
6
- * $Date: 2009-02-15 23:58:37 +0900 (Sun, 15 Feb 2009) $
6
+ * $Date: 2009-05-17 22:07:16 +0900 (Sun, 17 May 2009) $
7
7
  *
8
8
  * Copyright (C) 2005-2008 KUBO Takehiro <kubo@jiubao.org>
9
9
  *
@@ -2,10 +2,7 @@
2
2
  /*
3
3
  * ocinumber.c
4
4
  *
5
- * $Author: kubo $
6
- * $Date: 2009-01-12 00:11:09 +0900 (Mon, 12 Jan 2009) $
7
- *
8
- * Copyright (C) 2005-2008 KUBO Takehiro <kubo@jiubao.org>
5
+ * Copyright (C) 2005-2009 KUBO Takehiro <kubo@jiubao.org>
9
6
  *
10
7
  */
11
8
  #include "oci8.h"
@@ -20,6 +17,10 @@
20
17
 
21
18
  static ID id_power; /* rb_intern("**") */
22
19
  static ID id_cmp; /* rb_intern("<=>") */
20
+ static ID id_finite_p;
21
+ static ID id_split;
22
+ static ID id_numerator;
23
+ static ID id_denominator;
23
24
 
24
25
  static VALUE cOCINumber;
25
26
  static OCINumber const_p1; /* +1 */
@@ -61,40 +62,40 @@ static VALUE onum_s_alloc(VALUE klass)
61
62
  }
62
63
 
63
64
  /* construct an ruby object(OCI::Number) from C structure (OCINumber). */
64
- VALUE oci8_make_ocinumber(OCINumber *s)
65
+ VALUE oci8_make_ocinumber(OCINumber *s, OCIError *errhp)
65
66
  {
66
67
  VALUE obj;
67
68
  OCINumber *d;
68
69
 
69
70
  obj = Data_Make_Struct(cOCINumber, OCINumber, NULL, xfree, d);
70
- oci_lc(OCINumberAssign(oci8_errhp, s, d));
71
+ oci_lc(OCINumberAssign(errhp, s, d));
71
72
  return obj;
72
73
  }
73
74
 
74
- VALUE oci8_make_integer(OCINumber *s)
75
+ VALUE oci8_make_integer(OCINumber *s, OCIError *errhp)
75
76
  {
76
77
  signed long sl;
77
78
  char buf[512];
78
79
  ub4 buf_size = sizeof(buf);
79
80
 
80
- if (OCINumberToInt(oci8_errhp, s, sizeof(sl), OCI_NUMBER_SIGNED, &sl) == OCI_SUCCESS) {
81
+ if (OCINumberToInt(errhp, s, sizeof(sl), OCI_NUMBER_SIGNED, &sl) == OCI_SUCCESS) {
81
82
  return LONG2NUM(sl);
82
83
  }
83
- oci_lc(OCINumberToText(oci8_errhp, s, NUMBER_FORMAT2, NUMBER_FORMAT2_LEN,
84
+ oci_lc(OCINumberToText(errhp, s, NUMBER_FORMAT2, NUMBER_FORMAT2_LEN,
84
85
  NULL, 0, &buf_size, TO_ORATEXT(buf)));
85
86
  return rb_cstr2inum(buf, 10);
86
87
  }
87
88
 
88
- VALUE oci8_make_float(OCINumber *s)
89
+ VALUE oci8_make_float(OCINumber *s, OCIError *errhp)
89
90
  {
90
91
  double dbl;
91
92
 
92
- oci_lc(OCINumberToReal(oci8_errhp, s, sizeof(double), &dbl));
93
+ oci_lc(OCINumberToReal(errhp, s, sizeof(double), &dbl));
93
94
  return rb_float_new(dbl);
94
95
  }
95
96
 
96
97
  /* fill C structure (OCINumber) from a string. */
97
- static void set_oci_number_from_str(OCINumber *result, VALUE str, VALUE fmt, VALUE nls_params)
98
+ static void set_oci_number_from_str(OCINumber *result, VALUE str, VALUE fmt, VALUE nls_params, OCIError *errhp)
98
99
  {
99
100
  oratext *fmt_ptr;
100
101
  oratext *nls_params_ptr;
@@ -135,7 +136,7 @@ static void set_oci_number_from_str(OCINumber *result, VALUE str, VALUE fmt, VAL
135
136
  nls_params_ptr = RSTRING_ORATEXT(nls_params);
136
137
  nls_params_len = RSTRING_LEN(nls_params);
137
138
  }
138
- oci_lc(OCINumberFromText(oci8_errhp,
139
+ oci_lc(OCINumberFromText(errhp,
139
140
  RSTRING_ORATEXT(str), RSTRING_LEN(str),
140
141
  fmt_ptr, fmt_len, nls_params_ptr, nls_params_len,
141
142
  result));
@@ -143,56 +144,128 @@ static void set_oci_number_from_str(OCINumber *result, VALUE str, VALUE fmt, VAL
143
144
 
144
145
  /* fill C structure (OCINumber) from a numeric object. */
145
146
  /* 1 - success, 0 - error */
146
- static int set_oci_number_from_num(OCINumber *result, VALUE num, int force)
147
+ static int set_oci_number_from_num(OCINumber *result, VALUE num, int force, OCIError *errhp)
147
148
  {
148
149
  signed long sl;
149
150
  double dbl;
150
151
 
151
152
  if (!RTEST(rb_obj_is_kind_of(num, rb_cNumeric)))
152
153
  rb_raise(rb_eTypeError, "expect Numeric but %s", rb_class2name(CLASS_OF(num)));
154
+ if (rb_respond_to(num, id_finite_p) && !RTEST(rb_funcall(num, id_finite_p, 0))) {
155
+ rb_raise(rb_eTypeError, "cannot accept number which isn't finite.");
156
+ }
153
157
  switch (rb_type(num)) {
154
158
  case T_FIXNUM:
155
159
  /* set from long. */
156
160
  sl = NUM2LONG(num);
157
- oci_lc(OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, result));
161
+ oci_lc(OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, result));
158
162
  return 1;
159
163
  case T_FLOAT:
160
164
  /* set from double. */
161
165
  dbl = NUM2DBL(num);
162
- oci_lc(OCINumberFromReal(oci8_errhp, &dbl, sizeof(dbl), result));
166
+ oci_lc(OCINumberFromReal(errhp, &dbl, sizeof(dbl), result));
163
167
  return 1;
164
168
  case T_BIGNUM:
165
169
  /* change via string. */
166
170
  num = rb_big2str(num, 10);
167
- set_oci_number_from_str(result, num, Qnil, Qnil);
171
+ set_oci_number_from_str(result, num, Qnil, Qnil, errhp);
168
172
  return 1;
169
173
  }
170
174
  if (RTEST(rb_obj_is_instance_of(num, cOCINumber))) {
171
175
  /* OCI::Number */
172
- oci_lc(OCINumberAssign(oci8_errhp, DATA_PTR(num), result));
176
+ oci_lc(OCINumberAssign(errhp, DATA_PTR(num), result));
173
177
  return 1;
174
178
  }
179
+ if (rb_respond_to(num, id_split)) {
180
+ /* BigDecimal */
181
+ VALUE split = rb_funcall(num, id_split, 0);
182
+
183
+ if (TYPE(split) == T_ARRAY && RARRAY_LEN(split) == 4) {
184
+ /*
185
+ * sign, significant_digits, base, exponent = num.split
186
+ * onum = sign * "0.#{significant_digits}".to_f * (base ** exponent)
187
+ */
188
+ VALUE *ary = RARRAY_PTR(split);
189
+ int sign;
190
+ OCINumber digits;
191
+ int exponent;
192
+ int digits_len;
193
+ OCINumber work;
194
+
195
+ /* check sign */
196
+ if (TYPE(ary[0]) != T_FIXNUM) {
197
+ goto is_not_big_decimal;
198
+ }
199
+ sign = FIX2INT(ary[0]);
200
+ /* check digits */
201
+ StringValue(ary[1]);
202
+ digits_len = RSTRING_LEN(ary[1]);
203
+ set_oci_number_from_str(&digits, ary[1], Qnil, Qnil, errhp);
204
+ /* check base */
205
+ if (TYPE(ary[2]) != T_FIXNUM || FIX2LONG(ary[2]) != 10) {
206
+ goto is_not_big_decimal;
207
+ }
208
+ /* check exponent */
209
+ if (TYPE(ary[3]) != T_FIXNUM) {
210
+ goto is_not_big_decimal;
211
+ }
212
+ exponent = FIX2INT(ary[3]);
213
+
214
+ if (have_OCINumberShift) {
215
+ /* Oracle 8.1 or upper */
216
+ oci_lc(OCINumberShift(errhp, &digits, exponent - digits_len, &work));
217
+ } else {
218
+ /* Oracle 8.0 */
219
+ int n = 10;
220
+ OCINumber base;
221
+ OCINumber exp;
222
+
223
+ oci_lc(OCINumberFromInt(errhp, &n, sizeof(n), OCI_NUMBER_SIGNED, &base));
224
+ oci_lc(OCINumberIntPower(errhp, &base, exponent - digits_len, &exp));
225
+ oci_lc(OCINumberMul(errhp, &digits, &exp, &work));
226
+ }
227
+ if (sign >= 0) {
228
+ oci_lc(OCINumberAssign(errhp, &work, result));
229
+ } else {
230
+ oci_lc(OCINumberNeg(errhp, &work, result));
231
+ }
232
+ return 1;
233
+ }
234
+ }
235
+ is_not_big_decimal:
236
+ if (rb_respond_to(num, id_numerator) && rb_respond_to(num, id_denominator)) {
237
+ /* Rational */
238
+ OCINumber numerator;
239
+ OCINumber denominator;
240
+
241
+ if (set_oci_number_from_num(&numerator, rb_funcall(num, id_numerator, 0), 0, errhp) &&
242
+ set_oci_number_from_num(&denominator, rb_funcall(num, id_denominator, 0), 0, errhp)) {
243
+ oci_lc(OCINumberDiv(errhp, &numerator, &denominator, result));
244
+ return 1;
245
+ }
246
+ }
175
247
  if (force) {
176
248
  /* change via string as a last resort. */
177
249
  /* TODO: if error, raise TypeError instead of OCI::Error */
178
- set_oci_number_from_str(result, num, Qnil, Qnil);
250
+ set_oci_number_from_str(result, num, Qnil, Qnil, errhp);
179
251
  return 1;
180
252
  }
181
253
  return 0;
182
254
  }
183
255
 
184
- OCINumber *oci8_set_ocinumber(OCINumber *result, VALUE self)
256
+ OCINumber *oci8_set_ocinumber(OCINumber *result, VALUE self, OCIError *errhp)
185
257
  {
186
- set_oci_number_from_num(result, self, 1);
258
+ set_oci_number_from_num(result, self, 1, errhp);
187
259
  return result;
188
260
  }
189
- #define TO_OCINUM(on, val) oci8_set_ocinumber((on), (val))
261
+ #define TO_OCINUM oci8_set_ocinumber
190
262
 
191
- OCINumber *oci8_set_integer(OCINumber *result, VALUE self)
263
+ OCINumber *oci8_set_integer(OCINumber *result, VALUE self, OCIError *errhp)
192
264
  {
193
265
  OCINumber work;
194
- set_oci_number_from_num(&work, self, 1);
195
- oci_lc(OCINumberTrunc(oci8_errhp, &work, 0, result));
266
+
267
+ set_oci_number_from_num(&work, self, 1, errhp);
268
+ oci_lc(OCINumberTrunc(errhp, &work, 0, result));
196
269
  return result;
197
270
  }
198
271
 
@@ -205,30 +278,31 @@ OCINumber *oci8_set_integer(OCINumber *result, VALUE self)
205
278
  */
206
279
  static VALUE omath_atan2(VALUE self, VALUE Ycoordinate, VALUE Xcoordinate)
207
280
  {
281
+ OCIError *errhp = oci8_errhp;
208
282
  OCINumber nY;
209
283
  OCINumber nX;
210
284
  OCINumber rv;
211
285
  boolean is_zero;
212
286
  sword sign;
213
287
 
214
- set_oci_number_from_num(&nX, Xcoordinate, 1);
215
- set_oci_number_from_num(&nY, Ycoordinate, 1);
288
+ set_oci_number_from_num(&nX, Xcoordinate, 1, errhp);
289
+ set_oci_number_from_num(&nY, Ycoordinate, 1, errhp);
216
290
  /* check zero */
217
- oci_lc(OCINumberIsZero(oci8_errhp, &nX, &is_zero));
291
+ oci_lc(OCINumberIsZero(errhp, &nX, &is_zero));
218
292
  if (is_zero) {
219
- oci_lc(OCINumberSign(oci8_errhp, &nY, &sign));
293
+ oci_lc(OCINumberSign(errhp, &nY, &sign));
220
294
  switch (sign) {
221
295
  case 0:
222
296
  return INT2FIX(0); /* atan2(0, 0) => 0 or ERROR? */
223
297
  case 1:
224
- return oci8_make_ocinumber(&const_PI2); /* atan2(positive, 0) => PI/2 */
298
+ return oci8_make_ocinumber(&const_PI2, errhp); /* atan2(positive, 0) => PI/2 */
225
299
  case -1:
226
- return oci8_make_ocinumber(&const_mPI2); /* atan2(negative, 0) => -PI/2 */
300
+ return oci8_make_ocinumber(&const_mPI2, errhp); /* atan2(negative, 0) => -PI/2 */
227
301
  }
228
302
  }
229
303
  /* atan2 */
230
- oci_lc(OCINumberArcTan2(oci8_errhp, &nY, &nX, &rv));
231
- return oci8_make_ocinumber(&rv);
304
+ oci_lc(OCINumberArcTan2(errhp, &nY, &nX, &rv));
305
+ return oci8_make_ocinumber(&rv, errhp);
232
306
  }
233
307
 
234
308
  /*
@@ -240,11 +314,12 @@ static VALUE omath_atan2(VALUE self, VALUE Ycoordinate, VALUE Xcoordinate)
240
314
  */
241
315
  static VALUE omath_cos(VALUE obj, VALUE radian)
242
316
  {
317
+ OCIError *errhp = oci8_errhp;
243
318
  OCINumber r;
244
319
  OCINumber rv;
245
320
 
246
- oci_lc(OCINumberCos(oci8_errhp, TO_OCINUM(&r, radian), &rv));
247
- return oci8_make_ocinumber(&rv);
321
+ oci_lc(OCINumberCos(errhp, TO_OCINUM(&r, radian, errhp), &rv));
322
+ return oci8_make_ocinumber(&rv, errhp);
248
323
  }
249
324
 
250
325
  /*
@@ -256,11 +331,12 @@ static VALUE omath_cos(VALUE obj, VALUE radian)
256
331
  */
257
332
  static VALUE omath_sin(VALUE obj, VALUE radian)
258
333
  {
334
+ OCIError *errhp = oci8_errhp;
259
335
  OCINumber r;
260
336
  OCINumber rv;
261
337
 
262
- oci_lc(OCINumberSin(oci8_errhp, TO_OCINUM(&r, radian), &rv));
263
- return oci8_make_ocinumber(&rv);
338
+ oci_lc(OCINumberSin(errhp, TO_OCINUM(&r, radian, errhp), &rv));
339
+ return oci8_make_ocinumber(&rv, errhp);
264
340
  }
265
341
 
266
342
  /*
@@ -271,11 +347,12 @@ static VALUE omath_sin(VALUE obj, VALUE radian)
271
347
  */
272
348
  static VALUE omath_tan(VALUE obj, VALUE radian)
273
349
  {
350
+ OCIError *errhp = oci8_errhp;
274
351
  OCINumber r;
275
352
  OCINumber rv;
276
353
 
277
- oci_lc(OCINumberTan(oci8_errhp, TO_OCINUM(&r, radian), &rv));
278
- return oci8_make_ocinumber(&rv);
354
+ oci_lc(OCINumberTan(errhp, TO_OCINUM(&r, radian, errhp), &rv));
355
+ return oci8_make_ocinumber(&rv, errhp);
279
356
  }
280
357
 
281
358
  /*
@@ -286,22 +363,23 @@ static VALUE omath_tan(VALUE obj, VALUE radian)
286
363
  */
287
364
  static VALUE omath_acos(VALUE obj, VALUE num)
288
365
  {
366
+ OCIError *errhp = oci8_errhp;
289
367
  OCINumber n;
290
368
  OCINumber r;
291
369
  sword sign;
292
370
 
293
- set_oci_number_from_num(&n, num, 1);
371
+ set_oci_number_from_num(&n, num, 1, errhp);
294
372
  /* check upper bound */
295
- oci_lc(OCINumberCmp(oci8_errhp, &n, &const_p1, &sign));
373
+ oci_lc(OCINumberCmp(errhp, &n, &const_p1, &sign));
296
374
  if (sign > 0)
297
375
  rb_raise(rb_eRangeError, "out of range for acos");
298
376
  /* check lower bound */
299
- oci_lc(OCINumberCmp(oci8_errhp, &n, &const_m1, &sign));
377
+ oci_lc(OCINumberCmp(errhp, &n, &const_m1, &sign));
300
378
  if (sign < 0)
301
379
  rb_raise(rb_eRangeError, "out of range for acos");
302
380
  /* acos */
303
- oci_lc(OCINumberArcCos(oci8_errhp, &n, &r));
304
- return oci8_make_ocinumber(&r);
381
+ oci_lc(OCINumberArcCos(errhp, &n, &r));
382
+ return oci8_make_ocinumber(&r, errhp);
305
383
  }
306
384
 
307
385
  /*
@@ -312,22 +390,23 @@ static VALUE omath_acos(VALUE obj, VALUE num)
312
390
  */
313
391
  static VALUE omath_asin(VALUE obj, VALUE num)
314
392
  {
393
+ OCIError *errhp = oci8_errhp;
315
394
  OCINumber n;
316
395
  OCINumber r;
317
396
  sword sign;
318
397
 
319
- set_oci_number_from_num(&n, num, 1);
398
+ set_oci_number_from_num(&n, num, 1, errhp);
320
399
  /* check upper bound */
321
- oci_lc(OCINumberCmp(oci8_errhp, &n, &const_p1, &sign));
400
+ oci_lc(OCINumberCmp(errhp, &n, &const_p1, &sign));
322
401
  if (sign > 0)
323
402
  rb_raise(rb_eRangeError, "out of range for asin");
324
403
  /* check lower bound */
325
- oci_lc(OCINumberCmp(oci8_errhp, &n, &const_m1, &sign));
404
+ oci_lc(OCINumberCmp(errhp, &n, &const_m1, &sign));
326
405
  if (sign < 0)
327
406
  rb_raise(rb_eRangeError, "out of range for asin");
328
407
  /* asin */
329
- oci_lc(OCINumberArcSin(oci8_errhp, &n, &r));
330
- return oci8_make_ocinumber(&r);
408
+ oci_lc(OCINumberArcSin(errhp, &n, &r));
409
+ return oci8_make_ocinumber(&r, errhp);
331
410
  }
332
411
 
333
412
  /*
@@ -338,11 +417,12 @@ static VALUE omath_asin(VALUE obj, VALUE num)
338
417
  */
339
418
  static VALUE omath_atan(VALUE obj, VALUE num)
340
419
  {
420
+ OCIError *errhp = oci8_errhp;
341
421
  OCINumber n;
342
422
  OCINumber r;
343
423
 
344
- oci_lc(OCINumberArcTan(oci8_errhp, TO_OCINUM(&n, num), &r));
345
- return oci8_make_ocinumber(&r);
424
+ oci_lc(OCINumberArcTan(errhp, TO_OCINUM(&n, num, errhp), &r));
425
+ return oci8_make_ocinumber(&r, errhp);
346
426
  }
347
427
 
348
428
  /*
@@ -353,11 +433,12 @@ static VALUE omath_atan(VALUE obj, VALUE num)
353
433
  */
354
434
  static VALUE omath_cosh(VALUE obj, VALUE num)
355
435
  {
436
+ OCIError *errhp = oci8_errhp;
356
437
  OCINumber n;
357
438
  OCINumber r;
358
439
 
359
- oci_lc(OCINumberHypCos(oci8_errhp, TO_OCINUM(&n, num), &r));
360
- return oci8_make_ocinumber(&r);
440
+ oci_lc(OCINumberHypCos(errhp, TO_OCINUM(&n, num, errhp), &r));
441
+ return oci8_make_ocinumber(&r, errhp);
361
442
  }
362
443
 
363
444
  /*
@@ -369,11 +450,12 @@ static VALUE omath_cosh(VALUE obj, VALUE num)
369
450
  */
370
451
  static VALUE omath_sinh(VALUE obj, VALUE num)
371
452
  {
453
+ OCIError *errhp = oci8_errhp;
372
454
  OCINumber n;
373
455
  OCINumber r;
374
456
 
375
- oci_lc(OCINumberHypSin(oci8_errhp, TO_OCINUM(&n, num), &r));
376
- return oci8_make_ocinumber(&r);
457
+ oci_lc(OCINumberHypSin(errhp, TO_OCINUM(&n, num, errhp), &r));
458
+ return oci8_make_ocinumber(&r, errhp);
377
459
  }
378
460
 
379
461
  /*
@@ -385,11 +467,12 @@ static VALUE omath_sinh(VALUE obj, VALUE num)
385
467
  */
386
468
  static VALUE omath_tanh(VALUE obj, VALUE num)
387
469
  {
470
+ OCIError *errhp = oci8_errhp;
388
471
  OCINumber n;
389
472
  OCINumber r;
390
473
 
391
- oci_lc(OCINumberHypTan(oci8_errhp, TO_OCINUM(&n, num), &r));
392
- return oci8_make_ocinumber(&r);
474
+ oci_lc(OCINumberHypTan(errhp, TO_OCINUM(&n, num, errhp), &r));
475
+ return oci8_make_ocinumber(&r, errhp);
393
476
  }
394
477
 
395
478
  /*
@@ -400,11 +483,12 @@ static VALUE omath_tanh(VALUE obj, VALUE num)
400
483
  */
401
484
  static VALUE omath_exp(VALUE obj, VALUE num)
402
485
  {
486
+ OCIError *errhp = oci8_errhp;
403
487
  OCINumber n;
404
488
  OCINumber r;
405
489
 
406
- oci_lc(OCINumberExp(oci8_errhp, TO_OCINUM(&n, num), &r));
407
- return oci8_make_ocinumber(&r);
490
+ oci_lc(OCINumberExp(errhp, TO_OCINUM(&n, num, errhp), &r));
491
+ return oci8_make_ocinumber(&r, errhp);
408
492
  }
409
493
 
410
494
  /*
@@ -417,6 +501,7 @@ static VALUE omath_exp(VALUE obj, VALUE num)
417
501
  */
418
502
  static VALUE omath_log(int argc, VALUE *argv, VALUE obj)
419
503
  {
504
+ OCIError *errhp = oci8_errhp;
420
505
  VALUE num, base;
421
506
  OCINumber n;
422
507
  OCINumber b;
@@ -424,23 +509,23 @@ static VALUE omath_log(int argc, VALUE *argv, VALUE obj)
424
509
  sword sign;
425
510
 
426
511
  rb_scan_args(argc, argv, "11", &num, &base);
427
- set_oci_number_from_num(&n, num, 1);
428
- oci_lc(OCINumberSign(oci8_errhp, &n, &sign));
512
+ set_oci_number_from_num(&n, num, 1, errhp);
513
+ oci_lc(OCINumberSign(errhp, &n, &sign));
429
514
  if (sign <= 0)
430
515
  rb_raise(rb_eRangeError, "nonpositive value for log");
431
516
  if (NIL_P(base)) {
432
- oci_lc(OCINumberLn(oci8_errhp, &n, &r));
517
+ oci_lc(OCINumberLn(errhp, &n, &r));
433
518
  } else {
434
- set_oci_number_from_num(&b, base, 1);
435
- oci_lc(OCINumberSign(oci8_errhp, &b, &sign));
519
+ set_oci_number_from_num(&b, base, 1, errhp);
520
+ oci_lc(OCINumberSign(errhp, &b, &sign));
436
521
  if (sign <= 0)
437
522
  rb_raise(rb_eRangeError, "nonpositive value for the base of log");
438
- oci_lc(OCINumberCmp(oci8_errhp, &b, &const_p1, &sign));
523
+ oci_lc(OCINumberCmp(errhp, &b, &const_p1, &sign));
439
524
  if (sign == 0)
440
525
  rb_raise(rb_eRangeError, "base 1 for log");
441
- oci_lc(OCINumberLog(oci8_errhp, &b, &n, &r));
526
+ oci_lc(OCINumberLog(errhp, &b, &n, &r));
442
527
  }
443
- return oci8_make_ocinumber(&r);
528
+ return oci8_make_ocinumber(&r, errhp);
444
529
  }
445
530
 
446
531
  /*
@@ -451,16 +536,17 @@ static VALUE omath_log(int argc, VALUE *argv, VALUE obj)
451
536
  */
452
537
  static VALUE omath_log10(VALUE obj, VALUE num)
453
538
  {
539
+ OCIError *errhp = oci8_errhp;
454
540
  OCINumber n;
455
541
  OCINumber r;
456
542
  sword sign;
457
543
 
458
- set_oci_number_from_num(&n, num, 1);
459
- oci_lc(OCINumberSign(oci8_errhp, &n, &sign));
544
+ set_oci_number_from_num(&n, num, 1, errhp);
545
+ oci_lc(OCINumberSign(errhp, &n, &sign));
460
546
  if (sign <= 0)
461
547
  rb_raise(rb_eRangeError, "nonpositive value for log10");
462
- oci_lc(OCINumberLog(oci8_errhp, &const_p10, &n, &r));
463
- return oci8_make_ocinumber(&r);
548
+ oci_lc(OCINumberLog(errhp, &const_p10, &n, &r));
549
+ return oci8_make_ocinumber(&r, errhp);
464
550
  }
465
551
 
466
552
  /*
@@ -471,33 +557,35 @@ static VALUE omath_log10(VALUE obj, VALUE num)
471
557
  */
472
558
  static VALUE omath_sqrt(VALUE obj, VALUE num)
473
559
  {
560
+ OCIError *errhp = oci8_errhp;
474
561
  OCINumber n;
475
562
  OCINumber r;
476
563
  sword sign;
477
564
 
478
- set_oci_number_from_num(&n, num, 1);
565
+ set_oci_number_from_num(&n, num, 1, errhp);
479
566
  /* check whether num is negative */
480
- oci_lc(OCINumberSign(oci8_errhp, &n, &sign));
567
+ oci_lc(OCINumberSign(errhp, &n, &sign));
481
568
  if (sign < 0) {
482
569
  errno = EDOM;
483
570
  rb_sys_fail("sqrt");
484
571
  }
485
- oci_lc(OCINumberSqrt(oci8_errhp, &n, &r));
486
- return oci8_make_ocinumber(&r);
572
+ oci_lc(OCINumberSqrt(errhp, &n, &r));
573
+ return oci8_make_ocinumber(&r, errhp);
487
574
  }
488
575
 
489
576
  static VALUE onum_initialize(int argc, VALUE *argv, VALUE self)
490
577
  {
578
+ OCIError *errhp = oci8_errhp;
491
579
  VALUE val;
492
580
  VALUE fmt;
493
581
  VALUE nls_params;
494
582
 
495
583
  if (rb_scan_args(argc, argv, "03", &val /* 0 */, &fmt /* nil */, &nls_params /* nil */) == 0) {
496
- OCINumberSetZero(oci8_errhp, _NUMBER(self));
584
+ OCINumberSetZero(errhp, _NUMBER(self));
497
585
  } else if (RTEST(rb_obj_is_kind_of(val, rb_cNumeric))) {
498
- set_oci_number_from_num(_NUMBER(self), val, 1);
586
+ set_oci_number_from_num(_NUMBER(self), val, 1, errhp);
499
587
  } else {
500
- set_oci_number_from_str(_NUMBER(self), val, fmt, nls_params);
588
+ set_oci_number_from_str(_NUMBER(self), val, fmt, nls_params, errhp);
501
589
  }
502
590
  return Qnil;
503
591
  }
@@ -514,11 +602,12 @@ static VALUE onum_initialize_copy(VALUE lhs, VALUE rhs)
514
602
 
515
603
  static VALUE onum_coerce(VALUE self, VALUE other)
516
604
  {
605
+ OCIError *errhp = oci8_errhp;
517
606
  OCINumber n;
518
607
 
519
608
  if (RTEST(rb_obj_is_kind_of(other, rb_cNumeric)))
520
- if (set_oci_number_from_num(&n, other, 0))
521
- return rb_assoc_new(oci8_make_ocinumber(&n), self);
609
+ if (set_oci_number_from_num(&n, other, 0, errhp))
610
+ return rb_assoc_new(oci8_make_ocinumber(&n, errhp), self);
522
611
  rb_raise(rb_eTypeError, "Can't coerce %s to %s",
523
612
  rb_class2name(CLASS_OF(other)), rb_class2name(cOCINumber));
524
613
  }
@@ -531,10 +620,11 @@ static VALUE onum_coerce(VALUE self, VALUE other)
531
620
  */
532
621
  static VALUE onum_neg(VALUE self)
533
622
  {
623
+ OCIError *errhp = oci8_errhp;
534
624
  OCINumber r;
535
625
 
536
- oci_lc(OCINumberNeg(oci8_errhp, _NUMBER(self), &r));
537
- return oci8_make_ocinumber(&r);
626
+ oci_lc(OCINumberNeg(errhp, _NUMBER(self), &r));
627
+ return oci8_make_ocinumber(&r, errhp);
538
628
  }
539
629
 
540
630
  /*
@@ -546,15 +636,16 @@ static VALUE onum_neg(VALUE self)
546
636
  */
547
637
  static VALUE onum_add(VALUE lhs, VALUE rhs)
548
638
  {
639
+ OCIError *errhp = oci8_errhp;
549
640
  OCINumber n;
550
641
  OCINumber r;
551
642
 
552
643
  /* change to OCINumber */
553
- if (!set_oci_number_from_num(&n, rhs, 0))
644
+ if (!set_oci_number_from_num(&n, rhs, 0, errhp))
554
645
  return rb_num_coerce_bin(lhs, rhs, '+');
555
646
  /* add */
556
- oci_lc(OCINumberAdd(oci8_errhp, _NUMBER(lhs), &n, &r));
557
- return oci8_make_ocinumber(&r);
647
+ oci_lc(OCINumberAdd(errhp, _NUMBER(lhs), &n, &r));
648
+ return oci8_make_ocinumber(&r, errhp);
558
649
  }
559
650
 
560
651
  /*
@@ -566,15 +657,16 @@ static VALUE onum_add(VALUE lhs, VALUE rhs)
566
657
  */
567
658
  static VALUE onum_sub(VALUE lhs, VALUE rhs)
568
659
  {
660
+ OCIError *errhp = oci8_errhp;
569
661
  OCINumber n;
570
662
  OCINumber r;
571
663
 
572
664
  /* change to OCINumber */
573
- if (!set_oci_number_from_num(&n, rhs, 0))
665
+ if (!set_oci_number_from_num(&n, rhs, 0, errhp))
574
666
  return rb_num_coerce_bin(lhs, rhs, '-');
575
667
  /* subtracting */
576
- oci_lc(OCINumberSub(oci8_errhp, _NUMBER(lhs), &n, &r));
577
- return oci8_make_ocinumber(&r);
668
+ oci_lc(OCINumberSub(errhp, _NUMBER(lhs), &n, &r));
669
+ return oci8_make_ocinumber(&r, errhp);
578
670
  }
579
671
 
580
672
  /*
@@ -586,15 +678,16 @@ static VALUE onum_sub(VALUE lhs, VALUE rhs)
586
678
  */
587
679
  static VALUE onum_mul(VALUE lhs, VALUE rhs)
588
680
  {
681
+ OCIError *errhp = oci8_errhp;
589
682
  OCINumber n;
590
683
  OCINumber r;
591
684
 
592
685
  /* change to OCINumber */
593
- if (!set_oci_number_from_num(&n, rhs, 0))
686
+ if (!set_oci_number_from_num(&n, rhs, 0, errhp))
594
687
  return rb_num_coerce_bin(lhs, rhs, '*');
595
688
  /* multiply */
596
- oci_lc(OCINumberMul(oci8_errhp, _NUMBER(lhs), &n, &r));
597
- return oci8_make_ocinumber(&r);
689
+ oci_lc(OCINumberMul(errhp, _NUMBER(lhs), &n, &r));
690
+ return oci8_make_ocinumber(&r, errhp);
598
691
  }
599
692
 
600
693
  /*
@@ -606,20 +699,21 @@ static VALUE onum_mul(VALUE lhs, VALUE rhs)
606
699
  */
607
700
  static VALUE onum_div(VALUE lhs, VALUE rhs)
608
701
  {
702
+ OCIError *errhp = oci8_errhp;
609
703
  OCINumber n;
610
704
  OCINumber r;
611
705
  boolean is_zero;
612
706
 
613
707
  /* change to OCINumber */
614
- if (!set_oci_number_from_num(&n, rhs, 0))
708
+ if (!set_oci_number_from_num(&n, rhs, 0, errhp))
615
709
  return rb_num_coerce_bin(lhs, rhs, '/');
616
710
  /* check whether argument is not zero. */
617
- oci_lc(OCINumberIsZero(oci8_errhp, &n, &is_zero));
711
+ oci_lc(OCINumberIsZero(errhp, &n, &is_zero));
618
712
  if (is_zero)
619
713
  rb_num_zerodiv();
620
714
  /* division */
621
- oci_lc(OCINumberDiv(oci8_errhp, _NUMBER(lhs), &n, &r));
622
- return oci8_make_ocinumber(&r);
715
+ oci_lc(OCINumberDiv(errhp, _NUMBER(lhs), &n, &r));
716
+ return oci8_make_ocinumber(&r, errhp);
623
717
  }
624
718
 
625
719
  /*
@@ -630,20 +724,21 @@ static VALUE onum_div(VALUE lhs, VALUE rhs)
630
724
  */
631
725
  static VALUE onum_mod(VALUE lhs, VALUE rhs)
632
726
  {
727
+ OCIError *errhp = oci8_errhp;
633
728
  OCINumber n;
634
729
  OCINumber r;
635
730
  boolean is_zero;
636
731
 
637
732
  /* change to OCINumber */
638
- if (!set_oci_number_from_num(&n, rhs, 0))
733
+ if (!set_oci_number_from_num(&n, rhs, 0, errhp))
639
734
  return rb_num_coerce_bin(lhs, rhs, '%');
640
735
  /* check whether argument is not zero. */
641
- oci_lc(OCINumberIsZero(oci8_errhp, &n, &is_zero));
736
+ oci_lc(OCINumberIsZero(errhp, &n, &is_zero));
642
737
  if (is_zero)
643
738
  rb_num_zerodiv();
644
739
  /* modulo */
645
- oci_lc(OCINumberMod(oci8_errhp, _NUMBER(lhs), &n, &r));
646
- return oci8_make_ocinumber(&r);
740
+ oci_lc(OCINumberMod(errhp, _NUMBER(lhs), &n, &r));
741
+ return oci8_make_ocinumber(&r, errhp);
647
742
  }
648
743
 
649
744
  /*
@@ -654,18 +749,19 @@ static VALUE onum_mod(VALUE lhs, VALUE rhs)
654
749
  */
655
750
  static VALUE onum_power(VALUE lhs, VALUE rhs)
656
751
  {
752
+ OCIError *errhp = oci8_errhp;
657
753
  OCINumber n;
658
754
  OCINumber r;
659
755
 
660
756
  if (FIXNUM_P(rhs)) {
661
- oci_lc(OCINumberIntPower(oci8_errhp, _NUMBER(lhs), FIX2INT(rhs), &r));
757
+ oci_lc(OCINumberIntPower(errhp, _NUMBER(lhs), FIX2INT(rhs), &r));
662
758
  } else {
663
759
  /* change to OCINumber */
664
- if (!set_oci_number_from_num(&n, rhs, 0))
760
+ if (!set_oci_number_from_num(&n, rhs, 0, errhp))
665
761
  return rb_num_coerce_bin(lhs, rhs, id_power);
666
- oci_lc(OCINumberPower(oci8_errhp, _NUMBER(lhs), &n, &r));
762
+ oci_lc(OCINumberPower(errhp, _NUMBER(lhs), &n, &r));
667
763
  }
668
- return oci8_make_ocinumber(&r);
764
+ return oci8_make_ocinumber(&r, errhp);
669
765
  }
670
766
 
671
767
  /*
@@ -678,14 +774,15 @@ static VALUE onum_power(VALUE lhs, VALUE rhs)
678
774
  */
679
775
  static VALUE onum_cmp(VALUE lhs, VALUE rhs)
680
776
  {
777
+ OCIError *errhp = oci8_errhp;
681
778
  OCINumber n;
682
779
  sword r;
683
780
 
684
781
  /* change to OCINumber */
685
- if (!set_oci_number_from_num(&n, rhs, 0))
782
+ if (!set_oci_number_from_num(&n, rhs, 0, errhp))
686
783
  return rb_num_coerce_cmp(lhs, rhs, id_cmp);
687
784
  /* compare */
688
- oci_lc(OCINumberCmp(oci8_errhp, _NUMBER(lhs), &n, &r));
785
+ oci_lc(OCINumberCmp(errhp, _NUMBER(lhs), &n, &r));
689
786
  if (r > 0) {
690
787
  return INT2FIX(1);
691
788
  } else if (r == 0) {
@@ -703,10 +800,11 @@ static VALUE onum_cmp(VALUE lhs, VALUE rhs)
703
800
  */
704
801
  static VALUE onum_floor(VALUE self)
705
802
  {
803
+ OCIError *errhp = oci8_errhp;
706
804
  OCINumber r;
707
805
 
708
- oci_lc(OCINumberFloor(oci8_errhp, _NUMBER(self), &r));
709
- return oci8_make_integer(&r);
806
+ oci_lc(OCINumberFloor(errhp, _NUMBER(self), &r));
807
+ return oci8_make_integer(&r, errhp);
710
808
  }
711
809
 
712
810
  /*
@@ -718,10 +816,11 @@ static VALUE onum_floor(VALUE self)
718
816
  */
719
817
  static VALUE onum_ceil(VALUE self)
720
818
  {
819
+ OCIError *errhp = oci8_errhp;
721
820
  OCINumber r;
722
821
 
723
- oci_lc(OCINumberCeil(oci8_errhp, _NUMBER(self), &r));
724
- return oci8_make_integer(&r);
822
+ oci_lc(OCINumberCeil(errhp, _NUMBER(self), &r));
823
+ return oci8_make_integer(&r, errhp);
725
824
  }
726
825
 
727
826
  /*
@@ -738,15 +837,16 @@ static VALUE onum_ceil(VALUE self)
738
837
  */
739
838
  static VALUE onum_round(int argc, VALUE *argv, VALUE self)
740
839
  {
840
+ OCIError *errhp = oci8_errhp;
741
841
  VALUE decplace;
742
842
  OCINumber r;
743
843
 
744
844
  rb_scan_args(argc, argv, "01", &decplace /* 0 */);
745
- oci_lc(OCINumberRound(oci8_errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r));
845
+ oci_lc(OCINumberRound(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r));
746
846
  if (argc == 0) {
747
- return oci8_make_integer(&r);
847
+ return oci8_make_integer(&r, errhp);
748
848
  } else {
749
- return oci8_make_ocinumber(&r);
849
+ return oci8_make_ocinumber(&r, errhp);
750
850
  }
751
851
  }
752
852
 
@@ -760,12 +860,13 @@ static VALUE onum_round(int argc, VALUE *argv, VALUE self)
760
860
  */
761
861
  static VALUE onum_trunc(int argc, VALUE *argv, VALUE self)
762
862
  {
863
+ OCIError *errhp = oci8_errhp;
763
864
  VALUE decplace;
764
865
  OCINumber r;
765
866
 
766
867
  rb_scan_args(argc, argv, "01", &decplace /* 0 */);
767
- oci_lc(OCINumberTrunc(oci8_errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r));
768
- return oci8_make_ocinumber(&r);
868
+ oci_lc(OCINumberTrunc(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r));
869
+ return oci8_make_ocinumber(&r, errhp);
769
870
  }
770
871
 
771
872
  /*
@@ -781,10 +882,11 @@ static VALUE onum_trunc(int argc, VALUE *argv, VALUE self)
781
882
  */
782
883
  static VALUE onum_round_prec(VALUE self, VALUE ndigs)
783
884
  {
885
+ OCIError *errhp = oci8_errhp;
784
886
  OCINumber r;
785
887
 
786
- oci_lc(OCINumberPrec(oci8_errhp, _NUMBER(self), NUM2INT(ndigs), &r));
787
- return oci8_make_ocinumber(&r);
888
+ oci_lc(OCINumberPrec(errhp, _NUMBER(self), NUM2INT(ndigs), &r));
889
+ return oci8_make_ocinumber(&r, errhp);
788
890
  }
789
891
 
790
892
  /*
@@ -797,6 +899,7 @@ static VALUE onum_round_prec(VALUE self, VALUE ndigs)
797
899
  */
798
900
  static VALUE onum_to_char(int argc, VALUE *argv, VALUE self)
799
901
  {
902
+ OCIError *errhp = oci8_errhp;
800
903
  VALUE fmt;
801
904
  VALUE nls_params;
802
905
  char buf[512];
@@ -813,13 +916,13 @@ static VALUE onum_to_char(int argc, VALUE *argv, VALUE self)
813
916
  sword sign;
814
917
  boolean is_int;
815
918
 
816
- oci_lc(OCINumberIsInt(oci8_errhp, _NUMBER(self), &is_int));
919
+ oci_lc(OCINumberIsInt(errhp, _NUMBER(self), &is_int));
817
920
  if (is_int) {
818
921
  fmt_ptr = NUMBER_FORMAT_INT;
819
922
  fmt_len = NUMBER_FORMAT_INT_LEN;
820
923
  } else {
821
- oci_lc(OCINumberAbs(oci8_errhp, _NUMBER(self), &absval));
822
- oci_lc(OCINumberCmp(oci8_errhp, &absval, &const_shreshold, &sign));
924
+ oci_lc(OCINumberAbs(errhp, _NUMBER(self), &absval));
925
+ oci_lc(OCINumberCmp(errhp, &absval, &const_shreshold, &sign));
823
926
  if (sign >= 0) {
824
927
  fmt_ptr = NUMBER_FORMAT2;
825
928
  fmt_len = NUMBER_FORMAT2_LEN;
@@ -841,18 +944,18 @@ static VALUE onum_to_char(int argc, VALUE *argv, VALUE self)
841
944
  nls_params_ptr = RSTRING_ORATEXT(nls_params);
842
945
  nls_params_len = RSTRING_LEN(nls_params);
843
946
  }
844
- rv = OCINumberToText(oci8_errhp, _NUMBER(self),
947
+ rv = OCINumberToText(errhp, _NUMBER(self),
845
948
  fmt_ptr, fmt_len, nls_params_ptr, nls_params_len,
846
949
  &buf_size, TO_ORATEXT(buf));
847
950
  if (rv == OCI_ERROR) {
848
951
  sb4 errcode;
849
- OCIErrorGet(oci8_errhp, 1, NULL, &errcode, NULL, 0, OCI_HTYPE_ERROR);
952
+ OCIErrorGet(errhp, 1, NULL, &errcode, NULL, 0, OCI_HTYPE_ERROR);
850
953
  if (errcode == 22065) {
851
954
  /* OCI-22065: number to text translation for the given format causes overflow */
852
955
  if (NIL_P(fmt)) /* implicit conversion */
853
956
  return rb_usascii_str_new_cstr("overflow");
854
957
  }
855
- oci8_raise(oci8_errhp, rv, NULL);
958
+ oci8_raise(errhp, rv, NULL);
856
959
  }
857
960
  return rb_usascii_str_new(buf, buf_size);
858
961
  }
@@ -876,10 +979,11 @@ static VALUE onum_to_s(VALUE self)
876
979
  */
877
980
  static VALUE onum_to_i(VALUE self)
878
981
  {
982
+ OCIError *errhp = oci8_errhp;
879
983
  OCINumber num;
880
984
 
881
- oci_lc(OCINumberTrunc(oci8_errhp, _NUMBER(self), 0, &num));
882
- return oci8_make_integer(&num);
985
+ oci_lc(OCINumberTrunc(errhp, _NUMBER(self), 0, &num));
986
+ return oci8_make_integer(&num, errhp);
883
987
  }
884
988
 
885
989
  /*
@@ -891,9 +995,10 @@ static VALUE onum_to_i(VALUE self)
891
995
  */
892
996
  static VALUE onum_to_f(VALUE self)
893
997
  {
998
+ OCIError *errhp = oci8_errhp;
894
999
  double dbl;
895
1000
 
896
- oci_lc(OCINumberToReal(oci8_errhp, _NUMBER(self), sizeof(dbl), &dbl));
1001
+ oci_lc(OCINumberToReal(errhp, _NUMBER(self), sizeof(dbl), &dbl));
897
1002
  return rb_float_new(dbl);
898
1003
  }
899
1004
 
@@ -916,9 +1021,10 @@ static VALUE onum_to_onum(VALUE self)
916
1021
  */
917
1022
  static VALUE onum_zero_p(VALUE self)
918
1023
  {
1024
+ OCIError *errhp = oci8_errhp;
919
1025
  boolean result;
920
1026
 
921
- oci_lc(OCINumberIsZero(oci8_errhp, _NUMBER(self), &result));
1027
+ oci_lc(OCINumberIsZero(errhp, _NUMBER(self), &result));
922
1028
  return result ? Qtrue : Qfalse;
923
1029
  }
924
1030
 
@@ -931,10 +1037,11 @@ static VALUE onum_zero_p(VALUE self)
931
1037
  */
932
1038
  static VALUE onum_abs(VALUE self)
933
1039
  {
1040
+ OCIError *errhp = oci8_errhp;
934
1041
  OCINumber result;
935
1042
 
936
- oci_lc(OCINumberAbs(oci8_errhp, _NUMBER(self), &result));
937
- return oci8_make_ocinumber(&result);
1043
+ oci_lc(OCINumberAbs(errhp, _NUMBER(self), &result));
1044
+ return oci8_make_ocinumber(&result, errhp);
938
1045
  }
939
1046
 
940
1047
  /*
@@ -946,10 +1053,11 @@ static VALUE onum_abs(VALUE self)
946
1053
  */
947
1054
  static VALUE onum_shift(VALUE self, VALUE exp)
948
1055
  {
1056
+ OCIError *errhp = oci8_errhp;
949
1057
  OCINumber result;
950
1058
 
951
- oci_lc(OCINumberShift(oci8_errhp, _NUMBER(self), NUM2INT(exp), &result));
952
- return oci8_make_ocinumber(&result);
1059
+ oci_lc(OCINumberShift(errhp, _NUMBER(self), NUM2INT(exp), &result));
1060
+ return oci8_make_ocinumber(&result, errhp);
953
1061
  }
954
1062
 
955
1063
  static VALUE onum_hash(VALUE self)
@@ -1018,7 +1126,7 @@ onum_s_load(VALUE klass, VALUE str)
1018
1126
  }
1019
1127
  memset(&num, 0, sizeof(num));
1020
1128
  memcpy(&num, c, size);
1021
- return oci8_make_ocinumber(&num);
1129
+ return oci8_make_ocinumber(&num, oci8_errhp);
1022
1130
  }
1023
1131
 
1024
1132
  /*
@@ -1026,25 +1134,26 @@ onum_s_load(VALUE klass, VALUE str)
1026
1134
  */
1027
1135
  static VALUE bind_ocinumber_get(oci8_bind_t *obind, void *data, void *null_struct)
1028
1136
  {
1029
- return oci8_make_ocinumber((OCINumber*)data);
1137
+ return oci8_make_ocinumber((OCINumber*)data, oci8_errhp);
1030
1138
  }
1031
1139
 
1032
1140
  static VALUE bind_integer_get(oci8_bind_t *obind, void *data, void *null_struct)
1033
1141
  {
1034
- return oci8_make_integer((OCINumber*)data);
1142
+ return oci8_make_integer((OCINumber*)data, oci8_errhp);
1035
1143
  }
1036
1144
 
1037
1145
  static void bind_ocinumber_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val)
1038
1146
  {
1039
- set_oci_number_from_num((OCINumber*)data, val, 1);
1147
+ set_oci_number_from_num((OCINumber*)data, val, 1, oci8_errhp);
1040
1148
  }
1041
1149
 
1042
1150
  static void bind_integer_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val)
1043
1151
  {
1152
+ OCIError *errhp = oci8_errhp;
1044
1153
  OCINumber num;
1045
1154
 
1046
- set_oci_number_from_num(&num, val, 1);
1047
- oci_lc(OCINumberTrunc(oci8_errhp, &num, 0, (OCINumber*)data));
1155
+ set_oci_number_from_num(&num, val, 1, errhp);
1156
+ oci_lc(OCINumberTrunc(errhp, &num, 0, (OCINumber*)data));
1048
1157
  }
1049
1158
 
1050
1159
  static void bind_ocinumber_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
@@ -1055,10 +1164,11 @@ static void bind_ocinumber_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE
1055
1164
 
1056
1165
  static void bind_ocinumber_init_elem(oci8_bind_t *obind, VALUE svc)
1057
1166
  {
1167
+ OCIError *errhp = oci8_errhp;
1058
1168
  ub4 idx = 0;
1059
1169
 
1060
1170
  do {
1061
- OCINumberSetZero(oci8_errhp, (OCINumber*)obind->valuep + idx);
1171
+ OCINumberSetZero(errhp, (OCINumber*)obind->valuep + idx);
1062
1172
  } while (++idx < obind->maxar_sz);
1063
1173
  }
1064
1174
 
@@ -1095,7 +1205,7 @@ static const oci8_bind_class_t bind_integer_class = {
1095
1205
  };
1096
1206
 
1097
1207
  void
1098
- Init_oci_number(VALUE cOCI8)
1208
+ Init_oci_number(VALUE cOCI8, OCIError *errhp)
1099
1209
  {
1100
1210
  VALUE mMath;
1101
1211
  OCINumber num1, num2;
@@ -1104,6 +1214,10 @@ Init_oci_number(VALUE cOCI8)
1104
1214
 
1105
1215
  id_power = rb_intern("**");
1106
1216
  id_cmp = rb_intern("<=>");
1217
+ id_finite_p = rb_intern("finite?");
1218
+ id_split = rb_intern("split");
1219
+ id_numerator = rb_intern("numerator");
1220
+ id_denominator = rb_intern("denominator");
1107
1221
 
1108
1222
  cOCINumber = rb_define_class("OraNumber", rb_cNumeric);
1109
1223
  mMath = rb_define_module_under(cOCI8, "Math");
@@ -1111,27 +1225,27 @@ Init_oci_number(VALUE cOCI8)
1111
1225
  /* constants for internal use. */
1112
1226
  /* set const_p1 */
1113
1227
  sl = 1;
1114
- OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p1);
1228
+ OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p1);
1115
1229
  /* set const_p10 */
1116
1230
  sl = 10;
1117
- OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p10);
1231
+ OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p10);
1118
1232
  /* set const_m1 */
1119
1233
  sl = -1;
1120
- OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_m1);
1234
+ OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_m1);
1121
1235
  /* set const_PI2 */
1122
1236
  sl = 2;
1123
- OCINumberSetPi(oci8_errhp, &num1);
1124
- OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &num2);
1125
- OCINumberDiv(oci8_errhp, &num1 /* PI */, &num2 /* 2 */, &const_PI2);
1237
+ OCINumberSetPi(errhp, &num1);
1238
+ OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &num2);
1239
+ OCINumberDiv(errhp, &num1 /* PI */, &num2 /* 2 */, &const_PI2);
1126
1240
  /* set const_mPI2 */
1127
- OCINumberNeg(oci8_errhp, &const_PI2 /* PI/2 */, &const_mPI2);
1241
+ OCINumberNeg(errhp, &const_PI2 /* PI/2 */, &const_mPI2);
1128
1242
  /* set const_shreshold */
1129
- OCINumberFromText(oci8_errhp, SHRESHOLD_VAL, SHRESHOLD_VAL_LEN, SHRESHOLD_FMT, SHRESHOLD_FMT_LEN,
1243
+ OCINumberFromText(errhp, SHRESHOLD_VAL, SHRESHOLD_VAL_LEN, SHRESHOLD_FMT, SHRESHOLD_FMT_LEN,
1130
1244
  NULL, 0, &const_shreshold);
1131
1245
 
1132
1246
  /* PI */
1133
- OCINumberSetPi(oci8_errhp, &num1);
1134
- obj_PI = oci8_make_ocinumber(&num1);
1247
+ OCINumberSetPi(errhp, &num1);
1248
+ obj_PI = oci8_make_ocinumber(&num1, errhp);
1135
1249
 
1136
1250
  /* The ratio of the circumference of a circle to its diameter. */
1137
1251
  rb_define_const(mMath, "PI", obj_PI);