ruby-oci8 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -120,6 +120,9 @@ typedef struct OCIAdmin OCIAdmin;
120
120
  #ifndef STRINGIZE
121
121
  #define STRINGIZE(name) #name
122
122
  #endif
123
+ #ifndef RB_GC_GUARD
124
+ #define RB_GC_GUARD(v) (*(volatile VALUE *)&(v))
125
+ #endif
123
126
 
124
127
  /* new functions in ruby 1.9.
125
128
  * define compatible macros for ruby 1.8 or lower.
@@ -136,6 +139,7 @@ typedef VALUE rb_blocking_function_t(void *);
136
139
  #define rb_external_str_new_with_enc(ptr, len, enc) rb_tainted_str_new((ptr), (len))
137
140
  #define rb_locale_str_new_cstr(ptr) rb_str_new2(ptr)
138
141
  #define rb_str_conv_enc(str, from, to) (str)
142
+ #define rb_str_export_to_enc(str, enc) (str)
139
143
  #define rb_usascii_str_new(ptr, len) rb_str_new((ptr), (len))
140
144
  #define rb_usascii_str_new_cstr(ptr) rb_str_new2(ptr)
141
145
  #endif
@@ -263,6 +263,8 @@ void oci8_unlink_from_parent(oci8_base_t *base)
263
263
  }
264
264
 
265
265
  #ifdef RUBY_VM
266
+
267
+ #if 0
266
268
  typedef struct {
267
269
  dvoid *hndlp;
268
270
  OCIError *errhp;
@@ -285,6 +287,13 @@ static void oci8_unblock_func(void *user_data)
285
287
  rb_thread_blocking_region(call_OCIBreak, &arg, NULL, NULL);
286
288
  }
287
289
  }
290
+ #else
291
+ static void oci8_unblock_func(void *user_data)
292
+ {
293
+ oci8_svcctx_t *svcctx = (oci8_svcctx_t *)user_data;
294
+ OCIBreak(svcctx->base.hp.ptr, oci8_errhp);
295
+ }
296
+ #endif
288
297
 
289
298
  /* ruby 1.9 */
290
299
  sword oci8_blocking_region(oci8_svcctx_t *svcctx, rb_blocking_function_t func, void *data)
@@ -320,7 +329,7 @@ sword oci8_blocking_region(oci8_svcctx_t *svcctx, rb_blocking_function_t func, v
320
329
  rb_raise(rb_eRuntimeError /* FIXME */, "executing in another thread");
321
330
  }
322
331
  tv.tv_sec = 0;
323
- tv.tv_usec = 100000;
332
+ tv.tv_usec = 10000;
324
333
  svcctx->executing_thread = rb_thread_current();
325
334
  while ((rv = func(data)) == OCI_STILL_EXECUTING) {
326
335
  rb_thread_wait_for(tv);
@@ -3,7 +3,7 @@
3
3
  * ocidatetime.c
4
4
  *
5
5
  * $Author: kubo $
6
- * $Date: 2009-05-17 22:07:16 +0900 (Sun, 17 May 2009) $
6
+ * $Date: 2009-10-21 22:50:01 +0900 (Wed, 21 Oct 2009) $
7
7
  *
8
8
  * Copyright (C) 2005-2008 KUBO Takehiro <kubo@jiubao.org>
9
9
  *
@@ -320,8 +320,26 @@ OCIInterval *oci8_set_ociinterval_ym(OCIInterval *intvl, VALUE val)
320
320
  }
321
321
  year = NUM2INT(RARRAY_PTR(val)[0]);
322
322
  month = NUM2INT(RARRAY_PTR(val)[1]);
323
- oci_lc(OCIIntervalSetYearMonth(oci8_envhp, oci8_errhp,
324
- year, month, intvl));
323
+ if (oracle_client_version >= ORAVERNUM(9, 2, 0, 3, 0)) {
324
+ oci_lc(OCIIntervalSetYearMonth(oci8_envhp, oci8_errhp,
325
+ year, month, intvl));
326
+ } else {
327
+ /* Workaround for Bug 2227982 */
328
+ char buf[64];
329
+ char *sign = "";
330
+
331
+ if (year < 0 && month != 0) {
332
+ year += 1;
333
+ month -= 12;
334
+ }
335
+ if (year < 0 || month < 0) {
336
+ sign = "-";
337
+ year = -year;
338
+ month = -month;
339
+ }
340
+ sprintf(buf, "%s%d-%d", sign, year, month);
341
+ oci_lc(OCIIntervalFromText(oci8_envhp, oci8_errhp, (text*)buf, strlen(buf), intvl));
342
+ }
325
343
  return intvl;
326
344
  }
327
345
 
@@ -357,8 +375,32 @@ OCIInterval *oci8_set_ociinterval_ds(OCIInterval *intvl, VALUE val)
357
375
  minute = NUM2INT(RARRAY_PTR(val)[2]);
358
376
  sec = NUM2INT(RARRAY_PTR(val)[3]);
359
377
  fsec = NUM2INT(RARRAY_PTR(val)[4]);
360
- oci_lc(OCIIntervalSetDaySecond(oci8_envhp, oci8_errhp,
361
- day, hour, minute, sec, fsec, intvl));
378
+ if (oracle_client_version >= ORAVERNUM(9, 2, 0, 3, 0)) {
379
+ oci_lc(OCIIntervalSetDaySecond(oci8_envhp, oci8_errhp,
380
+ day, hour, minute, sec, fsec, intvl));
381
+ } else {
382
+ /* Workaround for Bug 2227982 */
383
+ char buf[64];
384
+ char *sign = "";
385
+
386
+ if (day == 0) {
387
+ if (hour < 0) {
388
+ sign = "-";
389
+ hour = -hour;
390
+ } else if (minute < 0) {
391
+ sign = "-";
392
+ minute = -minute;
393
+ } else if (sec < 0) {
394
+ sign = "-";
395
+ sec = -sec;
396
+ } else if (fsec < 0) {
397
+ sign = "-";
398
+ fsec = -fsec;
399
+ }
400
+ }
401
+ sprintf(buf, "%s%d %02d:%02d:%02d.%09d", sign, day, hour, minute, sec, fsec);
402
+ oci_lc(OCIIntervalFromText(oci8_envhp, oci8_errhp, (text*)buf, strlen(buf), intvl));
403
+ }
362
404
  return intvl;
363
405
  }
364
406
 
@@ -21,6 +21,13 @@ static ID id_finite_p;
21
21
  static ID id_split;
22
22
  static ID id_numerator;
23
23
  static ID id_denominator;
24
+ static ID id_Rational;
25
+ static ID id_BigDecimal;
26
+
27
+ #ifndef T_RATIONAL
28
+ static VALUE cRational;
29
+ #endif
30
+ static VALUE cBigDecimal;
24
31
 
25
32
  static VALUE cOCINumber;
26
33
  static OCINumber const_p1; /* +1 */
@@ -51,6 +58,58 @@ static OCINumber const_shreshold;
51
58
 
52
59
  #define _NUMBER(val) ((OCINumber *)DATA_PTR(val)) /* dangerous macro */
53
60
 
61
+ #define RBOCI8_T_ORANUMBER (T_MASK + 1)
62
+ #define RBOCI8_T_BIGDECIMAL (T_MASK + 2)
63
+ #ifdef T_RATIONAL
64
+ #define RBOCI8_T_RATIONAL T_RATIONAL
65
+ #else
66
+ #define RBOCI8_T_RATIONAL (T_MASK + 3)
67
+ #endif
68
+
69
+ static int rboci8_type(VALUE obj)
70
+ {
71
+ int type = TYPE(obj);
72
+ VALUE klass;
73
+
74
+ switch (type) {
75
+ #ifndef T_RATIONAL
76
+ case T_OBJECT:
77
+ klass = CLASS_OF(obj);
78
+ if (cRational != 0) {
79
+ if (klass == cRational) {
80
+ return RBOCI8_T_RATIONAL;
81
+ }
82
+ } else {
83
+ if (strcmp(rb_class2name(klass), "Rational") == 0) {
84
+ cRational = rb_const_get(rb_cObject, id_Rational);
85
+ return RBOCI8_T_RATIONAL;
86
+ }
87
+ }
88
+ break;
89
+ #endif
90
+ case T_DATA:
91
+ klass = CLASS_OF(obj);
92
+ if (klass == cOCINumber) {
93
+ return RBOCI8_T_ORANUMBER;
94
+ }
95
+ if (cBigDecimal != 0) {
96
+ if (klass == cBigDecimal) {
97
+ return RBOCI8_T_BIGDECIMAL;
98
+ }
99
+ } else {
100
+ if (strcmp(rb_class2name(klass), "BigDecimal") == 0) {
101
+ cBigDecimal = rb_const_get(rb_cObject, id_BigDecimal);
102
+ return RBOCI8_T_BIGDECIMAL;
103
+ }
104
+ }
105
+ }
106
+ return type;
107
+ }
108
+
109
+ static VALUE onum_to_f(VALUE self);
110
+ static VALUE onum_to_r(VALUE self);
111
+ static VALUE onum_to_d(VALUE self);
112
+
54
113
  static VALUE onum_s_alloc(VALUE klass)
55
114
  {
56
115
  VALUE obj;
@@ -573,6 +632,20 @@ static VALUE omath_sqrt(VALUE obj, VALUE num)
573
632
  return oci8_make_ocinumber(&r, errhp);
574
633
  }
575
634
 
635
+
636
+ /*
637
+ * call-seq:
638
+ * OraNumber(obj) -> oranumber
639
+ *
640
+ * Returns a new <code>OraNumber</code>.
641
+ */
642
+ static VALUE onum_f_new(int argc, VALUE *argv, VALUE self)
643
+ {
644
+ VALUE obj = rb_obj_alloc(cOCINumber);
645
+ rb_obj_call_init(obj, argc, argv);
646
+ return obj;
647
+ }
648
+
576
649
  static VALUE onum_initialize(int argc, VALUE *argv, VALUE self)
577
650
  {
578
651
  OCIError *errhp = oci8_errhp;
@@ -602,12 +675,26 @@ static VALUE onum_initialize_copy(VALUE lhs, VALUE rhs)
602
675
 
603
676
  static VALUE onum_coerce(VALUE self, VALUE other)
604
677
  {
605
- OCIError *errhp = oci8_errhp;
678
+ signed long sl;
606
679
  OCINumber n;
607
680
 
608
- if (RTEST(rb_obj_is_kind_of(other, rb_cNumeric)))
609
- if (set_oci_number_from_num(&n, other, 0, errhp))
610
- return rb_assoc_new(oci8_make_ocinumber(&n, errhp), self);
681
+ switch(rboci8_type(other)) {
682
+ case T_FIXNUM:
683
+ sl = NUM2LONG(other);
684
+ oci_lc(OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &n));
685
+ return rb_assoc_new(oci8_make_ocinumber(&n, oci8_errhp), self);
686
+ case T_BIGNUM:
687
+ /* change via string. */
688
+ other = rb_big2str(other, 10);
689
+ set_oci_number_from_str(&n, other, Qnil, Qnil, oci8_errhp);
690
+ return rb_assoc_new(oci8_make_ocinumber(&n, oci8_errhp), self);
691
+ case T_FLOAT:
692
+ return rb_assoc_new(other, onum_to_f(self));
693
+ case RBOCI8_T_RATIONAL:
694
+ return rb_assoc_new(other, onum_to_r(self));
695
+ case RBOCI8_T_BIGDECIMAL:
696
+ return rb_assoc_new(other, onum_to_d(self));
697
+ }
611
698
  rb_raise(rb_eTypeError, "Can't coerce %s to %s",
612
699
  rb_class2name(CLASS_OF(other)), rb_class2name(cOCINumber));
613
700
  }
@@ -616,7 +703,7 @@ static VALUE onum_coerce(VALUE self, VALUE other)
616
703
  * call-seq:
617
704
  * -onum -> oranumber
618
705
  *
619
- * Returns an <code>OraNumber</code>, negated.
706
+ * Returns a negated <code>OraNumber</code>.
620
707
  */
621
708
  static VALUE onum_neg(VALUE self)
622
709
  {
@@ -627,12 +714,12 @@ static VALUE onum_neg(VALUE self)
627
714
  return oci8_make_ocinumber(&r, errhp);
628
715
  }
629
716
 
717
+
630
718
  /*
631
719
  * call-seq:
632
- * onum + other -> oranumber
720
+ * onum + other -> number
633
721
  *
634
- * Returns a new <code>OraNumber</code> which is the sum of <i>onum</i>
635
- * and <i>other</i>.
722
+ * Returns the sum of <i>onum</i> and <i>other</i>.
636
723
  */
637
724
  static VALUE onum_add(VALUE lhs, VALUE rhs)
638
725
  {
@@ -640,20 +727,33 @@ static VALUE onum_add(VALUE lhs, VALUE rhs)
640
727
  OCINumber n;
641
728
  OCINumber r;
642
729
 
643
- /* change to OCINumber */
644
- if (!set_oci_number_from_num(&n, rhs, 0, errhp))
645
- return rb_num_coerce_bin(lhs, rhs, '+');
646
- /* add */
647
- oci_lc(OCINumberAdd(errhp, _NUMBER(lhs), &n, &r));
648
- return oci8_make_ocinumber(&r, errhp);
730
+ switch (rboci8_type(rhs)) {
731
+ case T_FIXNUM:
732
+ case T_BIGNUM:
733
+ if (set_oci_number_from_num(&n, rhs, 0, errhp)) {
734
+ oci_lc(OCINumberAdd(errhp, _NUMBER(lhs), &n, &r));
735
+ return oci8_make_ocinumber(&r, errhp);
736
+ }
737
+ break;
738
+ case RBOCI8_T_ORANUMBER:
739
+ oci_lc(OCINumberAdd(errhp, _NUMBER(lhs), _NUMBER(rhs), &r));
740
+ return oci8_make_ocinumber(&r, errhp);
741
+ case T_FLOAT:
742
+ return rb_funcall(onum_to_f(lhs), '+', 1, rhs);
743
+ case RBOCI8_T_RATIONAL:
744
+ return rb_funcall(onum_to_r(lhs), '+', 1, rhs);
745
+ case RBOCI8_T_BIGDECIMAL:
746
+ return rb_funcall(onum_to_d(lhs), '+', 1, rhs);
747
+ }
748
+ return rb_num_coerce_bin(lhs, rhs, '+');
649
749
  }
650
750
 
651
751
  /*
652
752
  * call-seq:
653
- * onum - other -> oranumber
753
+ * onum - integer -> oranumber
754
+ * onum - numeric -> numeric
654
755
  *
655
- * Returns a new <code>OraNumber</code> which is the difference of <i>onum</i>
656
- * and <i>other</i>.
756
+ * Returns the difference of <i>onum</i> and <i>other</i>.
657
757
  */
658
758
  static VALUE onum_sub(VALUE lhs, VALUE rhs)
659
759
  {
@@ -661,20 +761,32 @@ static VALUE onum_sub(VALUE lhs, VALUE rhs)
661
761
  OCINumber n;
662
762
  OCINumber r;
663
763
 
664
- /* change to OCINumber */
665
- if (!set_oci_number_from_num(&n, rhs, 0, errhp))
666
- return rb_num_coerce_bin(lhs, rhs, '-');
667
- /* subtracting */
668
- oci_lc(OCINumberSub(errhp, _NUMBER(lhs), &n, &r));
669
- return oci8_make_ocinumber(&r, errhp);
764
+ switch (rboci8_type(rhs)) {
765
+ case T_FIXNUM:
766
+ case T_BIGNUM:
767
+ if (set_oci_number_from_num(&n, rhs, 0, errhp)) {
768
+ oci_lc(OCINumberSub(errhp, _NUMBER(lhs), &n, &r));
769
+ return oci8_make_ocinumber(&r, errhp);
770
+ }
771
+ break;
772
+ case RBOCI8_T_ORANUMBER:
773
+ oci_lc(OCINumberSub(errhp, _NUMBER(lhs), _NUMBER(rhs), &r));
774
+ return oci8_make_ocinumber(&r, errhp);
775
+ case T_FLOAT:
776
+ return rb_funcall(onum_to_f(lhs), '-', 1, rhs);
777
+ case RBOCI8_T_RATIONAL:
778
+ return rb_funcall(onum_to_r(lhs), '-', 1, rhs);
779
+ case RBOCI8_T_BIGDECIMAL:
780
+ return rb_funcall(onum_to_d(lhs), '-', 1, rhs);
781
+ }
782
+ return rb_num_coerce_bin(lhs, rhs, '-');
670
783
  }
671
784
 
672
785
  /*
673
786
  * call-seq:
674
- * onum * other -> oranumber
787
+ * onum * other -> number
675
788
  *
676
- * Returns a new <code>OraNumber</code> which is the product of <i>onum</i>
677
- * and <i>other</i>.
789
+ * Returns the product of <i>onum</i> and <i>other</i>.
678
790
  */
679
791
  static VALUE onum_mul(VALUE lhs, VALUE rhs)
680
792
  {
@@ -682,20 +794,33 @@ static VALUE onum_mul(VALUE lhs, VALUE rhs)
682
794
  OCINumber n;
683
795
  OCINumber r;
684
796
 
685
- /* change to OCINumber */
686
- if (!set_oci_number_from_num(&n, rhs, 0, errhp))
687
- return rb_num_coerce_bin(lhs, rhs, '*');
688
- /* multiply */
689
- oci_lc(OCINumberMul(errhp, _NUMBER(lhs), &n, &r));
690
- return oci8_make_ocinumber(&r, errhp);
797
+ switch (rboci8_type(rhs)) {
798
+ case T_FIXNUM:
799
+ case T_BIGNUM:
800
+ if (set_oci_number_from_num(&n, rhs, 0, errhp)) {
801
+ oci_lc(OCINumberMul(errhp, _NUMBER(lhs), &n, &r));
802
+ return oci8_make_ocinumber(&r, errhp);
803
+ }
804
+ break;
805
+ case RBOCI8_T_ORANUMBER:
806
+ oci_lc(OCINumberMul(errhp, _NUMBER(lhs), _NUMBER(rhs), &r));
807
+ return oci8_make_ocinumber(&r, errhp);
808
+ case T_FLOAT:
809
+ return rb_funcall(onum_to_f(lhs), '*', 1, rhs);
810
+ case RBOCI8_T_RATIONAL:
811
+ return rb_funcall(onum_to_r(lhs), '*', 1, rhs);
812
+ case RBOCI8_T_BIGDECIMAL:
813
+ return rb_funcall(onum_to_d(lhs), '*', 1, rhs);
814
+ }
815
+ return rb_num_coerce_bin(lhs, rhs, '*');
691
816
  }
692
817
 
693
818
  /*
694
819
  * call-seq:
695
- * onum / other -> oranumber
820
+ * onum / integer -> oranumber
821
+ * onum / numeric -> numeric
696
822
  *
697
- * Returns a new <code>OraNumber</code> which is the result of dividing
698
- * <i>onum</i> by <i>other</i>.
823
+ * Returns the result of dividing <i>onum</i> by <i>other</i>.
699
824
  */
700
825
  static VALUE onum_div(VALUE lhs, VALUE rhs)
701
826
  {
@@ -704,16 +829,32 @@ static VALUE onum_div(VALUE lhs, VALUE rhs)
704
829
  OCINumber r;
705
830
  boolean is_zero;
706
831
 
707
- /* change to OCINumber */
708
- if (!set_oci_number_from_num(&n, rhs, 0, errhp))
709
- return rb_num_coerce_bin(lhs, rhs, '/');
710
- /* check whether argument is not zero. */
711
- oci_lc(OCINumberIsZero(errhp, &n, &is_zero));
712
- if (is_zero)
713
- rb_num_zerodiv();
714
- /* division */
715
- oci_lc(OCINumberDiv(errhp, _NUMBER(lhs), &n, &r));
716
- return oci8_make_ocinumber(&r, errhp);
832
+ switch (rboci8_type(rhs)) {
833
+ case T_FIXNUM:
834
+ if (rhs == INT2FIX(0)) {
835
+ rb_num_zerodiv();
836
+ }
837
+ case T_BIGNUM:
838
+ if (set_oci_number_from_num(&n, rhs, 0, errhp)) {
839
+ oci_lc(OCINumberDiv(errhp, _NUMBER(lhs), &n, &r));
840
+ return oci8_make_ocinumber(&r, errhp);
841
+ }
842
+ break;
843
+ case RBOCI8_T_ORANUMBER:
844
+ oci_lc(OCINumberIsZero(errhp, _NUMBER(rhs), &is_zero));
845
+ if (is_zero) {
846
+ rb_num_zerodiv();
847
+ }
848
+ oci_lc(OCINumberDiv(errhp, _NUMBER(lhs), _NUMBER(rhs), &r));
849
+ return oci8_make_ocinumber(&r, errhp);
850
+ case T_FLOAT:
851
+ return rb_funcall(onum_to_f(lhs), '/', 1, rhs);
852
+ case RBOCI8_T_RATIONAL:
853
+ return rb_funcall(onum_to_r(lhs), '/', 1, rhs);
854
+ case RBOCI8_T_BIGDECIMAL:
855
+ return rb_funcall(onum_to_d(lhs), '/', 1, rhs);
856
+ }
857
+ return rb_num_coerce_bin(lhs, rhs, '/');
717
858
  }
718
859
 
719
860
  /*
@@ -975,7 +1116,7 @@ static VALUE onum_to_s(VALUE self)
975
1116
  * call-seq:
976
1117
  * onum.to_i -> integer
977
1118
  *
978
- * Returns <i>onm</i> truncated to an <code>Integer</code>.
1119
+ * Returns <i>onum</i> truncated to an <code>Integer</code>.
979
1120
  */
980
1121
  static VALUE onum_to_i(VALUE self)
981
1122
  {
@@ -990,7 +1131,7 @@ static VALUE onum_to_i(VALUE self)
990
1131
  * call-seq:
991
1132
  * onum.to_f -> float
992
1133
  *
993
- * Converts <i>onum</i> to a <code>Float</code>.
1134
+ * Return the value as a <code>Float</code>.
994
1135
  *
995
1136
  */
996
1137
  static VALUE onum_to_f(VALUE self)
@@ -1002,10 +1143,71 @@ static VALUE onum_to_f(VALUE self)
1002
1143
  return rb_float_new(dbl);
1003
1144
  }
1004
1145
 
1146
+ /*
1147
+ * call-seq:
1148
+ * onum.to_r -> rational
1149
+ *
1150
+ * Return the value as a <code>Rational</code>.
1151
+ *
1152
+ */
1153
+ static VALUE onum_to_r(VALUE self)
1154
+ {
1155
+ VALUE x, y;
1156
+ int nshift = 0;
1157
+ OCINumber onum[2];
1158
+ int current = 0;
1159
+ boolean is_int;
1160
+
1161
+ oci_lc(OCINumberAssign(oci8_errhp, _NUMBER(self), &onum[0]));
1162
+
1163
+ for (;;) {
1164
+ oci_lc(OCINumberIsInt(oci8_errhp, &onum[current], &is_int));
1165
+ if (is_int) {
1166
+ break;
1167
+ }
1168
+ nshift++;
1169
+ oci_lc(OCINumberShift(oci8_errhp, &onum[current], 1, &onum[1 - current]));
1170
+ current = 1 - current;
1171
+ }
1172
+ x = oci8_make_integer(&onum[current], oci8_errhp);
1173
+ if (nshift == 0) {
1174
+ y = INT2FIX(1);
1175
+ } else {
1176
+ y = rb_funcall(INT2FIX(10), rb_intern("**"), 1, INT2FIX(nshift));
1177
+ }
1178
+ #ifdef T_RATIONAL
1179
+ return rb_Rational(x, y);
1180
+ #else
1181
+ if (!cRational) {
1182
+ rb_require("rational");
1183
+ cRational = rb_const_get(rb_cObject, id_Rational);
1184
+ }
1185
+ return rb_funcall(rb_cObject, id_Rational, 2, x, y);
1186
+ #endif
1187
+ }
1188
+
1189
+ /*
1190
+ * call-seq:
1191
+ * onum.to_d -> bigdecimal
1192
+ *
1193
+ * Return the value as a <code>BigDecimal</code>.
1194
+ *
1195
+ */
1196
+ static VALUE onum_to_d(VALUE self)
1197
+ {
1198
+ if (!cBigDecimal) {
1199
+ rb_require("bigdecimal");
1200
+ cBigDecimal = rb_const_get(rb_cObject, id_BigDecimal);
1201
+ }
1202
+ return rb_funcall(rb_cObject, id_BigDecimal, 1, onum_to_s(self));
1203
+ }
1204
+
1005
1205
  /*
1006
1206
  * call-seq:
1007
1207
  * onum.to_onum -> oranumber
1008
1208
  *
1209
+ * Returns self.
1210
+ *
1009
1211
  */
1010
1212
  static VALUE onum_to_onum(VALUE self)
1011
1213
  {
@@ -1218,6 +1420,8 @@ Init_oci_number(VALUE cOCI8, OCIError *errhp)
1218
1420
  id_split = rb_intern("split");
1219
1421
  id_numerator = rb_intern("numerator");
1220
1422
  id_denominator = rb_intern("denominator");
1423
+ id_Rational = rb_intern("Rational");
1424
+ id_BigDecimal = rb_intern("BigDecimal");
1221
1425
 
1222
1426
  cOCINumber = rb_define_class("OraNumber", rb_cNumeric);
1223
1427
  mMath = rb_define_module_under(cOCI8, "Math");
@@ -1275,6 +1479,7 @@ Init_oci_number(VALUE cOCI8, OCIError *errhp)
1275
1479
  rb_define_alloc_func(cOCINumber, onum_s_alloc);
1276
1480
 
1277
1481
  /* methods of OCI::Number */
1482
+ rb_define_method(rb_cObject, "OraNumber", onum_f_new, -1);
1278
1483
  rb_define_method_nodoc(cOCINumber, "initialize", onum_initialize, -1);
1279
1484
  rb_define_method_nodoc(cOCINumber, "initialize_copy", onum_initialize_copy, 1);
1280
1485
  rb_define_method_nodoc(cOCINumber, "coerce", onum_coerce, 1);
@@ -1302,6 +1507,8 @@ Init_oci_number(VALUE cOCI8, OCIError *errhp)
1302
1507
  rb_define_method(cOCINumber, "to_char", onum_to_char, -1);
1303
1508
  rb_define_method(cOCINumber, "to_i", onum_to_i, 0);
1304
1509
  rb_define_method(cOCINumber, "to_f", onum_to_f, 0);
1510
+ rb_define_method(cOCINumber, "to_r", onum_to_r, 0);
1511
+ rb_define_method(cOCINumber, "to_d", onum_to_d, 0);
1305
1512
  rb_define_method_nodoc(cOCINumber, "to_onum", onum_to_onum, 0);
1306
1513
 
1307
1514
  rb_define_method(cOCINumber, "zero?", onum_zero_p, 0);