From nobody at rubyforge.org Sat Oct 1 00:20:02 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 1 Oct 2011 00:20:02 -0400 (EDT) Subject: [ruby-oci8-commit] [451] trunk/ruby-oci8: delete subversion keywords. Message-ID: <20111001042002.985FD185838A@rubyforge.org> Revision: 451 Author: kubo Date: 2011-10-01 00:20:02 -0400 (Sat, 01 Oct 2011) Log Message: ----------- delete subversion keywords. use thread-local errhp not only at ruby 1.9 and rubinius, but also ruby 1.8 configured with --enable-pthread. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/attr.c trunk/ruby-oci8/ext/oci8/env.c trunk/ruby-oci8/ext/oci8/oci8.h trunk/ruby-oci8/ext/oci8/ocidatetime.c trunk/ruby-oci8/ext/oci8/oradate.c trunk/ruby-oci8/ext/oci8/thread_util.c trunk/ruby-oci8/ext/oci8/thread_util.h Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-10-01 03:14:45 UTC (rev 450) +++ trunk/ruby-oci8/ChangeLog 2011-10-01 04:20:02 UTC (rev 451) @@ -1,4 +1,11 @@ 2011-10-01 KUBO Takehiro + * ext/oci8/attr.c, ext/oci8/ocidatetime.c, ext/oci8/oradate.c: delete + subversion keywords. + * ext/oci8/env.c, ext/oci8/oci8.h, ext/oci8/thread_util.c, + ext/oci8/thread_util.h: use thread-local errhp not only at ruby 1.9 + and rubinius, but also ruby 1.8 configured with --enable-pthread. + +2011-10-01 KUBO Takehiro * ext/oci8/bind.c, ext/oci8/connection_pool.c, ext/oci8/lob.c, ext/oci8/metadata.c, ext/oci8/object.c, ext/oci8/oci8.c, ext/oci8/oci8.h, ext/oci8/oci8lib.c, ext/oci8/ocidatetime.c, ext/oci8/ocihandle.c, Modified: trunk/ruby-oci8/ext/oci8/attr.c =================================================================== --- trunk/ruby-oci8/ext/oci8/attr.c 2011-10-01 03:14:45 UTC (rev 450) +++ trunk/ruby-oci8/ext/oci8/attr.c 2011-10-01 04:20:02 UTC (rev 451) @@ -2,9 +2,6 @@ /* * attr.c * - * $Author$ - * $Date$ - * * Copyright (C) 2002-2007 KUBO Takehiro */ #include "oci8.h" Modified: trunk/ruby-oci8/ext/oci8/env.c =================================================================== --- trunk/ruby-oci8/ext/oci8/env.c 2011-10-01 03:14:45 UTC (rev 450) +++ trunk/ruby-oci8/ext/oci8/env.c 2011-10-01 04:20:02 UTC (rev 451) @@ -27,9 +27,9 @@ return oci8_global_envhp; } -#ifdef HAVE_RB_THREAD_BLOCKING_REGION +#ifdef USE_THREAD_LOCAL_ERRHP /* - * oci8_errhp is a thread local object in ruby 1.9. + * Setup thread-local oci8_errhp. */ oci8_tls_key_t oci8_tls_key; /* native thread key */ @@ -89,7 +89,7 @@ } #else /* - * oci8_errhp is global in ruby 1.8. + * oci8_errhp is global in ruby 1.8 configured without --enable-pthread on Unix. */ OCIError *oci8_global_errhp; @@ -106,7 +106,7 @@ void Init_oci8_env(void) { -#ifdef HAVE_RB_THREAD_BLOCKING_REGION +#ifdef USE_THREAD_LOCAL_ERRHP int error; #endif @@ -156,8 +156,7 @@ } } -#ifdef HAVE_RB_THREAD_BLOCKING_REGION -/* ruby 1.9 */ +#ifdef USE_THREAD_LOCAL_ERRHP #if defined(_WIN32) if (!dllmain_is_called) { /* sanity check */ Modified: trunk/ruby-oci8/ext/oci8/oci8.h =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8.h 2011-10-01 03:14:45 UTC (rev 450) +++ trunk/ruby-oci8/ext/oci8/oci8.h 2011-10-01 04:20:02 UTC (rev 451) @@ -157,6 +157,14 @@ #endif #endif +#if defined(HAVE_NATIVETHREAD) || defined(HAVE_RB_THREAD_BLOCKING_REGION) +/* + * oci8_errhp is a thread local object in ruby 1.9, rubinius + * and ruby 1.8 configured with --enable-pthread. + */ +#define USE_THREAD_LOCAL_ERRHP 1 +#endif + /* macros depends on the compiler. * LIKELY(x) hint for the compiler that 'x' is 1(TRUE) in many cases. * UNLIKELY(x) hint for the compiler that 'x' is 0(FALSE) in many cases. @@ -189,8 +197,8 @@ * set a value to the key. * */ -#ifdef HAVE_RB_THREAD_BLOCKING_REGION -/* ruby 1.9 */ +#ifdef USE_THREAD_LOCAL_ERRHP +/* rubies with native-thread support. */ #if defined(_WIN32) #include #define oci8_tls_key_t DWORD @@ -384,7 +392,7 @@ * extern OCIError *oci8_errhp; */ #define oci8_envhp (LIKELY(oci8_global_envhp != NULL) ? oci8_global_envhp : oci8_make_envhp()) -#ifdef HAVE_RB_THREAD_BLOCKING_REGION +#ifdef USE_THREAD_LOCAL_ERRHP #define oci8_errhp oci8_get_errhp() #else #define oci8_errhp (LIKELY(oci8_global_errhp != NULL) ? oci8_global_errhp : oci8_make_errhp()) @@ -394,7 +402,7 @@ extern ub4 oci8_env_mode; extern OCIEnv *oci8_global_envhp; OCIEnv *oci8_make_envhp(void); -#ifdef HAVE_RB_THREAD_BLOCKING_REGION +#ifdef USE_THREAD_LOCAL_ERRHP extern oci8_tls_key_t oci8_tls_key; /* native thread key */ OCIError *oci8_make_errhp(void); Modified: trunk/ruby-oci8/ext/oci8/ocidatetime.c =================================================================== --- trunk/ruby-oci8/ext/oci8/ocidatetime.c 2011-10-01 03:14:45 UTC (rev 450) +++ trunk/ruby-oci8/ext/oci8/ocidatetime.c 2011-10-01 04:20:02 UTC (rev 451) @@ -2,9 +2,6 @@ /* * ocidatetime.c * - * $Author$ - * $Date$ - * * Copyright (C) 2005-2008 KUBO Takehiro * */ Modified: trunk/ruby-oci8/ext/oci8/oradate.c =================================================================== --- trunk/ruby-oci8/ext/oci8/oradate.c 2011-10-01 03:14:45 UTC (rev 450) +++ trunk/ruby-oci8/ext/oci8/oradate.c 2011-10-01 04:20:02 UTC (rev 451) @@ -2,9 +2,6 @@ /* * oradate.c * - * $Author$ - * $Date$ - * * Copyright (C) 2002-2008 KUBO Takehiro * * date and time between 4712 B.C. and 9999 A.D. Modified: trunk/ruby-oci8/ext/oci8/thread_util.c =================================================================== --- trunk/ruby-oci8/ext/oci8/thread_util.c 2011-10-01 03:14:45 UTC (rev 450) +++ trunk/ruby-oci8/ext/oci8/thread_util.c 2011-10-01 04:20:02 UTC (rev 451) @@ -7,6 +7,8 @@ #include "oci8.h" #include +#ifdef USE_THREAD_LOCAL_ERRHP + #ifndef WIN32 #include static pthread_attr_t detached_thread_attr; @@ -51,7 +53,7 @@ return 0; } -#else +#else /* WIN32 */ static void *adapter(void *arg) { @@ -78,4 +80,6 @@ } return rv; } -#endif +#endif /* WIN32 */ + +#endif /* USE_THREAD_LOCAL_ERRHP */ Modified: trunk/ruby-oci8/ext/oci8/thread_util.h =================================================================== --- trunk/ruby-oci8/ext/oci8/thread_util.h 2011-10-01 03:14:45 UTC (rev 450) +++ trunk/ruby-oci8/ext/oci8/thread_util.h 2011-10-01 04:20:02 UTC (rev 451) @@ -4,7 +4,7 @@ * * Copyright (C) 2011 KUBO Takehiro */ -#ifndef NATIVE_THREAD_H +#ifdef USE_THREAD_LOCAL_ERRHP /* * Prepare to execute thread-related functions. @@ -18,4 +18,13 @@ */ int oci8_run_native_thread(rb_blocking_function_t func, void *arg); +#else + +/* + * For ruby 1.8 configured without --enable-pthread on Unix. + */ + +#define Init_oci8_thread_util() do {} while (0) +#define oci8_run_native_thread(func, arg) ((func)(arg), 0) + #endif From nobody at rubyforge.org Sun Oct 9 09:26:28 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sun, 9 Oct 2011 09:26:28 -0400 (EDT) Subject: [ruby-oci8-commit] [452] trunk/ruby-oci8: add OCI8::BindType::OCITimestamp, OCI8::BindType:: LocalDateTime, Message-ID: <20111009132628.6C02E185837D@rubyforge.org> Revision: 452 Author: kubo Date: 2011-10-09 09:26:27 -0400 (Sun, 09 Oct 2011) Log Message: ----------- add OCI8::BindType::OCITimestamp, OCI8::BindType::LocalDateTime, OCI8::BindType::UTCDateTime, OCI8::BindType::LocalTime and OCI8::BindType::UTCTime. The first is used for internal use. The others are used for timestamp (without time zone) datatype. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/ocidatetime.c trunk/ruby-oci8/lib/oci8/datetime.rb trunk/ruby-oci8/lib/oci8/object.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-10-01 04:20:02 UTC (rev 451) +++ trunk/ruby-oci8/ChangeLog 2011-10-09 13:26:27 UTC (rev 452) @@ -1,3 +1,10 @@ +2011-10-09 KUBO Takehiro + * ext/oci8/ocidatetime.c, lib/oci8/datetime.rb, lib/oci8/object.rb: + add OCI8::BindType::OCITimestamp, OCI8::BindType::LocalDateTime, + OCI8::BindType::UTCDateTime, OCI8::BindType::LocalTime and + OCI8::BindType::UTCTime. The first is used for internal use. + The others are used for timestamp (without time zone) datatype. + 2011-10-01 KUBO Takehiro * ext/oci8/attr.c, ext/oci8/ocidatetime.c, ext/oci8/oradate.c: delete subversion keywords. Modified: trunk/ruby-oci8/ext/oci8/ocidatetime.c =================================================================== --- trunk/ruby-oci8/ext/oci8/ocidatetime.c 2011-10-01 04:20:02 UTC (rev 451) +++ trunk/ruby-oci8/ext/oci8/ocidatetime.c 2011-10-09 13:26:27 UTC (rev 452) @@ -2,7 +2,7 @@ /* * ocidatetime.c * - * Copyright (C) 2005-2008 KUBO Takehiro + * Copyright (C) 2005-2011 KUBO Takehiro * */ #include "oci8.h" @@ -65,6 +65,12 @@ return od; } +static void bind_init_common(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length) +{ + obind->value_sz = sizeof(void *); + obind->alloc_sz = sizeof(void *); +} + static void bind_init_elem_common(oci8_bind_t *obind, VALUE svc, ub4 type) { ub4 idx = 0; @@ -95,7 +101,7 @@ oci8_bind_free(base); } -VALUE oci8_make_ocitimestamp_tz(OCIDateTime *dttm) +VALUE oci8_make_ocitimestamp(OCIDateTime *dttm, boolean have_tz) { sb2 year; ub1 month; @@ -106,13 +112,12 @@ ub4 fsec; sb1 tz_hour; sb1 tz_minute; - sword rv; - int have_tz; oci_lc(OCIDateTimeGetDate(oci8_envhp, oci8_errhp, dttm, &year, &month, &day)); oci_lc(OCIDateTimeGetTime(oci8_envhp, oci8_errhp, dttm, &hour, &minute, &sec, &fsec)); - rv = OCIDateTimeGetTimeZoneOffset(oci8_envhp, oci8_errhp, dttm, &tz_hour, &tz_minute); - have_tz = (rv == OCI_SUCCESS); + if (have_tz) { + oci_lc(OCIDateTimeGetTimeZoneOffset(oci8_envhp, oci8_errhp, dttm, &tz_hour, &tz_minute)); + } return rb_ary_new3(9, INT2FIX(year), INT2FIX(month), @@ -207,9 +212,43 @@ return dttm; } +static VALUE bind_ocitimestamp_get(oci8_bind_t *obind, void *data, void *null_struct) +{ + return oci8_make_ocitimestamp(*(OCIDateTime **)data, FALSE); +} + +static void bind_ocitimestamp_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val) +{ + oci8_set_ocitimestamp_tz(*(OCIDateTime **)data, val, Qnil); +} + +static void bind_ocitimestamp_init_elem(oci8_bind_t *obind, VALUE svc) +{ + bind_init_elem_common(obind, svc, OCI_DTYPE_TIMESTAMP); +} + +static void bind_ocitimestamp_free(oci8_base_t *base) +{ + bind_free_common(base, OCI_DTYPE_TIMESTAMP); +} + +static const oci8_bind_vtable_t bind_ocitimestamp_vtable = { + { + NULL, + bind_ocitimestamp_free, + sizeof(oci8_bind_t) + }, + bind_ocitimestamp_get, + bind_ocitimestamp_set, + bind_init_common, + bind_ocitimestamp_init_elem, + NULL, + SQLT_TIMESTAMP +}; + static VALUE bind_ocitimestamp_tz_get(oci8_bind_t *obind, void *data, void *null_struct) { - return oci8_make_ocitimestamp_tz(*(OCIDateTime **)data); + return oci8_make_ocitimestamp(*(OCIDateTime **)data, TRUE); } static void bind_ocitimestamp_tz_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val) @@ -378,12 +417,6 @@ oci8_set_ociinterval_ym(*(OCIInterval **)data, val); } -static void bind_ociinterval_ym_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length) -{ - obind->value_sz = sizeof(OCIInterval*); - obind->alloc_sz = sizeof(OCIInterval*); -} - static void bind_ociinterval_ym_init_elem(oci8_bind_t *obind, VALUE svc) { bind_init_elem_common(obind, svc, OCI_DTYPE_INTERVAL_YM); @@ -404,12 +437,6 @@ oci8_set_ociinterval_ds(*(OCIInterval **)data, val); } -static void bind_ociinterval_ds_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length) -{ - obind->value_sz = sizeof(OCIInterval *); - obind->alloc_sz = sizeof(OCIInterval *); -} - static void bind_ociinterval_ds_init_elem(oci8_bind_t *obind, VALUE svc) { bind_init_elem_common(obind, svc, OCI_DTYPE_INTERVAL_DS); @@ -428,7 +455,7 @@ }, bind_ociinterval_ym_get, bind_ociinterval_ym_set, - bind_ociinterval_ym_init, + bind_init_common, bind_ociinterval_ym_init_elem, NULL, SQLT_INTERVAL_YM @@ -442,7 +469,7 @@ }, bind_ociinterval_ds_get, bind_ociinterval_ds_set, - bind_ociinterval_ds_init, + bind_init_common, bind_ociinterval_ds_init_elem, NULL, SQLT_INTERVAL_DS @@ -450,6 +477,7 @@ void Init_oci_datetime(void) { + oci8_define_bind_class("OCITimestamp", &bind_ocitimestamp_vtable); oci8_define_bind_class("OCITimestampTZ", &bind_ocitimestamp_tz_vtable); oci8_define_bind_class("OCIIntervalYM", &bind_ociinterval_ym_vtable); oci8_define_bind_class("OCIIntervalDS", &bind_ociinterval_ds_vtable); Modified: trunk/ruby-oci8/lib/oci8/datetime.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/datetime.rb 2011-10-01 04:20:02 UTC (rev 451) +++ trunk/ruby-oci8/lib/oci8/datetime.rb 2011-10-09 13:26:27 UTC (rev 452) @@ -59,7 +59,7 @@ private - def datetime_to_array(val, full) + def datetime_to_array(val, datatype) return nil if val.nil? # year @@ -98,7 +98,7 @@ else sec = 0 end - return [year, month, day, hour, minute, sec] unless full + return [year, month, day, hour, minute, sec] if datatype == :date # fractional second if val.respond_to? :sec_fraction @@ -110,6 +110,8 @@ else fsec = 0 end + return [year, month, day, hour, minute, sec, fsec, nil, nil] if datatype == :timestamp + # time zone if val.respond_to? :offset # DateTime @@ -134,55 +136,40 @@ [year, month, day, hour, minute, sec, fsec, tz_hour, tz_min] end - def ocidate_to_datetime(ary) + def array_to_datetime(ary, timezone) return nil if ary.nil? - year, month, day, hour, minute, sec = ary - if @@default_timezone == :local - if ::DateTime.respond_to? :local_offset - offset = ::DateTime.local_offset # Use a method defined by active support. + year, month, day, hour, minute, sec, nsec, tz_hour, tz_min = ary + sec += nsec.to_r / 1000000000 if nsec and nsec != 0 + if tz_hour and tz_min + offset = tz_hour.to_r / 24 + tz_min.to_r / 1440 + else + if @@default_timezone == :local + if ::DateTime.respond_to? :local_offset + offset = ::DateTime.local_offset # Use a method defined by active support. + else + # Do as active support does. + offset = ::Time.local(2007).utc_offset.to_r / 86400 + end else - # Do as active support does. - offset = ::Time.local(2007).utc_offset.to_r / 86400 + offset = 0 end - else - offset = 0 end - ::DateTime.civil(year, month, day, hour, minute, sec, offset) - end - def ocidate_to_time(ary) - return nil if ary.nil? - - year, month, day, hour, minute, sec = ary - if @@time_new_accepts_timezone || year >= 139 || year < 0 - begin - return ::Time.send(@@default_timezone, year, month, day, hour, minute, sec) - rescue StandardError - end - end - ocidate_to_datetime(ary) - end - - def ocitimestamp_to_datetime(ary) - return nil if ary.nil? - - year, month, day, hour, minute, sec, fsec, tz_hour, tz_min = ary - if @@datetime_has_fractional_second_bug and sec >= 59 and fsec != 0 + if @@datetime_has_fractional_second_bug and sec >= 59 and nsec != 0 # convert to a DateTime via a String as a workaround - if tz_hour >= 0 && tz_min >= 0 + if offset >= 0 sign = ?+ else sign = ?- - tz_hour = - tz_hour - tz_min = - tz_min + offset = - offset; end + tz_min = (offset * 1440).to_i + tz_hour, tz_min = tz_min.divmod 60 time_str = format("%04d-%02d-%02dT%02d:%02d:%02d.%09d%c%02d:%02d", - year, month, day, hour, minute, sec, fsec, sign, tz_hour, tz_min) + year, month, day, hour, minute, sec, nsec, sign, tz_hour, tz_min) ::DateTime.parse(time_str) else - sec += fsec.to_r / 1000000000 - offset = tz_hour.to_r / 24 + tz_min.to_r / 1440 ::DateTime.civil(year, month, day, hour, minute, sec, offset) end end @@ -190,36 +177,48 @@ if @@time_new_accepts_timezone # after ruby 1.9.2 - def ocitimestamp_to_time(ary) + def array_to_time(ary, timezone) return nil if ary.nil? - year, month, day, hour, minute, sec, fsec, tz_hour, tz_min = ary + year, month, day, hour, minute, sec, nsec, tz_hour, tz_min = ary + nsec ||= 0 - sec += fsec / Rational(1000000000) - utc_offset = tz_hour * 3600 + tz_min * 60 - return ::Time.new(year, month, day, hour, minute, sec, utc_offset) + if timezone + usec = (nsec == 0) ? 0 : nsec.to_r / 1000 + ::Time.send(timezone, year, month, day, hour, minute, sec, usec) + else + sec += nsec.to_r / 1_000_000_000 if nsec != 0 + utc_offset = tz_hour * 3600 + tz_min * 60 + ::Time.new(year, month, day, hour, minute, sec, utc_offset) + end end else # prior to ruby 1.9.2 - def ocitimestamp_to_time(ary) + def array_to_time(ary, timezone) return nil if ary.nil? - year, month, day, hour, minute, sec, fsec, tz_hour, tz_min = ary - - if year >= 139 || year < 0 - begin + year, month, day, hour, minute, sec, nsec, tz_hour, tz_min = ary + nsec ||= 0 + usec = (nsec == 0) ? 0 : nsec.to_r / 1000 + begin + if timezone + return ::Time.send(:timezone, year, month, day, hour, minute, sec, usec) + else if tz_hour == 0 and tz_min == 0 - return ::Time.utc(year, month, day, hour, minute, sec, fsec / Rational(1000)) + tm = ::Time.utc(year, month, day, hour, minute, sec, usec) + # Time.utc(99, ...) returns a time object the year of which is 1999. + # 'tm.year == year' checks such cases. + return tm if tm.year == year else - tm = ::Time.local(year, month, day, hour, minute, sec, fsec / Rational(1000)) - return tm if tm.utc_offset == tz_hour * 3600 + tz_min * 60 + tm = ::Time.local(year, month, day, hour, minute, sec, usec) + return tm if tm.utc_offset == tz_hour * 3600 + tz_min * 60 and tm.year == year end - rescue StandardError end + rescue StandardError end - ocitimestamp_to_datetime(ary) + array_to_datetime(ary, timezone) end end @@ -290,14 +289,38 @@ include OCI8::BindType::Util def set(val) # :nodoc: - super(datetime_to_array(val, true)) + super(datetime_to_array(val, :timestamp_tz)) end def get() # :nodoc: - ocitimestamp_to_datetime(super()) + array_to_datetime(super(), nil) end end + class LocalDateTime < OCI8::BindType::OCITimestamp + include OCI8::BindType::Util + + def set(val) # :nodoc: + super(datetime_to_array(val, :timestamp)) + end + + def get() # :nodoc: + array_to_datetime(super(), :local) + end + end + + class UTCDateTime < OCI8::BindType::OCITimestamp + include OCI8::BindType::Util + + def set(val) # :nodoc: + super(datetime_to_array(val, :timestamp)) + end + + def get() # :nodoc: + array_to_datetime(super(), :utc) + end + end + #-- # OCI8::BindType::Time #++ @@ -365,202 +388,224 @@ include OCI8::BindType::Util def set(val) # :nodoc: - super(datetime_to_array(val, true)) + super(datetime_to_array(val, :timestamp_tz)) end def get() # :nodoc: - ocitimestamp_to_time(super()) + array_to_time(super(), nil) end end - if OCI8.oracle_client_version >= ORAVER_9_0 - #-- - # OCI8::BindType::IntervalYM - #++ - # - # This is a helper class to select or bind Oracle data type - # INTERVAL YEAR TO MONTH. The retrieved value is - # the number of months between two timestamps. - # - # The value can be applied to \DateTime#>> to shift months. - # It can be applied to \Time#months_since if activisupport has - # been loaded. - # - # === How to select INTERVAL YEAR TO MONTH - # - # INTERVAL YEAR TO MONTH is selected as an Integer. - # - # conn.exec("select (current_timestamp - hiredate) year to month from emp") do |hired_months| - # puts "hired_months = #{hired_months}" - # end - # - # == How to bind INTERVAL YEAR TO MONTH - # - # You cannot bind a bind variable as INTERVAL YEAR TO MONTH implicitly. - # It must be bound explicitly by OCI8::Cursor#bind_param. - # - # # output bind variable - # cursor = conn.parse(<<-EOS) - # BEGIN - # :interval := (:ts1 - :ts2) YEAR TO MONTH; - # END; - # EOS - # cursor.bind_param(:interval, nil, :interval_ym) - # cursor.bind_param(:ts1, DateTime.parse('1969-11-19 06:54:35 00:00')) - # cursor.bind_param(:ts2, DateTime.parse('1969-07-20 20:17:40 00:00')) - # cursor.exec - # cursor[:interval] # => 4 (months) - # cursor.close - # - # # input bind variable - # cursor = conn.parse(<<-EOS) - # BEGIN - # :ts1 := :ts2 + :interval; - # END; - # EOS - # cursor.bind_param(:ts1, nil, DateTime) - # cursor.bind_param(:ts2, Date.parse('1969-11-19')) - # cursor.bind_param(:interval, 4, :interval_ym) - # cursor.exec - # cursor[:ts1].strftime('%Y-%m-%d') # => 1970-03-19 - # cursor.close - # - class IntervalYM < OCI8::BindType::OCIIntervalYM - def set(val) # :nodoc: - unless val.nil? - val = [val / 12, val % 12] - end - super(val) + class LocalTime < OCI8::BindType::OCITimestamp + include OCI8::BindType::Util + + def set(val) # :nodoc: + super(datetime_to_array(val, :timestamp)) + end + + def get() # :nodoc: + array_to_time(super(), :local) + end + end + + class UTCTime < OCI8::BindType::OCITimestamp + include OCI8::BindType::Util + + def set(val) # :nodoc: + super(datetime_to_array(val, :timestamp)) + end + + def get() # :nodoc: + array_to_time(super(), :utc) + end + end + + #-- + # OCI8::BindType::IntervalYM + #++ + # + # This is a helper class to select or bind Oracle data type + # INTERVAL YEAR TO MONTH. The retrieved value is + # the number of months between two timestamps. + # + # The value can be applied to \DateTime#>> to shift months. + # It can be applied to \Time#months_since if activisupport has + # been loaded. + # + # === How to select INTERVAL YEAR TO MONTH + # + # INTERVAL YEAR TO MONTH is selected as an Integer. + # + # conn.exec("select (current_timestamp - hiredate) year to month from emp") do |hired_months| + # puts "hired_months = #{hired_months}" + # end + # + # == How to bind INTERVAL YEAR TO MONTH + # + # You cannot bind a bind variable as INTERVAL YEAR TO MONTH implicitly. + # It must be bound explicitly by OCI8::Cursor#bind_param. + # + # # output bind variable + # cursor = conn.parse(<<-EOS) + # BEGIN + # :interval := (:ts1 - :ts2) YEAR TO MONTH; + # END; + # EOS + # cursor.bind_param(:interval, nil, :interval_ym) + # cursor.bind_param(:ts1, DateTime.parse('1969-11-19 06:54:35 00:00')) + # cursor.bind_param(:ts2, DateTime.parse('1969-07-20 20:17:40 00:00')) + # cursor.exec + # cursor[:interval] # => 4 (months) + # cursor.close + # + # # input bind variable + # cursor = conn.parse(<<-EOS) + # BEGIN + # :ts1 := :ts2 + :interval; + # END; + # EOS + # cursor.bind_param(:ts1, nil, DateTime) + # cursor.bind_param(:ts2, Date.parse('1969-11-19')) + # cursor.bind_param(:interval, 4, :interval_ym) + # cursor.exec + # cursor[:ts1].strftime('%Y-%m-%d') # => 1970-03-19 + # cursor.close + # + class IntervalYM < OCI8::BindType::OCIIntervalYM + def set(val) # :nodoc: + unless val.nil? + val = [val / 12, val % 12] end - def get() # :nodoc: - val = super() - return nil if val.nil? - year, month = val - year * 12 + month - end - end # OCI8::BindType::IntervalYM + super(val) + end + def get() # :nodoc: + val = super() + return nil if val.nil? + year, month = val + year * 12 + month + end + end # OCI8::BindType::IntervalYM - #-- - # OCI8::BindType::IntervalDS - #++ + #-- + # OCI8::BindType::IntervalDS + #++ + # + # (new in 2.0) + # + # This is a helper class to select or bind Oracle data type + # INTERVAL DAY TO SECOND. The retrieved value is + # the number of seconds between two typestamps as a \Float. + # + # Note that it is the number days as a \Rational if + # OCI8::BindType::IntervalDS.unit is :day or the ruby-oci8 + # version is prior to 2.0.3. + # + # == How to bind INTERVAL DAY TO SECOND + # + # You cannot bind a bind variable as INTERVAL DAY TO SECOND + # implicitly. It must be bound explicitly by OCI8::Cursor#bind_param. + # + # # output bind variable + # cursor = conn.parse(<<-EOS) + # BEGIN + # :interval := (:ts1 - :ts2) DAY TO SECOND(9); + # END; + # EOS + # cursor.bind_param(:interval, nil, :interval_ds) + # cursor.bind_param(:ts1, DateTime.parse('1969-11-19 06:54:35 00:00')) + # cursor.bind_param(:ts2, DateTime.parse('1969-07-20 20:17:40 00:00')) + # cursor.exec + # cursor[:interval] # => 10492615.0 seconds + # cursor.close + # + # # input bind variable + # cursor = conn.parse(<<-EOS) + # BEGIN + # :ts1 := :ts2 + :interval; + # END; + # EOS + # cursor.bind_param(:ts1, nil, DateTime) + # cursor.bind_param(:ts2, DateTime.parse('1969-07-20 20:17:40 00:00')) + # cursor.bind_param(:interval, 10492615.0, :interval_ds) + # cursor.exec + # cursor[:ts1].strftime('%Y-%m-%d %H:%M:%S') # => 1969-11-19 06:54:35 + # cursor.close + # + class IntervalDS < OCI8::BindType::OCIIntervalDS + @@hour = 1 / 24.to_r + @@minute = @@hour / 60 + @@sec = @@minute / 60 + @@fsec = @@sec / 1000000000 + @@unit = :second + + # call-seq: + # OCI8::BindType::IntervalDS.unit -> :second or :day # - # (new in 2.0) + # (new in 2.0.3) # - # This is a helper class to select or bind Oracle data type - # INTERVAL DAY TO SECOND. The retrieved value is - # the number of seconds between two typestamps as a \Float. + # Retrieves the unit of interval. + def self.unit + @@unit + end + + # call-seq: + # OCI8::BindType::IntervalDS.unit = :second or :day # - # Note that it is the number days as a \Rational if - # OCI8::BindType::IntervalDS.unit is :day or the ruby-oci8 - # version is prior to 2.0.3. + # (new in 2.0.3) # - # == How to bind INTERVAL DAY TO SECOND - # - # You cannot bind a bind variable as INTERVAL DAY TO SECOND - # implicitly. It must be bound explicitly by OCI8::Cursor#bind_param. - # - # # output bind variable - # cursor = conn.parse(<<-EOS) - # BEGIN - # :interval := (:ts1 - :ts2) DAY TO SECOND(9); - # END; - # EOS - # cursor.bind_param(:interval, nil, :interval_ds) - # cursor.bind_param(:ts1, DateTime.parse('1969-11-19 06:54:35 00:00')) - # cursor.bind_param(:ts2, DateTime.parse('1969-07-20 20:17:40 00:00')) - # cursor.exec - # cursor[:interval] # => 10492615.0 seconds - # cursor.close - # - # # input bind variable - # cursor = conn.parse(<<-EOS) - # BEGIN - # :ts1 := :ts2 + :interval; - # END; - # EOS - # cursor.bind_param(:ts1, nil, DateTime) - # cursor.bind_param(:ts2, DateTime.parse('1969-07-20 20:17:40 00:00')) - # cursor.bind_param(:interval, 10492615.0, :interval_ds) - # cursor.exec - # cursor[:ts1].strftime('%Y-%m-%d %H:%M:%S') # => 1969-11-19 06:54:35 - # cursor.close - # - class IntervalDS < OCI8::BindType::OCIIntervalDS - @@hour = 1 / 24.to_r - @@minute = @@hour / 60 - @@sec = @@minute / 60 - @@fsec = @@sec / 1000000000 - @@unit = :second - - # call-seq: - # OCI8::BindType::IntervalDS.unit -> :second or :day - # - # (new in 2.0.3) - # - # Retrieves the unit of interval. - def self.unit - @@unit + # Changes the unit of interval. :second is the default. + def self.unit=(val) + case val + when :second, :day + @@unit = val + else + raise 'unit should be :second or :day' end + end - # call-seq: - # OCI8::BindType::IntervalDS.unit = :second or :day - # - # (new in 2.0.3) - # - # Changes the unit of interval. :second is the default. - def self.unit=(val) - case val - when :second, :day - @@unit = val + def set(val) # :nodoc: + unless val.nil? + if val < 0 + is_minus = true + val = -val else - raise 'unit should be :second or :day' + is_minus = false end - end - - def set(val) # :nodoc: - unless val.nil? - if val < 0 - is_minus = true - val = -val - else - is_minus = false - end - if @@unit == :second - day, val = val.divmod 86400 - hour, val = val.divmod 3600 - minute, val = val.divmod 60 - sec, val = val.divmod 1 - else - day, val = val.divmod 1 - hour, val = (val * 24).divmod 1 - minute, val = (val * 60).divmod 1 - sec, val = (val * 60).divmod 1 - end - fsec, val = (val * 1000000000).divmod 1 - if is_minus - day = - day - hour = - hour - minute = - minute - sec = - sec - fsec = - fsec - end - val = [day, hour, minute, sec, fsec] - end - super(val) - end - - def get() # :nodoc: - val = super() - return nil if val.nil? - day, hour, minute, sec, fsec = val if @@unit == :second - fsec = fsec / 1000000000.0 - day * 86400 + hour * 3600 + minute * 60 + sec + fsec + day, val = val.divmod 86400 + hour, val = val.divmod 3600 + minute, val = val.divmod 60 + sec, val = val.divmod 1 else - day + (hour * @@hour) + (minute * @@minute) + (sec * @@sec) + (fsec * @@fsec) + day, val = val.divmod 1 + hour, val = (val * 24).divmod 1 + minute, val = (val * 60).divmod 1 + sec, val = (val * 60).divmod 1 end + fsec, val = (val * 1000000000).divmod 1 + if is_minus + day = - day + hour = - hour + minute = - minute + sec = - sec + fsec = - fsec + end + val = [day, hour, minute, sec, fsec] end - end # OCI8::BindType::IntervalDS - end + super(val) + end + + def get() # :nodoc: + val = super() + return nil if val.nil? + day, hour, minute, sec, fsec = val + if @@unit == :second + fsec = fsec / 1000000000.0 + day * 86400 + hour * 3600 + minute * 60 + sec + fsec + else + day + (hour * @@hour) + (minute * @@minute) + (sec * @@sec) + (fsec * @@fsec) + end + end + end # OCI8::BindType::IntervalDS end # OCI8::BindType end # OCI8 Modified: trunk/ruby-oci8/lib/oci8/object.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/object.rb 2011-10-01 04:20:02 UTC (rev 451) +++ trunk/ruby-oci8/lib/oci8/object.rb 2011-10-09 13:26:27 UTC (rev 452) @@ -425,7 +425,7 @@ 'INTERVAL DAY TO SECOND' => :interval_ds, } - # for datetime_to_array and ocidate_to_datetime + # to use datetime_to_array and array_to_datetime extend OCI8::BindType::Util def self.check_metadata(con, metadata) @@ -442,8 +442,8 @@ [ATTR_FLOAT, nil, SIZE_OF_OCINUMBER, 2, ALIGNMENT_OF_OCINUMBER] when :date [ATTR_OCIDATE, nil, SIZE_OF_OCIDATE, 2, ALIGNMENT_OF_OCIDATE, - Proc.new do |val| datetime_to_array(val, false) end, # set_proc - Proc.new do |val| ocidate_to_datetime(val) end, # get_proc + Proc.new do |val| datetime_to_array(val, :date) end, # set_proc + Proc.new do |val| array_to_datetime(val) end, # get_proc ] when :binary_double [ATTR_BINARY_DOUBLE, nil, SIZE_OF_DOUBLE, 2, ALIGNMENT_OF_DOUBLE] From nobody at rubyforge.org Mon Oct 17 08:50:51 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Mon, 17 Oct 2011 08:50:51 -0400 (EDT) Subject: [ruby-oci8-commit] [453] trunk/ruby-oci8: embed a run-time loading path to the extention library oci8lib_*. so compiled for not only full clients, but also instant clients on Linux and Solaris. Message-ID: <20111017125051.D3A261858367@rubyforge.org> Revision: 453 Author: kubo Date: 2011-10-17 08:50:51 -0400 (Mon, 17 Oct 2011) Log Message: ----------- embed a run-time loading path to the extention library oci8lib_*.so compiled for not only full clients, but also instant clients on Linux and Solaris. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/oraconf.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-10-09 13:26:27 UTC (rev 452) +++ trunk/ruby-oci8/ChangeLog 2011-10-17 12:50:51 UTC (rev 453) @@ -1,3 +1,9 @@ +2011-10-17 KUBO Takehiro + * ext/oci8/oraconf.rb: embed a run-time loading path to the extention + library oci8lib_*.so compiled for not only full clients, but also + instant clients on Linux and Solaris. + (suggested by d c and others.) + 2011-10-09 KUBO Takehiro * ext/oci8/ocidatetime.c, lib/oci8/datetime.rb, lib/oci8/object.rb: add OCI8::BindType::OCITimestamp, OCI8::BindType::LocalDateTime, Modified: trunk/ruby-oci8/ext/oci8/oraconf.rb =================================================================== --- trunk/ruby-oci8/ext/oci8/oraconf.rb 2011-10-09 13:26:27 UTC (rev 452) +++ trunk/ruby-oci8/ext/oci8/oraconf.rb 2011-10-17 12:50:51 UTC (rev 453) @@ -703,6 +703,19 @@ end end + else + # Unix + def get_libs(lib_dir) + case RUBY_PLATFORM + when /solaris/ + " -L#{lib_dir} -R#{lib_dir} -lclntsh" + when /linux/ + " -L#{lib_dir} -Wl,-rpath,#{lib_dir} -lclntsh" + else + " -L#{lib_dir} -lclntsh" + end + end + end end @@ -735,14 +748,7 @@ else lib_dir = "#{@oracle_home}/lib" end - case RUBY_PLATFORM - when /solaris/ - @libs = " -L#{lib_dir} -R#{lib_dir} -lclntsh" - when /linux/ - @libs = " -L#{lib_dir} -Wl,-rpath,#{lib_dir} -lclntsh" - else - @libs = " -L#{lib_dir} -lclntsh" - end + @libs = get_libs(lib_dir) return if try_link_oci() end @@ -1119,7 +1125,7 @@ end raise 'failed' end - @libs = " -L#{lib_dir} -lclntsh " + @libs = get_libs(lib_dir) end unless File.exist?("#{inc_dir}/oci.h") raise < Revision: 454 Author: kubo Date: 2011-10-21 09:26:03 -0400 (Fri, 21 Oct 2011) Log Message: ----------- remove code to get linker options for Oracle 8 and Oracle 8i. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/oraconf.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-10-17 12:50:51 UTC (rev 453) +++ trunk/ruby-oci8/ChangeLog 2011-10-21 13:26:03 UTC (rev 454) @@ -1,3 +1,7 @@ +2011-10-21 KUBO Takehiro + * ext/oci8/oraconf.rb: remove code to get linker options for Oracle 8 + and Oracle 8i. + 2011-10-17 KUBO Takehiro * ext/oci8/oraconf.rb: embed a run-time loading path to the extention library oci8lib_*.so compiled for not only full clients, but also Modified: trunk/ruby-oci8/ext/oci8/oraconf.rb =================================================================== --- trunk/ruby-oci8/ext/oci8/oraconf.rb 2011-10-17 12:50:51 UTC (rev 453) +++ trunk/ruby-oci8/ext/oci8/oraconf.rb 2011-10-21 13:26:03 UTC (rev 454) @@ -741,27 +741,12 @@ use_lib32 = false end - # default - if @version.to_i >= 900 - if use_lib32 - lib_dir = "#{@oracle_home}/lib32" - else - lib_dir = "#{@oracle_home}/lib" - end - @libs = get_libs(lib_dir) - return if try_link_oci() - end - - # get from demo_rdbms.mk if use_lib32 - if File.exist?("#{@oracle_home}/rdbms/demo/demo_rdbms32.mk") - @libs = get_libs('32', '') - else - @libs = get_libs('', '32') - end + lib_dir = "#{@oracle_home}/lib32" else - @libs = get_libs() + lib_dir = "#{@oracle_home}/lib" end + @libs = get_libs(lib_dir) return if try_link_oci() raise 'cannot compile OCI' @@ -966,70 +951,6 @@ end end # get_cflags - def get_libs(postfix1 = '', postfix2 = "") - print("Running make for $ORACLE_HOME/rdbms/demo/demo_rdbms#{postfix1}.mk (build#{postfix2}) ...") - STDOUT.flush - - make_opt = "CC='echo MARKER' EXE=/dev/null ECHODO=echo ECHO=echo GENCLNTSH='echo genclntsh'" - if @cc_is_gcc && /solaris/ =~ RUBY_PLATFORM - # suggested by Brian Candler. - make_opt += " KPIC_OPTION= NOKPIC_CCFLAGS#{postfix2}=" - end - - command = "|make -f #{@oracle_home}/rdbms/demo/demo_rdbms#{postfix1}.mk build#{postfix2} #{make_opt}" - marker = /^\s*MARKER/ - echo = /^\s*echo/ - libs = nil - Logging::open do - puts command - open(command, "r") do |f| - while line = f.gets - puts line - line.chomp! - line = $' while line =~ echo - if line =~ marker - # found a line where a compiler runs. - libs = $' - libs.gsub!(/-o\s+\/dev\/null/, "") - libs.gsub!(/-o\s+build/, "") - end - end - end - end - raise 'Cannot get proper libs.' if libs.nil? - print("OK\n") - - case RUBY_PLATFORM - when /hpux/ - if @cc_is_gcc - # strip +DA2.0W, +DS2.0, -Wl,+s, -Wl,+n - libs.gsub!(/\+DA\S+(\s)*/, "") - libs.gsub!(/\+DS\S+(\s)*/, "") - libs.gsub!(/-Wl,\+[sn](\s)*/, "") - end - libs.gsub!(/ -Wl,/, " ") - when /aix/ - if @cc_is_gcc - # strip -bI:/xxx - libs.gsub!(/(-bI:\S+)/, '') - end - end - - # check whether object files are included. - if /\S+\.o\b/ =~ libs - - # monkey patching! - Object.module_eval do - alias :link_command_pre_oci8 :link_command - def link_command(*args) - args[1] = "" if args[1] == $libs - link_command_pre_oci8(*args) - end - end - - end - libs - end # get_libs end end From nobody at rubyforge.org Fri Oct 21 10:10:10 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Fri, 21 Oct 2011 10:10:10 -0400 (EDT) Subject: [ruby-oci8-commit] [455] trunk/ruby-oci8: fix checking code whether 'sys/types.h' is available for Ubuntu 11.10 where sys/types.h is not right under /usr/ include. Message-ID: <20111021141010.5A13F15B802D@rubyforge.org> Revision: 455 Author: kubo Date: 2011-10-21 10:10:10 -0400 (Fri, 21 Oct 2011) Log Message: ----------- fix checking code whether 'sys/types.h' is available for Ubuntu 11.10 where sys/types.h is not right under /usr/include. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/oraconf.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-10-21 13:26:03 UTC (rev 454) +++ trunk/ruby-oci8/ChangeLog 2011-10-21 14:10:10 UTC (rev 455) @@ -1,4 +1,9 @@ 2011-10-21 KUBO Takehiro + * ext/oci8/oraconf.rb: fix checking code whether 'sys/types.h' is + available for Ubuntu 11.10 where sys/types.h is not right under + /usr/include. + +2011-10-21 KUBO Takehiro * ext/oci8/oraconf.rb: remove code to get linker options for Oracle 8 and Oracle 8i. Modified: trunk/ruby-oci8/ext/oci8/oraconf.rb =================================================================== --- trunk/ruby-oci8/ext/oci8/oraconf.rb 2011-10-21 13:26:03 UTC (rev 454) +++ trunk/ruby-oci8/ext/oci8/oraconf.rb 2011-10-21 14:10:10 UTC (rev 455) @@ -581,6 +581,7 @@ check_cc() @cc_is_gcc = check_cc_is_gcc() @lp64 = check_lp64() + check_system_header() check_ruby_header() end @@ -622,6 +623,15 @@ end end # check_lp64 + def check_system_header + if not have_header('sys/types.h') + raise < Revision: 456 Author: kubo Date: 2011-10-21 10:23:18 -0400 (Fri, 21 Oct 2011) Log Message: ----------- refactor OCIException and its subclasses. OCIError#codes and OCIError#messages are deleted. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/error.c trunk/ruby-oci8/ext/oci8/oci8.h trunk/ruby-oci8/test/test_all.rb Added Paths: ----------- trunk/ruby-oci8/test/test_error.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-10-21 14:10:10 UTC (rev 455) +++ trunk/ruby-oci8/ChangeLog 2011-10-21 14:23:18 UTC (rev 456) @@ -1,4 +1,10 @@ 2011-10-21 KUBO Takehiro + * ext/oci8/error.c, ext/oci8/oci8.h: refactor OCIException and its + subclasses. OCIError#codes and OCIError#messages are deleted. + * test/test_all.rb, test/test_error.rb: add a testcase to check + OCIException's methods. + +2011-10-21 KUBO Takehiro * ext/oci8/oraconf.rb: fix checking code whether 'sys/types.h' is available for Ubuntu 11.10 where sys/types.h is not right under /usr/include. Modified: trunk/ruby-oci8/ext/oci8/error.c =================================================================== --- trunk/ruby-oci8/ext/oci8/error.c 2011-10-21 14:10:10 UTC (rev 455) +++ trunk/ruby-oci8/ext/oci8/error.c 2011-10-21 14:23:18 UTC (rev 456) @@ -2,11 +2,8 @@ /* error.c - part of ruby-oci8 - Copyright (C) 2002-2010 KUBO Takehiro + Copyright (C) 2002-2011 KUBO Takehiro -=begin -== OCIError -=end */ #include "oci8.h" @@ -25,10 +22,9 @@ static VALUE eOCIContinue; static VALUE eOCISuccessWithInfo; -static ID oci8_id_code; -static ID oci8_id_message; -static ID oci8_id_parse_error_offset; -static ID oci8_id_sql; +static ID oci8_id_at_code; +static ID oci8_id_at_sql; +static ID oci8_id_at_parse_error_offset; static ID oci8_id_caller; static ID oci8_id_set_backtrace; @@ -38,13 +34,8 @@ static OCIMsg *msghp; -#ifndef OCI_DURATION_PROCESS -#define OCI_DURATION_PROCESS ((OCIDuration)5) -#endif +static VALUE set_backtrace(VALUE exc, const char *file, int line); -NORETURN(static void oci8_raise2(dvoid *errhp, sword status, ub4 type, OCIStmt *stmthp, const char *file, int line)); -NORETURN(static void set_backtrace_and_raise(VALUE exc, const char *file, int line)); - static VALUE get_error_msg(dvoid *errhp, ub4 type, const char *default_msg, sb4 *errcode_p) { sword rv; @@ -84,75 +75,40 @@ return rb_external_str_new_with_enc(errbuf, len, oci8_encoding); } -static void oci8_raise2(dvoid *errhp, sword status, ub4 type, OCIStmt *stmthp, const char *file, int line) +VALUE oci8_make_exc(dvoid *errhp, sword status, ub4 type, OCIStmt *stmthp, const char *file, int line) { - VALUE vcodes = Qnil; - VALUE vmessages = Qnil; VALUE exc; - char errmsg[1024]; - sb4 errcode; - ub4 recodeno; + char errmsg[128]; + sb4 errcode = -1; VALUE msg; -#ifdef OCI_ATTR_PARSE_ERROR_OFFSET - VALUE vparse_error_offset = Qnil; -#endif -#ifdef OCI_ATTR_STATEMENT - VALUE vsql = Qnil; -#endif - int i; + VALUE parse_error_offset = Qnil; + VALUE sql = Qnil; int rv; switch (status) { case OCI_ERROR: case OCI_SUCCESS_WITH_INFO: - vcodes = rb_ary_new(); - vmessages = rb_ary_new(); - for (recodeno = 1;;recodeno++) { - /* get error string */ - rv = OCIErrorGet(errhp, recodeno, NULL, &errcode, TO_ORATEXT(errmsg), sizeof(errmsg), type); - if (rv != OCI_SUCCESS) { - break; - } - /* chop error string */ - for (i = strlen(errmsg) - 1;i >= 0;i--) { - if (errmsg[i] == '\n' || errmsg[i] == '\r') { - errmsg[i] = '\0'; - } else { - break; - } - } - rb_ary_push(vcodes, INT2FIX(errcode)); - rb_ary_push(vmessages, rb_external_str_new_with_enc(errmsg, strlen(errmsg), oci8_encoding)); - } - if (RARRAY_LEN(vmessages) > 0) { - msg = RARRAY_PTR(vmessages)[0]; - } else { - msg = rb_usascii_str_new_cstr("ERROR"); - } + /* get error string */ + msg = get_error_msg(errhp, type, "Error", &errcode); if (status == OCI_ERROR) { exc = eOCIError; } else { exc = eOCISuccessWithInfo; } -#ifdef OCI_ATTR_PARSE_ERROR_OFFSET if (stmthp != NULL) { ub2 offset; + text *text; + ub4 size; + rv = OCIAttrGet(stmthp, OCI_HTYPE_STMT, &offset, 0, OCI_ATTR_PARSE_ERROR_OFFSET, errhp); if (rv == OCI_SUCCESS) { - vparse_error_offset = INT2FIX(offset); + parse_error_offset = INT2FIX(offset); } - } -#endif -#ifdef OCI_ATTR_STATEMENT - if (stmthp != NULL) { - text *sql; - ub4 size; - rv = OCIAttrGet(stmthp, OCI_HTYPE_STMT, &sql, &size, OCI_ATTR_STATEMENT, errhp); + rv = OCIAttrGet(stmthp, OCI_HTYPE_STMT, &text, &size, OCI_ATTR_STATEMENT, errhp); if (rv == OCI_SUCCESS) { - vsql = rb_external_str_new_with_enc(TO_CHARPTR(sql), size, oci8_encoding); + sql = rb_external_str_new_with_enc(TO_CHARPTR(text), size, oci8_encoding); } } -#endif break; case OCI_NO_DATA: exc = eOCINoData; @@ -176,30 +132,14 @@ break; default: sprintf(errmsg, "Unknown error (%d)", status); - exc = rb_eStandardError; + exc = eOCIException; msg = rb_usascii_str_new_cstr(errmsg); } - exc = rb_funcall(exc, oci8_id_new, 1, msg); - if (!NIL_P(vcodes)) { - rb_ivar_set(exc, oci8_id_code, vcodes); - } - if (!NIL_P(vmessages)) { - rb_ivar_set(exc, oci8_id_message, vmessages); - } -#ifdef OCI_ATTR_PARSE_ERROR_OFFSET - if (!NIL_P(vparse_error_offset)) { - rb_ivar_set(exc, oci8_id_parse_error_offset, vparse_error_offset); - } -#endif -#ifdef OCI_ATTR_STATEMENT - if (!NIL_P(vsql)) { - rb_ivar_set(exc, oci8_id_sql, vsql); - } -#endif - set_backtrace_and_raise(exc, file, line); + exc = rb_funcall(exc, oci8_id_new, 4, msg, INT2FIX(errcode), sql, parse_error_offset); + return set_backtrace(exc, file, line); } -static void set_backtrace_and_raise(VALUE exc, const char *file, int line) +static VALUE set_backtrace(VALUE exc, const char *file, int line) { char errmsg[64]; VALUE backtrace; @@ -215,87 +155,30 @@ rb_ary_unshift(backtrace, rb_usascii_str_new_cstr(errmsg)); rb_funcall(exc, oci8_id_set_backtrace, 1, backtrace); } - rb_exc_raise(exc); + return exc; } +/* + * call-seq: + * OCI8.new(message, code = nil, sql = nil, parse_error_offset = nil) + * + * Creates a new OCIException object. + */ static VALUE oci8_error_initialize(int argc, VALUE *argv, VALUE self) { VALUE msg; VALUE code; + VALUE sql; + VALUE parse_error_offset; - rb_scan_args(argc, argv, "02", &msg, &code); + rb_scan_args(argc, argv, "04", &msg, &code, &sql, &parse_error_offset); rb_call_super(argc > 1 ? 1 : argc, argv); - if (!NIL_P(code)) { - rb_ivar_set(self, oci8_id_code, rb_ary_new3(1, code)); - } + rb_ivar_set(self, oci8_id_at_code, code); + rb_ivar_set(self, oci8_id_at_sql, sql); + rb_ivar_set(self, oci8_id_at_parse_error_offset, parse_error_offset); return Qnil; } -/* -=begin ---- OCIError#code() -=end -*/ -static VALUE oci8_error_code(VALUE self) -{ - VALUE ary = rb_ivar_get(self, oci8_id_code); - if (RARRAY_LEN(ary) == 0) { - return Qnil; - } - return RARRAY_PTR(ary)[0]; -} - -/* -=begin ---- OCIError#codes() -=end -*/ -static VALUE oci8_error_code_array(VALUE self) -{ - return rb_ivar_get(self, oci8_id_code); -} - -/* -=begin ---- OCIError#message() -=end -*/ - -/* -=begin ---- OCIError#messages() -=end -*/ -static VALUE oci8_error_message_array(VALUE self) -{ - return rb_ivar_get(self, oci8_id_message); -} - -#ifdef OCI_ATTR_PARSE_ERROR_OFFSET -/* -=begin ---- OCIError#parseErrorOffset() -=end -*/ -static VALUE oci8_error_parse_error_offset(VALUE self) -{ - return rb_ivar_get(self, oci8_id_parse_error_offset); -} -#endif - -#ifdef OCI_ATTR_STATEMENT -/* -=begin ---- OCIError#sql() - (Oracle 8.1.6 or later) -=end -*/ -static VALUE oci8_error_sql(VALUE self) -{ - return rb_ivar_get(self, oci8_id_sql); -} -#endif - sb4 oci8_get_error_code(OCIError *errhp) { sb4 errcode = -1; @@ -308,10 +191,9 @@ errbufsiz = ERRBUF_EXPAND_LEN; errbuf = xmalloc(errbufsiz); - oci8_id_code = rb_intern("code"); - oci8_id_message = rb_intern("message"); - oci8_id_parse_error_offset = rb_intern("parse_error_offset"); - oci8_id_sql = rb_intern("sql"); + oci8_id_at_code = rb_intern("@code"); + oci8_id_at_sql = rb_intern("@sql"); + oci8_id_at_parse_error_offset = rb_intern("@parse_error_offset"); oci8_id_caller = rb_intern("caller"); oci8_id_set_backtrace = rb_intern("set_backtrace"); @@ -326,36 +208,29 @@ eOCIContinue = rb_define_class("OCIContinue", eOCIException); eOCISuccessWithInfo = rb_define_class("OCISuccessWithInfo", eOCIError); - rb_define_method(eOCIError, "initialize", oci8_error_initialize, -1); - rb_define_method(eOCIError, "code", oci8_error_code, 0); - rb_define_method(eOCIError, "codes", oci8_error_code_array, 0); - rb_define_method(eOCIError, "messages", oci8_error_message_array, 0); -#ifdef OCI_ATTR_PARSE_ERROR_OFFSET - rb_define_method(eOCIError, "parseErrorOffset", oci8_error_parse_error_offset, 0); -#endif -#ifdef OCI_ATTR_STATEMENT - rb_define_method(eOCIError, "sql", oci8_error_sql, 0); -#endif + rb_define_method(eOCIException, "initialize", oci8_error_initialize, -1); + rb_define_attr(eOCIException, "code", 1, 0); + rb_define_attr(eOCIException, "sql", 1, 0); + rb_define_attr(eOCIException, "parse_error_offset", 1, 0); + rb_define_alias(eOCIException, "parseErrorOffset", "parse_error_offset"); } void oci8_do_raise(OCIError *errhp, sword status, OCIStmt *stmthp, const char *file, int line) { - oci8_raise2(errhp, status, OCI_HTYPE_ERROR, stmthp, file, line); + rb_exc_raise(oci8_make_exc(errhp, status, OCI_HTYPE_ERROR, stmthp, file, line)); } void oci8_do_env_raise(OCIEnv *envhp, sword status, const char *file, int line) { - oci8_raise2(envhp, status, OCI_HTYPE_ENV, NULL, file, line); + rb_exc_raise(oci8_make_exc(envhp, status, OCI_HTYPE_ENV, NULL, file, line)); } void oci8_do_raise_init_error(const char *file, int line) { VALUE msg = rb_usascii_str_new_cstr("OCI Library Initialization Error"); - VALUE exc = rb_funcall(eOCIError, oci8_id_new, 1, msg); + VALUE exc = rb_funcall(eOCIError, oci8_id_new, 2, msg, INT2FIX(-1)); - rb_ivar_set(exc, oci8_id_code, rb_ary_new3(1, INT2FIX(-1))); - rb_ivar_set(exc, oci8_id_message, rb_ary_new3(1, msg)); - set_backtrace_and_raise(exc, file, line); + rb_exc_raise(set_backtrace(exc, file, line)); } VALUE oci8_get_error_message(ub4 msgno, const char *default_msg) @@ -388,9 +263,83 @@ void oci8_do_raise_by_msgno(ub4 msgno, const char *default_msg, const char *file, int line) { VALUE msg = oci8_get_error_message(msgno, default_msg); - VALUE exc = rb_funcall(eOCIError, oci8_id_new, 1, msg); + VALUE exc = rb_funcall(eOCIError, oci8_id_new, 2, msg, INT2FIX(-1)); - rb_ivar_set(exc, oci8_id_code, rb_ary_new3(1, INT2FIX(-1))); - rb_ivar_set(exc, oci8_id_message, rb_ary_new3(1, msg)); - set_backtrace_and_raise(exc, file, line); + rb_exc_raise(set_backtrace(exc, file, line)); } + +/* + * Document-class: OCIException + * + * The superclass for all exceptions raised by ruby-oci8. + * + * The following exceptions are defined as subclasses of OCIError. + * These exceptions are raised when Oracle Call Interface functions + * return with an error status. + * + * - OCIBreak + * - OCINoData + * - OCIError + * - OCIInvalidHandle + * - OCINeedData + * - OCIStillExecuting + * - OCIContinue + * - OCISuccessWithInfo + */ + +/* + * Document-class: OCIBreak + * + * Subclass of OCIException + * + * + */ + +/* + * Document-class: OCINoData + * + * Subclass of OCIException + * + */ + +/* + * Document-class: OCIError + * + * Subclass of OCIException + * + */ + +/* + * Document-class: OCIInvalidHandle + * + * Subclass of OCIException + * + */ + +/* + * Document-class: OCINeedData + * + * Subclass of OCIException + * + */ + +/* + * Document-class: OCIStillExecuting + * + * Subclass of OCIException + * + */ + +/* + * Document-class: OCIContinue + * + * Subclass of OCIException + * + */ + +/* + * Document-class: OCISuccessWithInfo + * + * Subclass of OCIException + * + */ Modified: trunk/ruby-oci8/ext/oci8/oci8.h =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8.h 2011-10-21 14:10:10 UTC (rev 455) +++ trunk/ruby-oci8/ext/oci8/oci8.h 2011-10-21 14:23:18 UTC (rev 456) @@ -453,6 +453,7 @@ /* error.c */ extern VALUE eOCIException; extern VALUE eOCIBreak; +VALUE oci8_make_exc(dvoid *errhp, sword status, ub4 type, OCIStmt *stmthp, const char *file, int line); void Init_oci8_error(void); NORETURN(void oci8_do_raise(OCIError *, sword status, OCIStmt *, const char *file, int line)); NORETURN(void oci8_do_env_raise(OCIEnv *, sword status, const char *file, int line)); Modified: trunk/ruby-oci8/test/test_all.rb =================================================================== --- trunk/ruby-oci8/test/test_all.rb 2011-10-21 14:10:10 UTC (rev 455) +++ trunk/ruby-oci8/test/test_all.rb 2011-10-21 14:23:18 UTC (rev 456) @@ -21,6 +21,7 @@ require "#{srcdir}/test_rowid" require "#{srcdir}/test_appinfo" require "#{srcdir}/test_oracle_version" +require "#{srcdir}/test_error" if OCI8.respond_to? :encoding require "#{srcdir}/test_encoding" Added: trunk/ruby-oci8/test/test_error.rb =================================================================== --- trunk/ruby-oci8/test/test_error.rb (rev 0) +++ trunk/ruby-oci8/test/test_error.rb 2011-10-21 14:23:18 UTC (rev 456) @@ -0,0 +1,28 @@ +require 'oci8' +require 'test/unit' +require File.dirname(__FILE__) + '/config' + +class TestError < Test::Unit::TestCase + def setup + @conn = get_oci8_connection + end + + def teardown + @conn.logoff + end + + attr_reader :code, :sql, :parse_error_offset + + def test_error + begin + @conn.exec('select * from') # raises "ORA-00903: invalid table name" + rescue OCIException + assert_instance_of(OCIError, $!) + assert_match(/^ORA-00903: /, $!.to_s) + assert_equal(903, $!.code) + assert_equal(13, $!.parse_error_offset) + assert_equal(13, $!.parseErrorOffset) # barkward compatibility + assert_equal('select * from', $!.sql) + end + end +end From nobody at rubyforge.org Sat Oct 22 01:11:52 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 22 Oct 2011 01:11:52 -0400 (EDT) Subject: [ruby-oci8-commit] [457] trunk/ruby-oci8: delete code for Oracle 8 and Oracle 8i. Message-ID: <20111022051152.784F115B802B@rubyforge.org> Revision: 457 Author: kubo Date: 2011-10-22 01:11:51 -0400 (Sat, 22 Oct 2011) Log Message: ----------- delete code for Oracle 8 and Oracle 8i. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/lob.c trunk/ruby-oci8/ext/oci8/oci8.c trunk/ruby-oci8/ext/oci8/ocinumber.c Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-10-21 14:23:18 UTC (rev 456) +++ trunk/ruby-oci8/ChangeLog 2011-10-22 05:11:51 UTC (rev 457) @@ -1,3 +1,7 @@ +2011-10-22 KUBO Takehiro + * ext/oci8/lob.c, ext/oci8/oci8.c, ext/oci8/ocinumber.c: + delete code for Oracle 8 and Oracle 8i. + 2011-10-21 KUBO Takehiro * ext/oci8/error.c, ext/oci8/oci8.h: refactor OCIException and its subclasses. OCIError#codes and OCIError#messages are deleted. Modified: trunk/ruby-oci8/ext/oci8/lob.c =================================================================== --- trunk/ruby-oci8/ext/oci8/lob.c 2011-10-21 14:23:18 UTC (rev 456) +++ trunk/ruby-oci8/ext/oci8/lob.c 2011-10-22 05:11:51 UTC (rev 457) @@ -102,7 +102,7 @@ oci8_lob_t *lob = (oci8_lob_t *)base; boolean is_temporary; - if (have_OCILobIsTemporary && lob->svchp != NULL + if (lob->svchp != NULL && OCILobIsTemporary(oci8_envhp, oci8_errhp, lob->base.hp.lob, &is_temporary) == OCI_SUCCESS && is_temporary) { @@ -131,11 +131,9 @@ static void lob_open(oci8_lob_t *lob) { if (lob->state == S_CLOSE) { - if (have_OCILobOpen_nb) { - oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); + oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); - oci_lc(OCILobOpen_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, OCI_DEFAULT)); - } + oci_lc(OCILobOpen_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, OCI_DEFAULT)); lob->state = S_OPEN; } } @@ -143,11 +141,9 @@ static void lob_close(oci8_lob_t *lob) { if (lob->state == S_OPEN) { - if (have_OCILobClose_nb) { - oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); + oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); - oci_lc(OCILobClose_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob)); - } + oci_lc(OCILobClose_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob)); lob->state = S_CLOSE; } } @@ -192,15 +188,11 @@ lob->state = S_NO_OPEN_CLOSE; oci8_link_to_parent((oci8_base_t*)lob, (oci8_base_t*)DATA_PTR(svc)); if (!NIL_P(val)) { - if (have_OCILobCreateTemporary_nb) { - oci8_svcctx_t *svcctx = oci8_get_svcctx(svc); - OCI8StringValue(val); - oci_lc(OCILobCreateTemporary_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, 0, csfrm, lobtype, TRUE, OCI_DURATION_SESSION)); - lob->svchp = oci8_get_oci_svcctx(svc); - oci8_lob_write(self, val); - } else { - rb_raise(rb_eRuntimeError, "creating a temporary lob is not supported on this Oracle version"); - } + oci8_svcctx_t *svcctx = oci8_get_svcctx(svc); + OCI8StringValue(val); + oci_lc(OCILobCreateTemporary_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, 0, csfrm, lobtype, TRUE, OCI_DURATION_SESSION)); + lob->svchp = oci8_get_oci_svcctx(svc); + oci8_lob_write(self, val); } return Qnil; } @@ -459,16 +451,12 @@ static VALUE oci8_lob_get_chunk_size(VALUE self) { - if (have_OCILobGetChunkSize_nb) { - oci8_lob_t *lob = DATA_PTR(self); - oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); - ub4 len; + oci8_lob_t *lob = DATA_PTR(self); + oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); + ub4 len; - oci_lc(OCILobGetChunkSize_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &len)); - return UINT2NUM(len); - } else { - rb_notimplement(); - } + oci_lc(OCILobGetChunkSize_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &len)); + return UINT2NUM(len); } static VALUE oci8_lob_clone(VALUE self) @@ -481,9 +469,8 @@ newobj = rb_funcall(CLASS_OF(self), oci8_id_new, 1, lob->svc); newlob = DATA_PTR(newobj); - if (have_OCILobLocatorAssign_nb && have_OCILobIsTemporary - && OCILobIsTemporary(oci8_envhp, oci8_errhp, lob->base.hp.lob, &is_temporary) == OCI_SUCCESS - && is_temporary) { + if (OCILobIsTemporary(oci8_envhp, oci8_errhp, lob->base.hp.lob, &is_temporary) == OCI_SUCCESS + && is_temporary) { oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); rv = OCILobLocatorAssign_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &newlob->base.hp.lob); } else { Modified: trunk/ruby-oci8/ext/oci8/oci8.c =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8.c 2011-10-21 14:23:18 UTC (rev 456) +++ trunk/ruby-oci8/ext/oci8/oci8.c 2011-10-22 05:11:51 UTC (rev 457) @@ -779,24 +779,8 @@ ub4 version; char *p; - if (have_OCIServerRelease) { - /* Oracle 9i or later */ - oci_lc(OCIServerRelease(svcctx->base.hp.ptr, oci8_errhp, (text*)buf, sizeof(buf), (ub1)svcctx->base.type, &version)); - return UINT2NUM(version); - } else { - /* Oracle 8.x */ - oci_lc(OCIServerVersion(svcctx->base.hp.ptr, oci8_errhp, (text*)buf, sizeof(buf), (ub1)svcctx->base.type)); - if ((p = strchr(buf, '.')) != NULL) { - unsigned int major, minor, update, patch, port_update; - while (p >= buf && *p != ' ') { - p--; - } - if (sscanf(p + 1, "%u.%u.%u.%u.%u", &major, &minor, &update, &patch, &port_update) == 5) { - return INT2FIX(ORAVERNUM(major, minor, update, patch, port_update)); - } - } - return Qnil; - } + oci_lc(OCIServerRelease(svcctx->base.hp.ptr, oci8_errhp, (text*)buf, sizeof(buf), (ub1)svcctx->base.type, &version)); + return UINT2NUM(version); } /* @@ -1127,9 +1111,7 @@ rb_define_const(cOCI8, "VERSION", rb_obj_freeze(rb_usascii_str_new_cstr(OCI8LIB_VERSION))); rb_define_singleton_method_nodoc(cOCI8, "oracle_client_vernum", oci8_s_oracle_client_vernum, 0); rb_define_singleton_method_nodoc(cOCI8, "__set_property", oci8_s_set_property, 2); - if (have_OCIMessageOpen && have_OCIMessageGet) { - rb_define_singleton_method(cOCI8, "error_message", oci8_s_error_message, 1); - } + rb_define_singleton_method(cOCI8, "error_message", oci8_s_error_message, 1); rb_define_private_method(cOCI8, "parse_connect_string", oci8_parse_connect_string, 1); rb_define_private_method(cOCI8, "logon", oci8_logon, 3); rb_define_private_method(cOCI8, "allocate_handles", oci8_allocate_handles, 0); Modified: trunk/ruby-oci8/ext/oci8/ocinumber.c =================================================================== --- trunk/ruby-oci8/ext/oci8/ocinumber.c 2011-10-21 14:23:18 UTC (rev 456) +++ trunk/ruby-oci8/ext/oci8/ocinumber.c 2011-10-22 05:11:51 UTC (rev 457) @@ -257,19 +257,7 @@ } exponent = FIX2INT(ary[3]); - if (have_OCINumberShift) { - /* Oracle 8.1 or upper */ - oci_lc(OCINumberShift(errhp, &digits, exponent - digits_len, &work)); - } else { - /* Oracle 8.0 */ - int n = 10; - OCINumber base; - OCINumber exp; - - oci_lc(OCINumberFromInt(errhp, &n, sizeof(n), OCI_NUMBER_SIGNED, &base)); - oci_lc(OCINumberIntPower(errhp, &base, exponent - digits_len, &exp)); - oci_lc(OCINumberMul(errhp, &digits, &exp, &work)); - } + oci_lc(OCINumberShift(errhp, &digits, exponent - digits_len, &work)); if (sign >= 0) { oci_lc(OCINumberAssign(errhp, &work, result)); } else { @@ -1586,9 +1574,7 @@ rb_define_method(cOCINumber, "ceil", onum_ceil, 0); rb_define_method(cOCINumber, "round", onum_round, -1); rb_define_method(cOCINumber, "truncate", onum_trunc, -1); - if (have_OCINumberPrec) { - rb_define_method(cOCINumber, "round_prec", onum_round_prec, 1); - } + rb_define_method(cOCINumber, "round_prec", onum_round_prec, 1); rb_define_method(cOCINumber, "to_s", onum_to_s, 0); rb_define_method(cOCINumber, "to_char", onum_to_char, -1); @@ -1601,9 +1587,7 @@ rb_define_method(cOCINumber, "zero?", onum_zero_p, 0); rb_define_method(cOCINumber, "abs", onum_abs, 0); - if (have_OCINumberShift) { - rb_define_method(cOCINumber, "shift", onum_shift, 1); - } + rb_define_method(cOCINumber, "shift", onum_shift, 1); rb_define_method(cOCINumber, "dump", onum_dump, 0); rb_define_method_nodoc(cOCINumber, "hash", onum_hash, 0); From nobody at rubyforge.org Sat Oct 22 07:21:46 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 22 Oct 2011 07:21:46 -0400 (EDT) Subject: [ruby-oci8-commit] [458] trunk/ruby-oci8: change the super class of OCINoData from OCIException to OCIError and fix testcases for OCIError and its subclasses . Message-ID: <20111022112146.680BB15B802B@rubyforge.org> Revision: 458 Author: kubo Date: 2011-10-22 07:21:44 -0400 (Sat, 22 Oct 2011) Log Message: ----------- change the super class of OCINoData from OCIException to OCIError and fix testcases for OCIError and its subclasses. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/error.c trunk/ruby-oci8/test/test_break.rb trunk/ruby-oci8/test/test_error.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-10-22 05:11:51 UTC (rev 457) +++ trunk/ruby-oci8/ChangeLog 2011-10-22 11:21:44 UTC (rev 458) @@ -1,4 +1,9 @@ 2011-10-22 KUBO Takehiro + * ext/oci8/error.c, test/test_break.rb, test/test_error.rb: change the super + class of OCINoData from OCIException to OCIError and fix testcases for + OCIError and its subclasses. + +2011-10-22 KUBO Takehiro * ext/oci8/lob.c, ext/oci8/oci8.c, ext/oci8/ocinumber.c: delete code for Oracle 8 and Oracle 8i. Modified: trunk/ruby-oci8/ext/oci8/error.c =================================================================== --- trunk/ruby-oci8/ext/oci8/error.c 2011-10-22 05:11:51 UTC (rev 457) +++ trunk/ruby-oci8/ext/oci8/error.c 2011-10-22 11:21:44 UTC (rev 458) @@ -84,35 +84,23 @@ VALUE parse_error_offset = Qnil; VALUE sql = Qnil; int rv; + int numarg = 1; switch (status) { case OCI_ERROR: + exc = eOCIError; + msg = get_error_msg(errhp, type, "Error", &errcode); + numarg = 4; + break; case OCI_SUCCESS_WITH_INFO: - /* get error string */ + exc = eOCISuccessWithInfo; msg = get_error_msg(errhp, type, "Error", &errcode); - if (status == OCI_ERROR) { - exc = eOCIError; - } else { - exc = eOCISuccessWithInfo; - } - if (stmthp != NULL) { - ub2 offset; - text *text; - ub4 size; - - rv = OCIAttrGet(stmthp, OCI_HTYPE_STMT, &offset, 0, OCI_ATTR_PARSE_ERROR_OFFSET, errhp); - if (rv == OCI_SUCCESS) { - parse_error_offset = INT2FIX(offset); - } - rv = OCIAttrGet(stmthp, OCI_HTYPE_STMT, &text, &size, OCI_ATTR_STATEMENT, errhp); - if (rv == OCI_SUCCESS) { - sql = rb_external_str_new_with_enc(TO_CHARPTR(text), size, oci8_encoding); - } - } + numarg = 4; break; case OCI_NO_DATA: exc = eOCINoData; msg = get_error_msg(errhp, type, "No Data", &errcode); + numarg = 4; break; case OCI_INVALID_HANDLE: exc = eOCIInvalidHandle; @@ -135,7 +123,21 @@ exc = eOCIException; msg = rb_usascii_str_new_cstr(errmsg); } - exc = rb_funcall(exc, oci8_id_new, 4, msg, INT2FIX(errcode), sql, parse_error_offset); + if (stmthp != NULL) { + ub2 offset; + text *text; + ub4 size; + + rv = OCIAttrGet(stmthp, OCI_HTYPE_STMT, &offset, 0, OCI_ATTR_PARSE_ERROR_OFFSET, errhp); + if (rv == OCI_SUCCESS) { + parse_error_offset = INT2FIX(offset); + } + rv = OCIAttrGet(stmthp, OCI_HTYPE_STMT, &text, &size, OCI_ATTR_STATEMENT, errhp); + if (rv == OCI_SUCCESS) { + sql = rb_external_str_new_with_enc(TO_CHARPTR(text), size, oci8_encoding); + } + } + exc = rb_funcall(exc, oci8_id_new, numarg, msg, INT2FIX(errcode), sql, parse_error_offset); return set_backtrace(exc, file, line); } @@ -162,7 +164,7 @@ * call-seq: * OCI8.new(message, code = nil, sql = nil, parse_error_offset = nil) * - * Creates a new OCIException object. + * Creates a new OCIError object. */ static VALUE oci8_error_initialize(int argc, VALUE *argv, VALUE self) { @@ -200,19 +202,19 @@ eOCIException = rb_define_class("OCIException", rb_eStandardError); eOCIBreak = rb_define_class("OCIBreak", eOCIException); - eOCINoData = rb_define_class("OCINoData", eOCIException); eOCIError = rb_define_class("OCIError", eOCIException); + eOCINoData = rb_define_class("OCINoData", eOCIError); eOCIInvalidHandle = rb_define_class("OCIInvalidHandle", eOCIException); eOCINeedData = rb_define_class("OCINeedData", eOCIException); eOCIStillExecuting = rb_define_class("OCIStillExecuting", eOCIException); eOCIContinue = rb_define_class("OCIContinue", eOCIException); eOCISuccessWithInfo = rb_define_class("OCISuccessWithInfo", eOCIError); - rb_define_method(eOCIException, "initialize", oci8_error_initialize, -1); - rb_define_attr(eOCIException, "code", 1, 0); - rb_define_attr(eOCIException, "sql", 1, 0); - rb_define_attr(eOCIException, "parse_error_offset", 1, 0); - rb_define_alias(eOCIException, "parseErrorOffset", "parse_error_offset"); + rb_define_method(eOCIError, "initialize", oci8_error_initialize, -1); + rb_define_attr(eOCIError, "code", 1, 0); + rb_define_attr(eOCIError, "sql", 1, 0); + rb_define_attr(eOCIError, "parse_error_offset", 1, 0); + rb_define_alias(eOCIError, "parseErrorOffset", "parse_error_offset"); } void oci8_do_raise(OCIError *errhp, sword status, OCIStmt *stmthp, const char *file, int line) @@ -273,18 +275,18 @@ * * The superclass for all exceptions raised by ruby-oci8. * - * The following exceptions are defined as subclasses of OCIError. + * The following exceptions are defined as subclasses of OCIException * These exceptions are raised when Oracle Call Interface functions * return with an error status. * * - OCIBreak - * - OCINoData + * - OCIContinue * - OCIError + * - OCISuccessWithInfo + * - OCINoData (It had been a subclass of OCIException, not OCIError, until ruby-oci8 2.0) * - OCIInvalidHandle * - OCINeedData * - OCIStillExecuting - * - OCIContinue - * - OCISuccessWithInfo */ /* @@ -292,14 +294,16 @@ * * Subclass of OCIException * - * + * Raised when a SQL execution is cancelled by OCI8#break. */ /* * Document-class: OCINoData * - * Subclass of OCIException + * Subclass of OCIError from ruby-oci8 2.1. + * It had been a subclass of OCIException until ruby-oci8 2.0. * + * Raised when PL/SQL NO_DATA_FOUND exception is got. */ /* @@ -307,6 +311,13 @@ * * Subclass of OCIException * + * The following exceptions are defined as subclasses of OCIError. + * + * - OCISuccessWithInfo + * - OCINoData (It had been a subclass of OCIException, not OCIError, until ruby-oci8 2.0) + * + * Raised when underlying Oracle Call Interface failed with an Oracle error code + * such as ORA-00001. */ /* @@ -314,6 +325,8 @@ * * Subclass of OCIException * + * Raised when an invalid handle is passed to underlying Oracle Call Interface. + * Report to the ruby-oci8 author if it is raised. */ /* @@ -321,13 +334,15 @@ * * Subclass of OCIException * + * Report to the ruby-oci8 author if it is raised. */ /* * Document-class: OCIStillExecuting * - * Subclass of OCIException + * Subclass of OCIError * + * Report to the ruby-oci8 author if it is raised. */ /* @@ -335,11 +350,12 @@ * * Subclass of OCIException * + * Report to the ruby-oci8 author if it is raised. */ /* * Document-class: OCISuccessWithInfo * - * Subclass of OCIException + * Subclass of OCIError * */ Modified: trunk/ruby-oci8/test/test_break.rb =================================================================== --- trunk/ruby-oci8/test/test_break.rb 2011-10-22 05:11:51 UTC (rev 457) +++ trunk/ruby-oci8/test/test_break.rb 2011-10-22 11:21:44 UTC (rev 458) @@ -34,6 +34,7 @@ assert_equal(expect[PLSQL_DONE], (Time.now - $start_time).round, 'PLSQL_DONE') rescue OCIBreak assert_equal(expect[OCIBREAK], (Time.now - $start_time).round, 'OCIBREAK') + assert_equal('Canceled by user request.', $!.to_s) end end Modified: trunk/ruby-oci8/test/test_error.rb =================================================================== --- trunk/ruby-oci8/test/test_error.rb 2011-10-22 05:11:51 UTC (rev 457) +++ trunk/ruby-oci8/test/test_error.rb 2011-10-22 11:21:44 UTC (rev 458) @@ -11,18 +11,78 @@ @conn.logoff end - attr_reader :code, :sql, :parse_error_offset - - def test_error + def test_sql_parse_error + sql = 'select * from' begin - @conn.exec('select * from') # raises "ORA-00903: invalid table name" + @conn.exec(sql) # raises "ORA-00903: invalid table name" rescue OCIException assert_instance_of(OCIError, $!) assert_match(/^ORA-00903: /, $!.to_s) assert_equal(903, $!.code) assert_equal(13, $!.parse_error_offset) assert_equal(13, $!.parseErrorOffset) # barkward compatibility - assert_equal('select * from', $!.sql) + assert_equal(sql, $!.sql) end end + + def test_plsql_parse_error + sql = < Revision: 459 Author: kubo Date: 2011-10-22 09:32:49 -0400 (Sat, 22 Oct 2011) Log Message: ----------- add OCI8#last_error and OCI8#last_error=. When an exception is raised associated with a connection, the exception is set to OCI8#last_error. No OCISuccessWithInfo excpetion is raised from now on. It is set to OCI8#last_error instead. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/attr.c trunk/ruby-oci8/ext/oci8/bind.c trunk/ruby-oci8/ext/oci8/connection_pool.c trunk/ruby-oci8/ext/oci8/error.c trunk/ruby-oci8/ext/oci8/lob.c trunk/ruby-oci8/ext/oci8/metadata.c trunk/ruby-oci8/ext/oci8/object.c trunk/ruby-oci8/ext/oci8/oci8.c trunk/ruby-oci8/ext/oci8/oci8.h trunk/ruby-oci8/ext/oci8/oci8lib.c trunk/ruby-oci8/ext/oci8/ocidatetime.c trunk/ruby-oci8/ext/oci8/ocihandle.c trunk/ruby-oci8/ext/oci8/ocinumber.c trunk/ruby-oci8/ext/oci8/stmt.c Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ChangeLog 2011-10-22 13:32:49 UTC (rev 459) @@ -1,4 +1,15 @@ 2011-10-22 KUBO Takehiro + * ext/oci8/attr.c, ext/oci8/bind.c, ext/oci8/connection_pool.c, + ext/oci8/error.c, ext/oci8/lob.c, ext/oci8/metadata.c, + ext/oci8/object.c, ext/oci8/oci8.c, ext/oci8/oci8.h, + ext/oci8/oci8lib.c, ext/oci8/ocidatetime.c, ext/oci8/ocihandle.c, + ext/oci8/ocinumber.c, ext/oci8/stmt.c: add OCI8#last_error and + OCI8#last_error=. When an exception is raised associated with a + connection, the exception is set to OCI8#last_error. + No OCISuccessWithInfo excpetion is raised from now on. It is + set to OCI8#last_error instead. + +2011-10-22 KUBO Takehiro * ext/oci8/error.c, test/test_break.rb, test/test_error.rb: change the super class of OCINoData from OCIException to OCIError and fix testcases for OCIError and its subclasses. Modified: trunk/ruby-oci8/ext/oci8/attr.c =================================================================== --- trunk/ruby-oci8/ext/oci8/attr.c 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/attr.c 2011-10-22 13:32:49 UTC (rev 459) @@ -6,47 +6,39 @@ */ #include "oci8.h" -VALUE oci8_get_sb1_attr(oci8_base_t *base, ub4 attrtype) +VALUE oci8_get_sb1_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp) { sb1 val; - sword rv; - rv = OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp); - if (rv != OCI_SUCCESS) - oci8_raise(oci8_errhp, rv, NULL); + chker3(OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp), + base, stmtp); return INT2FIX(val); } -VALUE oci8_get_ub2_attr(oci8_base_t *base, ub4 attrtype) +VALUE oci8_get_ub2_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp) { ub2 val; - sword rv; - rv = OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp); - if (rv != OCI_SUCCESS) - oci8_raise(oci8_errhp, rv, NULL); + chker3(OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp), + base, stmtp); return INT2FIX(val); } -VALUE oci8_get_sb2_attr(oci8_base_t *base, ub4 attrtype) +VALUE oci8_get_sb2_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp) { sb2 val; - sword rv; - rv = OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp); - if (rv != OCI_SUCCESS) - oci8_raise(oci8_errhp, rv, NULL); + chker3(OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp), + base, stmtp); return INT2FIX(val); } -VALUE oci8_get_ub4_attr(oci8_base_t *base, ub4 attrtype) +VALUE oci8_get_ub4_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp) { ub4 val; - sword rv; - rv = OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp); - if (rv != OCI_SUCCESS) - oci8_raise(oci8_errhp, rv, NULL); + chker3(OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp), + base, stmtp); #if SIZEOF_LONG > 4 return LONG2FIX(val); #else @@ -54,15 +46,13 @@ #endif } -VALUE oci8_get_string_attr(oci8_base_t *base, ub4 attrtype) +VALUE oci8_get_string_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp) { text *val; ub4 size; - sword rv; - rv = OCIAttrGet(base->hp.ptr, base->type, &val, &size, attrtype, oci8_errhp); - if (rv != OCI_SUCCESS) - oci8_raise(oci8_errhp, rv, NULL); + chker3(OCIAttrGet(base->hp.ptr, base->type, &val, &size, attrtype, oci8_errhp), + base, stmtp); return rb_external_str_new_with_enc(TO_CHARPTR(val), size, oci8_encoding); } @@ -70,6 +60,7 @@ typedef struct { oci8_base_t *base; + OCIStmt *stmtp; ub4 attrtype; OCIRowid *ridp; } rowid_arg_t; @@ -86,52 +77,12 @@ rv = OCIDescriptorAlloc(oci8_envhp, (dvoid*)&arg->ridp, OCI_DTYPE_ROWID, 0, NULL); if (rv != OCI_SUCCESS) oci8_env_raise(oci8_envhp, rv); - rv = OCIAttrGet(base->hp.ptr, base->type, arg->ridp, 0, attrtype, oci8_errhp); - if (rv != OCI_SUCCESS) { - oci8_raise(oci8_errhp, rv, NULL); - } + chker3(OCIAttrGet(base->hp.ptr, base->type, arg->ridp, 0, attrtype, oci8_errhp), + base, arg->stmtp); /* convert the rowid descriptor to a string. */ - if (have_OCIRowidToChar) { - /* If OCIRowidToChar is available, use it. */ - buflen = MAX_ROWID_LEN; - rv = OCIRowidToChar(arg->ridp, TO_ORATEXT(buf), &buflen, oci8_errhp); - if (rv != OCI_SUCCESS) { - oci8_raise(oci8_errhp, rv, NULL); - } - } else { - /* If OCIRowidToChar is not available, convert it on - * Oracle Server. - */ - oci8_base_t *svc; - oci8_exec_sql_var_t define_var; - oci8_exec_sql_var_t bind_var; - - /* search a connection from the handle */ - svc = base; - while (svc->type != OCI_HTYPE_SVCCTX) { - svc = svc->parent; - if (svc == NULL) { - rb_raise(rb_eRuntimeError, "No connection is found!!"); - } - } - /* :strval */ - define_var.valuep = buf; - define_var.value_sz = sizeof(buf); - define_var.dty = SQLT_CHR; - define_var.indp = NULL; - define_var.alenp = &buflen; - /* :rowid */ - bind_var.valuep = &arg->ridp; - bind_var.value_sz = sizeof(void *); - bind_var.dty = SQLT_RDD; - bind_var.indp = NULL; - bind_var.alenp = NULL; - /* convert the rowid descriptor to a string value by querying Oracle server. */ - oci8_exec_sql((oci8_svcctx_t*)svc, "SELECT :rid FROM dual", 1, &define_var, 1, &bind_var, 1); - if (buflen == 0) { - return Qnil; - } - } + buflen = MAX_ROWID_LEN; + chker3(OCIRowidToChar(arg->ridp, TO_ORATEXT(buf), &buflen, oci8_errhp), + base, arg->stmtp); return rb_external_str_new_with_enc(buf, buflen, rb_usascii_encoding()); } @@ -143,10 +94,11 @@ return Qnil; } -VALUE oci8_get_rowid_attr(oci8_base_t *base, ub4 attrtype) +VALUE oci8_get_rowid_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp) { rowid_arg_t arg; arg.base = base; + arg.stmtp = stmtp; arg.attrtype = attrtype; arg.ridp = NULL; return rb_ensure(get_rowid_attr, (VALUE)&arg, rowid_ensure, (VALUE)&arg); Modified: trunk/ruby-oci8/ext/oci8/bind.c =================================================================== --- trunk/ruby-oci8/ext/oci8/bind.c 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/bind.c 2011-10-22 13:32:49 UTC (rev 459) @@ -97,9 +97,11 @@ oci8_bind_string_t *obs = (oci8_bind_string_t *)obind; if (obs->charlen != 0) { - oci_lc(OCIAttrSet(obind->base.hp.ptr, obind->base.type, (void*)&obs->charlen, 0, OCI_ATTR_MAXCHAR_SIZE, oci8_errhp)); + chker2(OCIAttrSet(obind->base.hp.ptr, obind->base.type, (void*)&obs->charlen, 0, OCI_ATTR_MAXCHAR_SIZE, oci8_errhp), + &obind->base); } - oci_lc(OCIAttrSet(obind->base.hp.ptr, obind->base.type, (void*)&obs->csfrm, 0, OCI_ATTR_CHARSET_FORM, oci8_errhp)); + chker2(OCIAttrSet(obind->base.hp.ptr, obind->base.type, (void*)&obs->csfrm, 0, OCI_ATTR_CHARSET_FORM, oci8_errhp), + &obind->base); } static const oci8_bind_vtable_t bind_string_vtable = { Modified: trunk/ruby-oci8/ext/oci8/connection_pool.c =================================================================== --- trunk/ruby-oci8/ext/oci8/connection_pool.c 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/connection_pool.c 2011-10-22 13:32:49 UTC (rev 459) @@ -124,7 +124,7 @@ oci8_env_raise(oci8_envhp, rv); cpool->base.type = OCI_HTYPE_CPOOL; - oci_lc(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp, + chker2(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp, &pool_name, &pool_name_len, NIL_P(dbname) ? NULL : RSTRING_ORATEXT(dbname), NIL_P(dbname) ? 0 : RSTRING_LEN(dbname), @@ -134,7 +134,8 @@ NIL_P(username) ? 0 : RSTRING_LEN(username), NIL_P(password) ? NULL : RSTRING_ORATEXT(password), NIL_P(password) ? 0 : RSTRING_LEN(password), - OCI_DEFAULT)); + OCI_DEFAULT), + &cpool->base); cpool->pool_name = rb_str_new(TO_CHARPTR(pool_name), pool_name_len); rb_str_freeze(cpool->pool_name); return Qnil; @@ -158,11 +159,12 @@ Check_Type(conn_max, T_FIXNUM); Check_Type(conn_incr, T_FIXNUM); - oci_lc(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp, + chker2(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp, &pool_name, &pool_name_len, NULL, 0, FIX2UINT(conn_min), FIX2UINT(conn_max), FIX2UINT(conn_incr), - NULL, 0, NULL, 0, OCI_CPOOL_REINITIALIZE)); + NULL, 0, NULL, 0, OCI_CPOOL_REINITIALIZE), + &cpool->base); return self; } Modified: trunk/ruby-oci8/ext/oci8/error.c =================================================================== --- trunk/ruby-oci8/ext/oci8/error.c 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/error.c 2011-10-22 13:32:49 UTC (rev 459) @@ -75,7 +75,7 @@ return rb_external_str_new_with_enc(errbuf, len, oci8_encoding); } -VALUE oci8_make_exc(dvoid *errhp, sword status, ub4 type, OCIStmt *stmthp, const char *file, int line) +static VALUE oci8_make_exc(dvoid *errhp, sword status, ub4 type, OCIStmt *stmthp, const char *file, int line) { VALUE exc; char errmsg[128]; @@ -244,7 +244,7 @@ if (have_OCIMessageGet) { if (msghp == NULL) { - oci_lc(OCIMessageOpen(oci8_envhp, oci8_errhp, &msghp, TO_ORATEXT("rdbms"), TO_ORATEXT("ora"), OCI_DURATION_PROCESS)); + chkerr(OCIMessageOpen(oci8_envhp, oci8_errhp, &msghp, TO_ORATEXT("rdbms"), TO_ORATEXT("ora"), OCI_DURATION_PROCESS)); } errmsg = TO_CHARPTR(OCIMessageGet(msghp, msgno, NULL, 0)); } @@ -270,6 +270,23 @@ rb_exc_raise(set_backtrace(exc, file, line)); } +void oci8_check_error_(sword status, oci8_base_t *base, OCIStmt *stmthp, const char *file, int line) +{ + if (status != OCI_SUCCESS) { + VALUE exc = oci8_make_exc(oci8_errhp, status, OCI_HTYPE_ERROR, stmthp, file, line); + while (base != NULL) { + if (base->type == OCI_HTYPE_SVCCTX) { + rb_ivar_set(exc, oci8_id_at_last_error, exc); + break; + } + base = base->parent; + } + if (status != OCI_SUCCESS_WITH_INFO) { + rb_exc_raise(exc); + } + } +} + /* * Document-class: OCIException * Modified: trunk/ruby-oci8/ext/oci8/lob.c =================================================================== --- trunk/ruby-oci8/ext/oci8/lob.c 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/lob.c 2011-10-22 13:32:49 UTC (rev 459) @@ -41,7 +41,8 @@ lob_obj = rb_funcall(klass, oci8_id_new, 1, svcctx->base.self); lob = DATA_PTR(lob_obj); /* If 's' is a temporary lob, use OCILobLocatorAssign instead. */ - oci_lc(OCILobAssign(oci8_envhp, oci8_errhp, s, &lob->base.hp.lob)); + chker2(OCILobAssign(oci8_envhp, oci8_errhp, s, &lob->base.hp.lob), + &svcctx->base); return lob_obj; } @@ -68,7 +69,7 @@ static void oci8_assign_lob(VALUE klass, oci8_svcctx_t *svcctx, VALUE lob, OCILobLocator **dest) { oci8_base_t *base = oci8_get_handle(lob, klass); - oci_lc(OCILobLocatorAssign_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, base->hp.lob, dest)); + chker2(OCILobLocatorAssign_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, base->hp.lob, dest), base); } void oci8_assign_clob(oci8_svcctx_t *svcctx, VALUE lob, OCILobLocator **dest) @@ -124,7 +125,8 @@ oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); ub4 len; - oci_lc(OCILobGetLength_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &len)); + chker2(OCILobGetLength_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &len), + &svcctx->base); return len; } @@ -133,7 +135,8 @@ if (lob->state == S_CLOSE) { oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); - oci_lc(OCILobOpen_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, OCI_DEFAULT)); + chker2(OCILobOpen_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, OCI_DEFAULT), + &svcctx->base); lob->state = S_OPEN; } } @@ -143,7 +146,8 @@ if (lob->state == S_OPEN) { oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); - oci_lc(OCILobClose_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob)); + chker2(OCILobClose_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob), + &svcctx->base); lob->state = S_CLOSE; } } @@ -153,7 +157,8 @@ if (lob->state == S_BFILE_OPEN) { oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); - oci_lc(OCILobFileClose_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob)); + chker2(OCILobFileClose_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob), + &svcctx->base); lob->state = S_BFILE_CLOSE; } } @@ -190,7 +195,8 @@ if (!NIL_P(val)) { oci8_svcctx_t *svcctx = oci8_get_svcctx(svc); OCI8StringValue(val); - oci_lc(OCILobCreateTemporary_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, 0, csfrm, lobtype, TRUE, OCI_DURATION_SESSION)); + chker2(OCILobCreateTemporary_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, 0, csfrm, lobtype, TRUE, OCI_DURATION_SESSION), + &svcctx->base); lob->svchp = oci8_get_oci_svcctx(svc); oci8_lob_write(self, val); } @@ -233,7 +239,8 @@ oci8_lob_t *lob = DATA_PTR(self); boolean is_initialized; - oci_lc(OCILobLocatorIsInit(oci8_envhp, oci8_errhp, lob->base.hp.lob, &is_initialized)); + chker2(OCILobLocatorIsInit(oci8_envhp, oci8_errhp, lob->base.hp.lob, &is_initialized), + &lob->base); return is_initialized ? Qtrue : Qfalse; } @@ -294,7 +301,8 @@ oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); lob_open(lob); - oci_lc(OCILobTrim_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, NUM2UINT(len))); + chker2(OCILobTrim_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, NUM2UINT(len)), + &svcctx->base); return self; } @@ -346,11 +354,11 @@ } } } - oci_lc(OCILobFileCloseAll_nb(svcctx, svcctx->base.hp.svc, oci8_errhp)); + chker2(OCILobFileCloseAll_nb(svcctx, svcctx->base.hp.svc, oci8_errhp), + &svcctx->base); continue; } - if (rv != OCI_SUCCESS) - oci8_raise(oci8_errhp, rv, NULL); + chker2(rv, &svcctx->base); lob->state = S_BFILE_OPEN; } /* initialize buf in zeros everytime to check a nul characters. */ @@ -361,8 +369,9 @@ if (lob->state == S_BFILE_CLOSE) continue; } - if (rv != OCI_SUCCESS && rv != OCI_NEED_DATA) - oci8_raise(oci8_errhp, rv, NULL); + if (rv != OCI_SUCCESS && rv != OCI_NEED_DATA) { + chker2(rv, &svcctx->base); + } /* Workaround when using Oracle 10.2.0.4 or 11.1.0.6 client and * variable-length character set (e.g. AL32UTF8). @@ -418,7 +427,8 @@ } RB_GC_GUARD(data); amt = RSTRING_LEN(data); - oci_lc(OCILobWrite_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &amt, lob->pos + 1, RSTRING_PTR(data), amt, OCI_ONE_PIECE, NULL, NULL, 0, lob->csfrm)); + chker2(OCILobWrite_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &amt, lob->pos + 1, RSTRING_PTR(data), amt, OCI_ONE_PIECE, NULL, NULL, 0, lob->csfrm), + &svcctx->base); lob->pos += amt; return UINT2NUM(amt); } @@ -455,7 +465,8 @@ oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); ub4 len; - oci_lc(OCILobGetChunkSize_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &len)); + chker2(OCILobGetChunkSize_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &len), + &svcctx->base); return UINT2NUM(len); } @@ -464,7 +475,6 @@ oci8_lob_t *lob = DATA_PTR(self); oci8_lob_t *newlob; VALUE newobj; - sword rv; boolean is_temporary; newobj = rb_funcall(CLASS_OF(self), oci8_id_new, 1, lob->svc); @@ -472,13 +482,11 @@ if (OCILobIsTemporary(oci8_envhp, oci8_errhp, lob->base.hp.lob, &is_temporary) == OCI_SUCCESS && is_temporary) { oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); - rv = OCILobLocatorAssign_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &newlob->base.hp.lob); + chker2(OCILobLocatorAssign_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &newlob->base.hp.lob), + &svcctx->base); } else { - rv = OCILobAssign(oci8_envhp, oci8_errhp, lob->base.hp.lob, &newlob->base.hp.lob); + chker2(OCILobAssign(oci8_envhp, oci8_errhp, lob->base.hp.lob, &newlob->base.hp.lob), &lob->base); } - if (rv != OCI_SUCCESS) { - oci8_raise(oci8_errhp, rv, NULL); - } return newobj; } @@ -504,7 +512,8 @@ VALUE dir_alias; VALUE filename; - oci_lc(OCILobFileGetName(oci8_envhp, oci8_errhp, lob->base.hp.lob, TO_ORATEXT(d_buf), &d_length, TO_ORATEXT(f_buf), &f_length)); + chker2(OCILobFileGetName(oci8_envhp, oci8_errhp, lob->base.hp.lob, TO_ORATEXT(d_buf), &d_length, TO_ORATEXT(f_buf), &f_length), + &lob->base); dir_alias = rb_external_str_new_with_enc(d_buf, d_length, oci8_encoding); filename = rb_external_str_new_with_enc(f_buf, f_length, oci8_encoding); rb_ivar_set(self, id_dir_alias, dir_alias); @@ -529,9 +538,10 @@ if (RSTRING_LEN(filename) > UB2MAXVAL) { rb_raise(rb_eRuntimeError, "filename is too long."); } - oci_lc(OCILobFileSetName(oci8_envhp, oci8_errhp, &lob->base.hp.lob, + chker2(OCILobFileSetName(oci8_envhp, oci8_errhp, &lob->base.hp.lob, RSTRING_ORATEXT(dir_alias), (ub2)RSTRING_LEN(dir_alias), - RSTRING_ORATEXT(filename), (ub2)RSTRING_LEN(filename))); + RSTRING_ORATEXT(filename), (ub2)RSTRING_LEN(filename)), + &lob->base); } static VALUE oci8_bfile_initialize(int argc, VALUE *argv, VALUE self) @@ -540,10 +550,14 @@ VALUE svc; VALUE dir_alias; VALUE filename; + int rv; rb_scan_args(argc, argv, "12", &svc, &dir_alias, &filename); TO_SVCCTX(svc); /* check argument type */ - oci_lc(OCIDescriptorAlloc(oci8_envhp, &lob->base.hp.ptr, OCI_DTYPE_LOB, 0, NULL)); + rv = OCIDescriptorAlloc(oci8_envhp, &lob->base.hp.ptr, OCI_DTYPE_LOB, 0, NULL); + if (rv != OCI_SUCCESS) { + oci8_env_raise(oci8_envhp, rv); + } lob->base.type = OCI_DTYPE_LOB; lob->svc = svc; lob->pos = 0; @@ -604,7 +618,8 @@ oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc); boolean flag; - oci_lc(OCILobFileExists_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &flag)); + chker2(OCILobFileExists_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &flag), + &svcctx->base); return flag ? Qtrue : Qfalse; } @@ -664,7 +679,8 @@ { ub1 csfrm = SQLCS_NCHAR; - oci_lc(OCIAttrSet(obind->base.hp.ptr, obind->base.type, (void*)&csfrm, 0, OCI_ATTR_CHARSET_FORM, oci8_errhp)); + chker2(OCIAttrSet(obind->base.hp.ptr, obind->base.type, (void*)&csfrm, 0, OCI_ATTR_CHARSET_FORM, oci8_errhp), + &obind->base); } static const oci8_bind_lob_vtable_t bind_clob_vtable = { Modified: trunk/ruby-oci8/ext/oci8/metadata.c =================================================================== --- trunk/ruby-oci8/ext/oci8/metadata.c 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/metadata.c 2011-10-22 13:32:49 UTC (rev 459) @@ -40,7 +40,7 @@ p = oci8_get_handle(parent, oci8_cOCIHandle); - oci_lc(OCIAttrGet(parmhp, OCI_DTYPE_PARAM, &ptype, &size, OCI_ATTR_PTYPE, oci8_errhp)); + chker2(OCIAttrGet(parmhp, OCI_DTYPE_PARAM, &ptype, &size, OCI_ATTR_PTYPE, oci8_errhp), p); klass = rb_hash_aref(ptype_to_class, INT2FIX(ptype)); if (NIL_P(klass)) rb_raise(rb_eRuntimeError, "unknown parameter type %d", ptype); @@ -88,7 +88,8 @@ Check_Type(idx, T_FIXNUM); /* Is it remote call? */ - oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &value, &size, FIX2INT(idx), oci8_errhp)); + chker2(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &value, &size, FIX2INT(idx), oci8_errhp), + &svcctx->base); if (size != sizeof(OCIParam *)) { rb_raise(rb_eRuntimeError, "Invalid attribute size. expect %d, but %d", (sb4)sizeof(OCIParam *), size); } @@ -103,7 +104,8 @@ oci8_metadata_t *md = DATA_PTR(self); OCIParam *value; - oci_lc(OCIParamGet(md->base.hp.ptr, md->base.type, oci8_errhp, (dvoid *)&value, FIX2INT(idx))); + chker2(OCIParamGet(md->base.hp.ptr, md->base.type, oci8_errhp, (dvoid *)&value, FIX2INT(idx)), + &md->base); return oci8_metadata_create(value, md->svc, self); } @@ -133,22 +135,29 @@ VALUE type; VALUE obj; oci8_base_t *desc; + int rv; /* make a describe handle object */ obj = rb_obj_alloc(oci8_cOCIHandle); desc = DATA_PTR(obj); - oci_lc(OCIHandleAlloc(oci8_envhp, (dvoid *)&desc->hp.dschp, OCI_HTYPE_DESCRIBE, 0, 0)); + rv = OCIHandleAlloc(oci8_envhp, (dvoid *)&desc->hp.dschp, OCI_HTYPE_DESCRIBE, 0, 0); + if (rv != OCI_SUCCESS) { + oci8_env_raise(oci8_envhp, rv); + } desc->type = OCI_HTYPE_DESCRIBE; type = rb_hash_aref(class_to_ptype, klass); if (RTEST(check_public)) { sb4 val = -1; /* size of OCI_ATTR_DESC_PUBLIC is undocumented. */ - oci_lc(OCIAttrSet(desc->hp.dschp, OCI_HTYPE_DESCRIBE, &val, 0, OCI_ATTR_DESC_PUBLIC, oci8_errhp)); + chker2(OCIAttrSet(desc->hp.dschp, OCI_HTYPE_DESCRIBE, &val, 0, OCI_ATTR_DESC_PUBLIC, oci8_errhp), + &svcctx->base); } - oci_lc(OCIDescribeAny_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, objptr, objlen, - objtype, OCI_DEFAULT, (ub1)FIX2INT(type), desc->hp.dschp)); - oci_lc(OCIAttrGet(desc->hp.dschp, OCI_HTYPE_DESCRIBE, &parmhp, 0, OCI_ATTR_PARAM, oci8_errhp)); + chker2(OCIDescribeAny_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, objptr, objlen, + objtype, OCI_DEFAULT, (ub1)FIX2INT(type), desc->hp.dschp), + &svcctx->base); + chker2(OCIAttrGet(desc->hp.dschp, OCI_HTYPE_DESCRIBE, &parmhp, 0, OCI_ATTR_PARAM, oci8_errhp), + &svcctx->base); return oci8_metadata_create(parmhp, self, obj); } @@ -168,7 +177,8 @@ OCIRef *ref = NULL; /* remote call */ - oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp)); + chker2(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp), + &svcctx->base); return oci8_do_describe(md->svc, ref, 0, OCI_OTYPE_REF, klass, Qfalse); } @@ -179,11 +189,14 @@ OCIRef *tdo_ref = NULL; void *tdo; - oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &tdo_ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp)); + chker2(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &tdo_ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp), + &svcctx->base); if (tdo_ref == NULL) return Qnil; - oci_lc(OCIObjectPin_nb(svcctx, oci8_envhp, oci8_errhp, tdo_ref, 0, OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, &tdo)); - oci_lc(OCIObjectUnpin(oci8_envhp, oci8_errhp, tdo)); + chker2(OCIObjectPin_nb(svcctx, oci8_envhp, oci8_errhp, tdo_ref, 0, OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, &tdo), + &svcctx->base); + chker2(OCIObjectUnpin(oci8_envhp, oci8_errhp, tdo), + &svcctx->base); #if SIZEOF_LONG == SIZEOF_VOIDP return ((VALUE)tdo | (VALUE)1); #else Modified: trunk/ruby-oci8/ext/oci8/object.c =================================================================== --- trunk/ruby-oci8/ext/oci8/object.c 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/object.c 2011-10-22 13:32:49 UTC (rev 459) @@ -80,10 +80,12 @@ OCIObjectUnpin(oci8_envhp, oci8_errhp, tdo->hp.tdo); tdo->hp.tdo = NULL; } - oci_lc(OCIAttrGet(md->hp.ptr, OCI_DTYPE_PARAM, &tdo_ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp)); + chker2(OCIAttrGet(md->hp.ptr, OCI_DTYPE_PARAM, &tdo_ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp), + &svcctx->base); if (tdo_ref == NULL) return Qnil; - oci_lc(OCIObjectPin_nb(svcctx, oci8_envhp, oci8_errhp, tdo_ref, 0, OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, &tdo->hp.ptr)); + chker2(OCIObjectPin_nb(svcctx, oci8_envhp, oci8_errhp, tdo_ref, 0, OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, &tdo->hp.ptr), + &svcctx->base); oci8_link_to_parent(tdo, &svcctx->base); return self; } @@ -233,11 +235,11 @@ if (*ind) { return Qnil; } - oci_lc(OCICollSize(oci8_envhp, oci8_errhp, coll, &size)); + chker2(OCICollSize(oci8_envhp, oci8_errhp, coll, &size), &obj->base); ary = rb_ary_new2(size); for (idx = 0; idx < size; idx++) { boolean exists; - oci_lc(OCICollGetElem(oci8_envhp, oci8_errhp, coll, idx, &exists, &data, (dvoid**)&ind)); + chker2(OCICollGetElem(oci8_envhp, oci8_errhp, coll, idx, &exists, &data, (dvoid**)&ind), &obj->base); if (exists) { void *tmp; if (datatype == INT2FIX(ATTR_NAMED_COLLECTION)) { @@ -330,11 +332,13 @@ cb_data.coll = (OCIColl*)*obj->instancep; switch (FIX2INT(datatype)) { case ATTR_STRING: - oci_lc(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_VARCHAR2, NULL, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr)); + chker2(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_VARCHAR2, NULL, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr), + svcctx); cb_data.indp = &cb_data.ind; break; case ATTR_RAW: - oci_lc(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_RAW, NULL, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr)); + chker2(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_RAW, NULL, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr), + svcctx); cb_data.indp = &cb_data.ind; break; case ATTR_OCINUMBER: @@ -357,14 +361,18 @@ case ATTR_NAMED_TYPE: Check_Object(typeinfo, cOCI8TDO); tdo = DATA_PTR(typeinfo); - oci_lc(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_OBJECT, tdo->hp.tdo, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr)); - oci_lc(OCIObjectGetInd(oci8_envhp, oci8_errhp, cb_data.data.ptr, (dvoid**)&cb_data.indp)); + chker2(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_OBJECT, tdo->hp.tdo, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr), + svcctx); + chker2(OCIObjectGetInd(oci8_envhp, oci8_errhp, cb_data.data.ptr, (dvoid**)&cb_data.indp), + svcctx); break; case ATTR_NAMED_COLLECTION: Check_Object(typeinfo, cOCI8TDO); tdo = DATA_PTR(typeinfo); - oci_lc(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_NAMEDCOLLECTION, tdo->hp.tdo, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr)); - oci_lc(OCIObjectGetInd(oci8_envhp, oci8_errhp, cb_data.data.ptr, (dvoid**)&cb_data.indp)); + chker2(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_NAMEDCOLLECTION, tdo->hp.tdo, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr), + svcctx); + chker2(OCIObjectGetInd(oci8_envhp, oci8_errhp, cb_data.data.ptr, (dvoid**)&cb_data.indp), + svcctx); break; case ATTR_CLOB: case ATTR_NCLOB: @@ -395,9 +403,9 @@ sb4 idx; void *elem_ptr; - oci_lc(OCICollSize(oci8_envhp, oci8_errhp, coll, &size)); + chkerr(OCICollSize(oci8_envhp, oci8_errhp, coll, &size)); if (RARRAY_LEN(val) < size) { - oci_lc(OCICollTrim(oci8_envhp, oci8_errhp, size - RARRAY_LEN(val), coll)); + chkerr(OCICollTrim(oci8_envhp, oci8_errhp, size - RARRAY_LEN(val), coll)); } for (idx = 0; idx < RARRAY_LEN(val); idx++) { switch (FIX2INT(datatype)) { @@ -422,9 +430,9 @@ break; } if (idx < size) { - oci_lc(OCICollAssignElem(oci8_envhp, oci8_errhp, idx, elem_ptr, cb_data->indp, cb_data->coll)); + chkerr(OCICollAssignElem(oci8_envhp, oci8_errhp, idx, elem_ptr, cb_data->indp, cb_data->coll)); } else { - oci_lc(OCICollAppend(oci8_envhp, oci8_errhp, elem_ptr, cb_data->indp, coll)); + chkerr(OCICollAppend(oci8_envhp, oci8_errhp, elem_ptr, cb_data->indp, coll)); } } return Qnil; @@ -468,13 +476,13 @@ switch (FIX2INT(datatype)) { case ATTR_STRING: OCI8StringValue(val); - oci_lc(OCIStringAssignText(oci8_envhp, oci8_errhp, + chkerr(OCIStringAssignText(oci8_envhp, oci8_errhp, RSTRING_ORATEXT(val), RSTRING_LEN(val), (OCIString **)data)); break; case ATTR_RAW: StringValue(val); - oci_lc(OCIRawAssignBytes(oci8_envhp, oci8_errhp, + chkerr(OCIRawAssignBytes(oci8_envhp, oci8_errhp, RSTRING_ORATEXT(val), RSTRING_LEN(val), (OCIRaw **)data)); break; @@ -624,8 +632,10 @@ obj->null_structp = (char**)&obind->u.null_structs[idx]; oci8_link_to_parent(&obj->base, &obind->base); - oci_lc(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->base.hp.svc, tc, tdo->hp.tdo, NULL, OCI_DURATION_SESSION, TRUE, (dvoid**)obj->instancep)); - oci_lc(OCIObjectGetInd(oci8_envhp, oci8_errhp, (dvoid*)*obj->instancep, (dvoid**)obj->null_structp)); + chker2(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->base.hp.svc, tc, tdo->hp.tdo, NULL, OCI_DURATION_SESSION, TRUE, (dvoid**)obj->instancep), + &svcctx->base); + chker2(OCIObjectGetInd(oci8_envhp, oci8_errhp, (dvoid*)*obj->instancep, (dvoid**)obj->null_structp), + &svcctx->base); *(OCIInd*)*obj->null_structp = -1; } while (++idx < obind->maxar_sz); } @@ -635,12 +645,14 @@ oci8_base_t *tdo = DATA_PTR(obind->tdo); switch (obind->base.type) { case OCI_HTYPE_DEFINE: - oci_lc(OCIDefineObject(obind->base.hp.dfn, oci8_errhp, tdo->hp.tdo, - obind->valuep, 0, obind->u.null_structs, 0)); + chker2(OCIDefineObject(obind->base.hp.dfn, oci8_errhp, tdo->hp.tdo, + obind->valuep, 0, obind->u.null_structs, 0), + &obind->base); break; case OCI_HTYPE_BIND: - oci_lc(OCIBindObject(obind->base.hp.bnd, oci8_errhp, tdo->hp.tdo, - obind->valuep, 0, obind->u.null_structs, 0)); + chker2(OCIBindObject(obind->base.hp.bnd, oci8_errhp, tdo->hp.tdo, + obind->valuep, 0, obind->u.null_structs, 0), + &obind->base); break; } } Modified: trunk/ruby-oci8/ext/oci8/oci8.c =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8.c 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/oci8.c 2011-10-22 13:32:49 UTC (rev 459) @@ -358,20 +358,23 @@ } /* logon */ - oci_lc(OCILogon_nb(svcctx, oci8_envhp, oci8_errhp, &svcctx->base.hp.svc, + chker2(OCILogon_nb(svcctx, oci8_envhp, oci8_errhp, &svcctx->base.hp.svc, RSTRING_ORATEXT(username), RSTRING_LEN(username), RSTRING_ORATEXT(password), RSTRING_LEN(password), NIL_P(dbname) ? NULL : RSTRING_ORATEXT(dbname), - NIL_P(dbname) ? 0 : RSTRING_LEN(dbname))); + NIL_P(dbname) ? 0 : RSTRING_LEN(dbname)), + &svcctx->base); svcctx->base.type = OCI_HTYPE_SVCCTX; svcctx->logoff_strategy = &simple_logoff; /* setup the session handle */ - oci_lc(OCIAttrGet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, &svcctx->usrhp, 0, OCI_ATTR_SESSION, oci8_errhp)); + chker2(OCIAttrGet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, &svcctx->usrhp, 0, OCI_ATTR_SESSION, oci8_errhp), + &svcctx->base); copy_session_handle(svcctx); /* setup the server handle */ - oci_lc(OCIAttrGet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, &svcctx->srvhp, 0, OCI_ATTR_SERVER, oci8_errhp)); + chker2(OCIAttrGet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, &svcctx->srvhp, 0, OCI_ATTR_SERVER, oci8_errhp), + &svcctx->base); copy_server_handle(svcctx); return Qnil; @@ -469,13 +472,15 @@ Check_Type(mode, T_FIXNUM); /* attach to the server */ - oci_lc(OCIServerAttach_nb(svcctx, svcctx->srvhp, oci8_errhp, + chker2(OCIServerAttach_nb(svcctx, svcctx->srvhp, oci8_errhp, NIL_P(dbname) ? NULL : RSTRING_ORATEXT(dbname), NIL_P(dbname) ? 0 : RSTRING_LEN(dbname), - FIX2UINT(mode))); - oci_lc(OCIAttrSet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, + FIX2UINT(mode)), + &svcctx->base); + chker2(OCIAttrSet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, svcctx->srvhp, 0, OCI_ATTR_SERVER, - oci8_errhp)); + oci8_errhp), + &svcctx->base); svcctx->state |= OCI8_STATE_SERVER_ATTACH_WAS_CALLED; return self; } @@ -504,12 +509,14 @@ Check_Type(mode, T_FIXNUM); /* begin session */ - oci_lc(OCISessionBegin_nb(svcctx, svcctx->base.hp.ptr, oci8_errhp, + chker2(OCISessionBegin_nb(svcctx, svcctx->base.hp.ptr, oci8_errhp, svcctx->usrhp, FIX2UINT(cred), - FIX2UINT(mode))); - oci_lc(OCIAttrSet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, + FIX2UINT(mode)), + &svcctx->base); + chker2(OCIAttrSet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, svcctx->usrhp, 0, OCI_ATTR_SESSION, - oci8_errhp)); + oci8_errhp), + &svcctx->base); svcctx->state |= OCI8_STATE_SESSION_BEGIN_WAS_CALLED; return Qnil; } @@ -533,7 +540,7 @@ void *data = strategy->prepare(svcctx); svcctx->base.type = 0; svcctx->logoff_strategy = NULL; - oci_lc(oci8_blocking_region(svcctx, strategy->execute, data)); + chker2(oci8_blocking_region(svcctx, strategy->execute, data), &svcctx->base); } return Qtrue; } @@ -563,7 +570,7 @@ static VALUE oci8_commit(VALUE self) { oci8_svcctx_t *svcctx = DATA_PTR(self); - oci_lc(OCITransCommit_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, OCI_DEFAULT)); + chker2(OCITransCommit_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, OCI_DEFAULT), &svcctx->base); return self; } @@ -576,7 +583,7 @@ static VALUE oci8_rollback(VALUE self) { oci8_svcctx_t *svcctx = DATA_PTR(self); - oci_lc(OCITransRollback_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, OCI_DEFAULT)); + chker2(OCITransRollback_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, OCI_DEFAULT), &svcctx->base); return self; } @@ -597,7 +604,7 @@ #else sb1 non_blocking; - oci_lc(OCIAttrGet(svcctx->srvhp, OCI_HTYPE_SERVER, &non_blocking, 0, OCI_ATTR_NONBLOCKING_MODE, oci8_errhp)); + chker2(OCIAttrGet(svcctx->srvhp, OCI_HTYPE_SERVER, &non_blocking, 0, OCI_ATTR_NONBLOCKING_MODE, oci8_errhp), &svcctx->base); return non_blocking ? Qtrue : Qfalse; #endif } @@ -647,10 +654,10 @@ #else sb1 non_blocking; - oci_lc(OCIAttrGet(svcctx->srvhp, OCI_HTYPE_SERVER, &non_blocking, 0, OCI_ATTR_NONBLOCKING_MODE, oci8_errhp)); + chker2(OCIAttrGet(svcctx->srvhp, OCI_HTYPE_SERVER, &non_blocking, 0, OCI_ATTR_NONBLOCKING_MODE, oci8_errhp), &svcctx->base); if ((RTEST(val) && !non_blocking) || (!RTEST(val) && non_blocking)) { /* toggle blocking / non-blocking. */ - oci_lc(OCIAttrSet(svcctx->srvhp, OCI_HTYPE_SERVER, 0, 0, OCI_ATTR_NONBLOCKING_MODE, oci8_errhp)); + chker2(OCIAttrSet(svcctx->srvhp, OCI_HTYPE_SERVER, 0, 0, OCI_ATTR_NONBLOCKING_MODE, oci8_errhp), &svcctx->base); } #endif return val; @@ -729,17 +736,12 @@ static VALUE oci8_break(VALUE self) { oci8_svcctx_t *svcctx = DATA_PTR(self); -#ifndef HAVE_RB_THREAD_BLOCKING_REGION - sword rv; -#endif if (NIL_P(svcctx->executing_thread)) { return Qfalse; } #ifndef HAVE_RB_THREAD_BLOCKING_REGION - rv = OCIBreak(svcctx->base.hp.ptr, oci8_errhp); - if (rv != OCI_SUCCESS) - oci8_raise(oci8_errhp, rv, NULL); + chker2(OCIBreak(svcctx->base.hp.ptr, oci8_errhp), &svcctx->base); #endif rb_thread_wakeup(svcctx->executing_thread); return Qtrue; @@ -777,9 +779,8 @@ oci8_svcctx_t *svcctx = DATA_PTR(self); char buf[100]; ub4 version; - char *p; - oci_lc(OCIServerRelease(svcctx->base.hp.ptr, oci8_errhp, (text*)buf, sizeof(buf), (ub1)svcctx->base.type, &version)); + chker2(OCIServerRelease(svcctx->base.hp.ptr, oci8_errhp, (text*)buf, sizeof(buf), (ub1)svcctx->base.type, &version), &svcctx->base); return UINT2NUM(version); } @@ -862,8 +863,9 @@ if (size > 0 && ptr[0] == ':') { rb_raise(rb_eArgError, "client identifier should not start with ':'."); } - oci_lc(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr, - size, OCI_ATTR_CLIENT_IDENTIFIER, oci8_errhp)); + chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr, + size, OCI_ATTR_CLIENT_IDENTIFIER, oci8_errhp), + DATA_PTR(self)); } else { /* Workaround for Bug 2449486 */ oci8_exec_sql_var_t bind_vars[1]; @@ -932,8 +934,9 @@ } if (oracle_client_version >= ORAVER_10_1) { /* Oracle 10g or upper */ - oci_lc(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr, - size, OCI_ATTR_MODULE, oci8_errhp)); + chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr, + size, OCI_ATTR_MODULE, oci8_errhp), + DATA_PTR(self)); } else { /* Oracle 9i or lower */ oci8_exec_sql_var_t bind_vars[1]; @@ -1001,8 +1004,9 @@ } if (oracle_client_version >= ORAVER_10_1) { /* Oracle 10g or upper */ - oci_lc(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr, - size, OCI_ATTR_ACTION, oci8_errhp)); + chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr, + size, OCI_ATTR_ACTION, oci8_errhp), + DATA_PTR(self)); } else { /* Oracle 9i or lower */ oci8_exec_sql_var_t bind_vars[1]; @@ -1063,8 +1067,9 @@ } if (oracle_client_version >= ORAVER_10_1) { /* Oracle 10g or upper */ - oci_lc(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr, - size, OCI_ATTR_CLIENT_INFO, oci8_errhp)); + chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr, + size, OCI_ATTR_CLIENT_INFO, oci8_errhp), + DATA_PTR(self)); } else { /* Oracle 9i or lower */ oci8_exec_sql_var_t bind_vars[1]; @@ -1137,6 +1142,7 @@ rb_define_method(cOCI8, "module=", oci8_set_module, 1); rb_define_method(cOCI8, "action=", oci8_set_action, 1); rb_define_method(cOCI8, "client_info=", oci8_set_client_info, 1); + rb_define_attr(cOCI8, "last_error", 1, 1); return cOCI8; } Modified: trunk/ruby-oci8/ext/oci8/oci8.h =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8.h 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/oci8.h 2011-10-22 13:32:49 UTC (rev 459) @@ -371,13 +371,9 @@ #define oci8_raise_init_error() oci8_do_raise_init_error(__FILE__, __LINE__) #define oci8_raise_by_msgno(msgno, default_msg) oci8_do_raise_by_msgno(msgno, default_msg, __FILE__, __LINE__) -/* raise on error */ -#define oci_lc(rv) do { \ - sword __rv = (rv); \ - if (__rv != OCI_SUCCESS) { \ - oci8_raise(oci8_errhp, __rv, NULL); \ - } \ -} while(0) +#define chkerr(status) oci8_check_error_((status), NULL, NULL, __FILE__, __LINE__) +#define chker2(status, base) oci8_check_error_((status), (base), NULL, __FILE__, __LINE__) +#define chker3(status, base, stmt) oci8_check_error_((status), (base), (stmt), __FILE__, __LINE__) #if SIZEOF_LONG > 4 #define UB4_TO_NUM INT2FIX @@ -419,6 +415,7 @@ void Init_oci8_env(void); /* oci8lib.c */ +extern ID oci8_id_at_last_error; extern ID oci8_id_new; extern ID oci8_id_get; extern ID oci8_id_set; @@ -453,14 +450,13 @@ /* error.c */ extern VALUE eOCIException; extern VALUE eOCIBreak; -VALUE oci8_make_exc(dvoid *errhp, sword status, ub4 type, OCIStmt *stmthp, const char *file, int line); void Init_oci8_error(void); -NORETURN(void oci8_do_raise(OCIError *, sword status, OCIStmt *, const char *file, int line)); NORETURN(void oci8_do_env_raise(OCIEnv *, sword status, const char *file, int line)); NORETURN(void oci8_do_raise_init_error(const char *file, int line)); sb4 oci8_get_error_code(OCIError *errhp); VALUE oci8_get_error_message(ub4 msgno, const char *default_msg); NORETURN(void oci8_do_raise_by_msgno(ub4 msgno, const char *default_msg, const char *file, int line)); +void oci8_check_error_(sword status, oci8_base_t *base, OCIStmt *stmthp, const char *file, int line); /* ocihandle.c */ void Init_oci8_handle(void); @@ -538,12 +534,12 @@ void Init_oci_object(VALUE mOCI); /* attr.c */ -VALUE oci8_get_sb1_attr(oci8_base_t *base, ub4 attrtype); -VALUE oci8_get_ub2_attr(oci8_base_t *base, ub4 attrtype); -VALUE oci8_get_sb2_attr(oci8_base_t *base, ub4 attrtype); -VALUE oci8_get_ub4_attr(oci8_base_t *base, ub4 attrtype); -VALUE oci8_get_string_attr(oci8_base_t *base, ub4 attrtype); -VALUE oci8_get_rowid_attr(oci8_base_t *base, ub4 attrtype); +VALUE oci8_get_sb1_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp); +VALUE oci8_get_ub2_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp); +VALUE oci8_get_sb2_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp); +VALUE oci8_get_ub4_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp); +VALUE oci8_get_string_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp); +VALUE oci8_get_rowid_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp); /* encoding.c */ void Init_oci8_encoding(VALUE cOCI8); Modified: trunk/ruby-oci8/ext/oci8/oci8lib.c =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8lib.c 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/oci8lib.c 2011-10-22 13:32:49 UTC (rev 459) @@ -10,6 +10,7 @@ #include #endif +ID oci8_id_at_last_error; ID oci8_id_new; ID oci8_id_get; ID oci8_id_set; @@ -75,6 +76,7 @@ } #endif + oci8_id_at_last_error = rb_intern("@last_error"); oci8_id_new = rb_intern("new"); oci8_id_get = rb_intern("get"); oci8_id_set = rb_intern("set"); @@ -361,23 +363,26 @@ if (rv != OCI_SUCCESS) { oci8_env_raise(oci8_envhp, rv); } - oci_lc(OCIStmtPrepare(arg->stmtp, oci8_errhp, (text*)arg->sql_text, - strlen(arg->sql_text), OCI_NTV_SYNTAX, OCI_DEFAULT)); + chker2(OCIStmtPrepare(arg->stmtp, oci8_errhp, (text*)arg->sql_text, + strlen(arg->sql_text), OCI_NTV_SYNTAX, OCI_DEFAULT), + &arg->svcctx->base); for (pos = 0; pos < arg->num_define_vars; pos++) { arg->define_vars[pos].hp = NULL; - oci_lc(OCIDefineByPos(arg->stmtp, (OCIDefine**)&arg->define_vars[pos].hp, + chker3(OCIDefineByPos(arg->stmtp, (OCIDefine**)&arg->define_vars[pos].hp, oci8_errhp, pos + 1, arg->define_vars[pos].valuep, arg->define_vars[pos].value_sz, arg->define_vars[pos].dty, arg->define_vars[pos].indp, - arg->define_vars[pos].alenp, NULL, OCI_DEFAULT)); + arg->define_vars[pos].alenp, NULL, OCI_DEFAULT), + &arg->svcctx->base, arg->stmtp); } for (pos = 0; pos < arg->num_bind_vars; pos++) { arg->bind_vars[pos].hp = NULL; - oci_lc(OCIBindByPos(arg->stmtp, (OCIBind**)&arg->bind_vars[pos].hp, + chker3(OCIBindByPos(arg->stmtp, (OCIBind**)&arg->bind_vars[pos].hp, oci8_errhp, pos + 1, arg->bind_vars[pos].valuep, arg->bind_vars[pos].value_sz, arg->bind_vars[pos].dty, arg->bind_vars[pos].indp, arg->bind_vars[pos].alenp, - NULL, 0, NULL, OCI_DEFAULT)); + NULL, 0, NULL, OCI_DEFAULT), + &arg->svcctx->base, arg->stmtp); } rv = OCIStmtExecute_nb(arg->svcctx, arg->svcctx->base.hp.svc, arg->stmtp, oci8_errhp, 1, 0, NULL, NULL, OCI_DEFAULT); if (rv == OCI_ERROR) { @@ -390,7 +395,7 @@ } } if (arg->raise_on_error) { - oci_lc(rv); + chker3(rv, &arg->svcctx->base, arg->stmtp); } return (VALUE)rv; } Modified: trunk/ruby-oci8/ext/oci8/ocidatetime.c =================================================================== --- trunk/ruby-oci8/ext/oci8/ocidatetime.c 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/ocidatetime.c 2011-10-22 13:32:49 UTC (rev 459) @@ -113,10 +113,10 @@ sb1 tz_hour; sb1 tz_minute; - oci_lc(OCIDateTimeGetDate(oci8_envhp, oci8_errhp, dttm, &year, &month, &day)); - oci_lc(OCIDateTimeGetTime(oci8_envhp, oci8_errhp, dttm, &hour, &minute, &sec, &fsec)); + chkerr(OCIDateTimeGetDate(oci8_envhp, oci8_errhp, dttm, &year, &month, &day)); + chkerr(OCIDateTimeGetTime(oci8_envhp, oci8_errhp, dttm, &hour, &minute, &sec, &fsec)); if (have_tz) { - oci_lc(OCIDateTimeGetTimeZoneOffset(oci8_envhp, oci8_errhp, dttm, &tz_hour, &tz_minute)); + chkerr(OCIDateTimeGetTimeZoneOffset(oci8_envhp, oci8_errhp, dttm, &tz_hour, &tz_minute)); } return rb_ary_new3(9, INT2FIX(year), @@ -200,7 +200,7 @@ tzlen = strlen(tz_str); } /* construct */ - oci_lc(OCIDateTimeConstruct(seshp ? (void*)seshp : (void*)oci8_envhp, oci8_errhp, dttm, + chkerr(OCIDateTimeConstruct(seshp ? (void*)seshp : (void*)oci8_envhp, oci8_errhp, dttm, (sb2)year, (ub1)month, (ub1)day, @@ -307,7 +307,7 @@ sb4 year; sb4 month; - oci_lc(OCIIntervalGetYearMonth(oci8_envhp, oci8_errhp, &year, &month, s)); + chkerr(OCIIntervalGetYearMonth(oci8_envhp, oci8_errhp, &year, &month, s)); return rb_ary_new3(2, INT2FIX(year), INT2FIX(month)); } @@ -323,7 +323,7 @@ year = NUM2INT(RARRAY_PTR(val)[0]); month = NUM2INT(RARRAY_PTR(val)[1]); if (oracle_client_version >= ORAVERNUM(9, 2, 0, 3, 0)) { - oci_lc(OCIIntervalSetYearMonth(oci8_envhp, oci8_errhp, + chkerr(OCIIntervalSetYearMonth(oci8_envhp, oci8_errhp, year, month, intvl)); } else { /* Workaround for Bug 2227982 */ @@ -340,7 +340,7 @@ month = -month; } sprintf(buf, "%s%d-%d", sign, year, month); - oci_lc(OCIIntervalFromText(oci8_envhp, oci8_errhp, (text*)buf, strlen(buf), intvl)); + chkerr(OCIIntervalFromText(oci8_envhp, oci8_errhp, (text*)buf, strlen(buf), intvl)); } return intvl; } @@ -353,7 +353,7 @@ sb4 sec; sb4 fsec; - oci_lc(OCIIntervalGetDaySecond(oci8_envhp, oci8_errhp, &day, &hour, &minute, &sec, &fsec, s)); + chkerr(OCIIntervalGetDaySecond(oci8_envhp, oci8_errhp, &day, &hour, &minute, &sec, &fsec, s)); return rb_ary_new3(5, INT2FIX(day), INT2FIX(hour), INT2FIX(minute), INT2FIX(sec), @@ -378,7 +378,7 @@ sec = NUM2INT(RARRAY_PTR(val)[3]); fsec = NUM2INT(RARRAY_PTR(val)[4]); if (oracle_client_version >= ORAVERNUM(9, 2, 0, 3, 0)) { - oci_lc(OCIIntervalSetDaySecond(oci8_envhp, oci8_errhp, + chkerr(OCIIntervalSetDaySecond(oci8_envhp, oci8_errhp, day, hour, minute, sec, fsec, intvl)); } else { /* Workaround for Bug 2227982 */ @@ -401,7 +401,7 @@ } } sprintf(buf, "%s%d %02d:%02d:%02d.%09d", sign, day, hour, minute, sec, fsec); - oci_lc(OCIIntervalFromText(oci8_envhp, oci8_errhp, (text*)buf, strlen(buf), intvl)); + chkerr(OCIIntervalFromText(oci8_envhp, oci8_errhp, (text*)buf, strlen(buf), intvl)); } return intvl; } Modified: trunk/ruby-oci8/ext/oci8/ocihandle.c =================================================================== --- trunk/ruby-oci8/ext/oci8/ocihandle.c 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/ocihandle.c 2011-10-22 13:32:49 UTC (rev 459) @@ -123,7 +123,7 @@ v.dummy = MAGIC_NUMBER; Check_Type(attr_type, T_FIXNUM); - oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base); return INT2FIX(v.value); } @@ -145,7 +145,7 @@ v.dummy = MAGIC_NUMBER; Check_Type(attr_type, T_FIXNUM); - oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base); return INT2FIX(v.value); } @@ -167,7 +167,7 @@ v.dummy = MAGIC_NUMBER; Check_Type(attr_type, T_FIXNUM); - oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base); return UINT2NUM(v.value); } @@ -189,7 +189,7 @@ v.dummy = MAGIC_NUMBER; Check_Type(attr_type, T_FIXNUM); - oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base); return ULL2NUM(v.value); } @@ -211,7 +211,7 @@ v.dummy = MAGIC_NUMBER; Check_Type(attr_type, T_FIXNUM); - oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base); return INT2FIX(v.value); } @@ -233,7 +233,7 @@ v.dummy = MAGIC_NUMBER; Check_Type(attr_type, T_FIXNUM); - oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base); return INT2FIX(v.value); } @@ -255,7 +255,7 @@ v.dummy = MAGIC_NUMBER; Check_Type(attr_type, T_FIXNUM); - oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base); return INT2NUM(v.value); } @@ -277,7 +277,7 @@ v.dummy = MAGIC_NUMBER; Check_Type(attr_type, T_FIXNUM); - oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base); return LL2NUM(v.value); } @@ -299,7 +299,7 @@ v.dummy = MAGIC_NUMBER; Check_Type(attr_type, T_FIXNUM); - oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base); return v.value ? Qtrue : Qfalse; } @@ -327,7 +327,7 @@ v.dummy = MAGIC_NUMBER; Check_Type(attr_type, T_FIXNUM); - oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp), base); return rb_external_str_new_with_enc(v.value, size, oci8_encoding); } @@ -354,7 +354,7 @@ v.dummy = 0; Check_Type(attr_type, T_FIXNUM); - oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp), base); return rb_tainted_str_new(v.value, size); } @@ -381,7 +381,7 @@ v.dummy = 0; Check_Type(attr_type, T_FIXNUM); - oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp), base); return oci8_make_integer(v.value, oci8_errhp); } @@ -409,7 +409,7 @@ v.dummy = 0; Check_Type(attr_type, T_FIXNUM); - oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp), base); if (NIL_P(cOraDate)) cOraDate = rb_eval_string("OraDate"); return rb_funcall(cOraDate, oci8_id_new, 6, @@ -441,7 +441,7 @@ Check_Type(attr_type, T_FIXNUM); value = (ub1)check_data_range(val, 0, UCHAR_MAX, "ub1"); /* set attribute */ - oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base); return self; } @@ -465,7 +465,7 @@ Check_Type(attr_type, T_FIXNUM); value = (ub2)check_data_range(val, 0, USHRT_MAX, "ub2"); /* set attribute */ - oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base); return self; } @@ -489,7 +489,7 @@ Check_Type(attr_type, T_FIXNUM); value = NUM2UINT(val); /* set attribute */ - oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base); return self; } @@ -513,7 +513,7 @@ Check_Type(attr_type, T_FIXNUM); value = NUM2ULL(val); /* set attribute */ - oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base); return self; } @@ -537,7 +537,7 @@ Check_Type(attr_type, T_FIXNUM); value = (sb1)check_data_range(val, CHAR_MIN, CHAR_MAX, "sb1"); /* set attribute */ - oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base); return self; } @@ -561,7 +561,7 @@ Check_Type(attr_type, T_FIXNUM); value = (sb2)check_data_range(val, SHRT_MIN, SHRT_MAX, "sb2"); /* set attribute */ - oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base); return self; } @@ -585,7 +585,7 @@ Check_Type(attr_type, T_FIXNUM); value = NUM2INT(val); /* set attribute */ - oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base); return self; } @@ -609,7 +609,7 @@ Check_Type(attr_type, T_FIXNUM); value = NUM2LL(val); /* set attribute */ - oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base); return self; } @@ -633,7 +633,7 @@ Check_Type(attr_type, T_FIXNUM); value = RTEST(val) ? TRUE : FALSE; /* set attribute */ - oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base); return self; } @@ -655,7 +655,7 @@ Check_Type(attr_type, T_FIXNUM); OCI8SafeStringValue(val); /* set attribute */ - oci_lc(OCIAttrSet(base->hp.ptr, base->type, RSTRING_PTR(val), RSTRING_LEN(val), FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrSet(base->hp.ptr, base->type, RSTRING_PTR(val), RSTRING_LEN(val), FIX2INT(attr_type), oci8_errhp), base); return self; } @@ -675,7 +675,7 @@ Check_Type(attr_type, T_FIXNUM); SafeStringValue(val); /* set attribute */ - oci_lc(OCIAttrSet(base->hp.ptr, base->type, RSTRING_PTR(val), RSTRING_LEN(val), FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrSet(base->hp.ptr, base->type, RSTRING_PTR(val), RSTRING_LEN(val), FIX2INT(attr_type), oci8_errhp), base); return self; } @@ -698,7 +698,7 @@ Check_Type(attr_type, T_FIXNUM); oci8_set_integer(&value, val, oci8_errhp); /* set attribute */ - oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp)); + chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base); return self; } Modified: trunk/ruby-oci8/ext/oci8/ocinumber.c =================================================================== --- trunk/ruby-oci8/ext/oci8/ocinumber.c 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/ocinumber.c 2011-10-22 13:32:49 UTC (rev 459) @@ -119,7 +119,7 @@ OCINumber *d; obj = Data_Make_Struct(cOCINumber, OCINumber, NULL, xfree, d); - oci_lc(OCINumberAssign(errhp, s, d)); + chkerr(OCINumberAssign(errhp, s, d)); return obj; } @@ -184,7 +184,7 @@ nls_params_ptr = RSTRING_ORATEXT(nls_params); nls_params_len = RSTRING_LEN(nls_params); } - oci_lc(OCINumberFromText(errhp, + chkerr(OCINumberFromText(errhp, RSTRING_ORATEXT(str), RSTRING_LEN(str), fmt_ptr, fmt_len, nls_params_ptr, nls_params_len, result)); @@ -205,7 +205,7 @@ case T_FIXNUM: /* set from long. */ sl = NUM2LONG(num); - oci_lc(OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, result)); + chkerr(OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, result)); return 1; case T_FLOAT: /* set from double. */ @@ -219,7 +219,7 @@ } if (RTEST(rb_obj_is_instance_of(num, cOCINumber))) { /* OCI::Number */ - oci_lc(OCINumberAssign(errhp, DATA_PTR(num), result)); + chkerr(OCINumberAssign(errhp, DATA_PTR(num), result)); return 1; } if (rb_respond_to(num, id_split)) { @@ -257,11 +257,11 @@ } exponent = FIX2INT(ary[3]); - oci_lc(OCINumberShift(errhp, &digits, exponent - digits_len, &work)); + chkerr(OCINumberShift(errhp, &digits, exponent - digits_len, &work)); if (sign >= 0) { - oci_lc(OCINumberAssign(errhp, &work, result)); + chkerr(OCINumberAssign(errhp, &work, result)); } else { - oci_lc(OCINumberNeg(errhp, &work, result)); + chkerr(OCINumberNeg(errhp, &work, result)); } return 1; } @@ -274,7 +274,7 @@ if (set_oci_number_from_num(&numerator, rb_funcall(num, id_numerator, 0), 0, errhp) && set_oci_number_from_num(&denominator, rb_funcall(num, id_denominator, 0), 0, errhp)) { - oci_lc(OCINumberDiv(errhp, &numerator, &denominator, result)); + chkerr(OCINumberDiv(errhp, &numerator, &denominator, result)); return 1; } } @@ -299,7 +299,7 @@ OCINumber work; set_oci_number_from_num(&work, self, 1, errhp); - oci_lc(OCINumberTrunc(errhp, &work, 0, result)); + chkerr(OCINumberTrunc(errhp, &work, 0, result)); return result; } @@ -325,7 +325,7 @@ } else { double dbl; - oci_lc(OCINumberToReal(errhp, s, sizeof(double), &dbl)); + chkerr(OCINumberToReal(errhp, s, sizeof(double), &dbl)); return dbl; } } @@ -356,7 +356,7 @@ oci8_raise_by_msgno(rv, NULL); } } else { - oci_lc(OCINumberFromReal(errhp, &dbl, sizeof(dbl), result)); + chkerr(OCINumberFromReal(errhp, &dbl, sizeof(dbl), result)); } return result; } @@ -380,9 +380,9 @@ set_oci_number_from_num(&nX, Xcoordinate, 1, errhp); set_oci_number_from_num(&nY, Ycoordinate, 1, errhp); /* check zero */ - oci_lc(OCINumberIsZero(errhp, &nX, &is_zero)); + chkerr(OCINumberIsZero(errhp, &nX, &is_zero)); if (is_zero) { - oci_lc(OCINumberSign(errhp, &nY, &sign)); + chkerr(OCINumberSign(errhp, &nY, &sign)); switch (sign) { case 0: return INT2FIX(0); /* atan2(0, 0) => 0 or ERROR? */ @@ -393,7 +393,7 @@ } } /* atan2 */ - oci_lc(OCINumberArcTan2(errhp, &nY, &nX, &rv)); + chkerr(OCINumberArcTan2(errhp, &nY, &nX, &rv)); return oci8_make_ocinumber(&rv, errhp); } @@ -410,7 +410,7 @@ OCINumber r; OCINumber rv; - oci_lc(OCINumberCos(errhp, TO_OCINUM(&r, radian, errhp), &rv)); + chkerr(OCINumberCos(errhp, TO_OCINUM(&r, radian, errhp), &rv)); return oci8_make_ocinumber(&rv, errhp); } @@ -427,7 +427,7 @@ OCINumber r; OCINumber rv; - oci_lc(OCINumberSin(errhp, TO_OCINUM(&r, radian, errhp), &rv)); + chkerr(OCINumberSin(errhp, TO_OCINUM(&r, radian, errhp), &rv)); return oci8_make_ocinumber(&rv, errhp); } @@ -443,7 +443,7 @@ OCINumber r; OCINumber rv; - oci_lc(OCINumberTan(errhp, TO_OCINUM(&r, radian, errhp), &rv)); + chkerr(OCINumberTan(errhp, TO_OCINUM(&r, radian, errhp), &rv)); return oci8_make_ocinumber(&rv, errhp); } @@ -462,15 +462,15 @@ set_oci_number_from_num(&n, num, 1, errhp); /* check upper bound */ - oci_lc(OCINumberCmp(errhp, &n, &const_p1, &sign)); + chkerr(OCINumberCmp(errhp, &n, &const_p1, &sign)); if (sign > 0) rb_raise(rb_eRangeError, "out of range for acos"); /* check lower bound */ - oci_lc(OCINumberCmp(errhp, &n, &const_m1, &sign)); + chkerr(OCINumberCmp(errhp, &n, &const_m1, &sign)); if (sign < 0) rb_raise(rb_eRangeError, "out of range for acos"); /* acos */ - oci_lc(OCINumberArcCos(errhp, &n, &r)); + chkerr(OCINumberArcCos(errhp, &n, &r)); return oci8_make_ocinumber(&r, errhp); } @@ -489,15 +489,15 @@ set_oci_number_from_num(&n, num, 1, errhp); /* check upper bound */ - oci_lc(OCINumberCmp(errhp, &n, &const_p1, &sign)); + chkerr(OCINumberCmp(errhp, &n, &const_p1, &sign)); if (sign > 0) rb_raise(rb_eRangeError, "out of range for asin"); /* check lower bound */ - oci_lc(OCINumberCmp(errhp, &n, &const_m1, &sign)); + chkerr(OCINumberCmp(errhp, &n, &const_m1, &sign)); if (sign < 0) rb_raise(rb_eRangeError, "out of range for asin"); /* asin */ - oci_lc(OCINumberArcSin(errhp, &n, &r)); + chkerr(OCINumberArcSin(errhp, &n, &r)); return oci8_make_ocinumber(&r, errhp); } @@ -513,7 +513,7 @@ OCINumber n; OCINumber r; - oci_lc(OCINumberArcTan(errhp, TO_OCINUM(&n, num, errhp), &r)); + chkerr(OCINumberArcTan(errhp, TO_OCINUM(&n, num, errhp), &r)); return oci8_make_ocinumber(&r, errhp); } @@ -529,7 +529,7 @@ OCINumber n; OCINumber r; - oci_lc(OCINumberHypCos(errhp, TO_OCINUM(&n, num, errhp), &r)); + chkerr(OCINumberHypCos(errhp, TO_OCINUM(&n, num, errhp), &r)); return oci8_make_ocinumber(&r, errhp); } @@ -546,7 +546,7 @@ OCINumber n; OCINumber r; - oci_lc(OCINumberHypSin(errhp, TO_OCINUM(&n, num, errhp), &r)); + chkerr(OCINumberHypSin(errhp, TO_OCINUM(&n, num, errhp), &r)); return oci8_make_ocinumber(&r, errhp); } @@ -563,7 +563,7 @@ OCINumber n; OCINumber r; - oci_lc(OCINumberHypTan(errhp, TO_OCINUM(&n, num, errhp), &r)); + chkerr(OCINumberHypTan(errhp, TO_OCINUM(&n, num, errhp), &r)); return oci8_make_ocinumber(&r, errhp); } @@ -579,7 +579,7 @@ OCINumber n; OCINumber r; - oci_lc(OCINumberExp(errhp, TO_OCINUM(&n, num, errhp), &r)); + chkerr(OCINumberExp(errhp, TO_OCINUM(&n, num, errhp), &r)); return oci8_make_ocinumber(&r, errhp); } @@ -602,20 +602,20 @@ rb_scan_args(argc, argv, "11", &num, &base); set_oci_number_from_num(&n, num, 1, errhp); - oci_lc(OCINumberSign(errhp, &n, &sign)); + chkerr(OCINumberSign(errhp, &n, &sign)); if (sign <= 0) rb_raise(rb_eRangeError, "nonpositive value for log"); if (NIL_P(base)) { - oci_lc(OCINumberLn(errhp, &n, &r)); + chkerr(OCINumberLn(errhp, &n, &r)); } else { set_oci_number_from_num(&b, base, 1, errhp); - oci_lc(OCINumberSign(errhp, &b, &sign)); + chkerr(OCINumberSign(errhp, &b, &sign)); if (sign <= 0) rb_raise(rb_eRangeError, "nonpositive value for the base of log"); - oci_lc(OCINumberCmp(errhp, &b, &const_p1, &sign)); + chkerr(OCINumberCmp(errhp, &b, &const_p1, &sign)); if (sign == 0) rb_raise(rb_eRangeError, "base 1 for log"); - oci_lc(OCINumberLog(errhp, &b, &n, &r)); + chkerr(OCINumberLog(errhp, &b, &n, &r)); } return oci8_make_ocinumber(&r, errhp); } @@ -634,10 +634,10 @@ sword sign; set_oci_number_from_num(&n, num, 1, errhp); - oci_lc(OCINumberSign(errhp, &n, &sign)); + chkerr(OCINumberSign(errhp, &n, &sign)); if (sign <= 0) rb_raise(rb_eRangeError, "nonpositive value for log10"); - oci_lc(OCINumberLog(errhp, &const_p10, &n, &r)); + chkerr(OCINumberLog(errhp, &const_p10, &n, &r)); return oci8_make_ocinumber(&r, errhp); } @@ -656,12 +656,12 @@ set_oci_number_from_num(&n, num, 1, errhp); /* check whether num is negative */ - oci_lc(OCINumberSign(errhp, &n, &sign)); + chkerr(OCINumberSign(errhp, &n, &sign)); if (sign < 0) { errno = EDOM; rb_sys_fail("sqrt"); } - oci_lc(OCINumberSqrt(errhp, &n, &r)); + chkerr(OCINumberSqrt(errhp, &n, &r)); return oci8_make_ocinumber(&r, errhp); } @@ -702,7 +702,7 @@ rb_raise(rb_eTypeError, "invalid type: expected %s but %s", rb_class2name(CLASS_OF(lhs)), rb_class2name(CLASS_OF(rhs))); } - oci_lc(OCINumberAssign(oci8_errhp, _NUMBER(rhs), _NUMBER(lhs))); + chkerr(OCINumberAssign(oci8_errhp, _NUMBER(rhs), _NUMBER(lhs))); return lhs; } @@ -714,7 +714,7 @@ switch(rboci8_type(other)) { case T_FIXNUM: sl = NUM2LONG(other); - oci_lc(OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &n)); + chkerr(OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &n)); return rb_assoc_new(oci8_make_ocinumber(&n, oci8_errhp), self); case T_BIGNUM: /* change via string. */ @@ -743,7 +743,7 @@ OCIError *errhp = oci8_errhp; OCINumber r; - oci_lc(OCINumberNeg(errhp, _NUMBER(self), &r)); + chkerr(OCINumberNeg(errhp, _NUMBER(self), &r)); return oci8_make_ocinumber(&r, errhp); } @@ -764,12 +764,12 @@ case T_FIXNUM: case T_BIGNUM: if (set_oci_number_from_num(&n, rhs, 0, errhp)) { - oci_lc(OCINumberAdd(errhp, _NUMBER(lhs), &n, &r)); + chkerr(OCINumberAdd(errhp, _NUMBER(lhs), &n, &r)); return oci8_make_ocinumber(&r, errhp); } break; case RBOCI8_T_ORANUMBER: - oci_lc(OCINumberAdd(errhp, _NUMBER(lhs), _NUMBER(rhs), &r)); + chkerr(OCINumberAdd(errhp, _NUMBER(lhs), _NUMBER(rhs), &r)); return oci8_make_ocinumber(&r, errhp); case T_FLOAT: return rb_funcall(onum_to_f(lhs), oci8_id_add_op, 1, rhs); @@ -798,12 +798,12 @@ case T_FIXNUM: case T_BIGNUM: if (set_oci_number_from_num(&n, rhs, 0, errhp)) { - oci_lc(OCINumberSub(errhp, _NUMBER(lhs), &n, &r)); + chkerr(OCINumberSub(errhp, _NUMBER(lhs), &n, &r)); return oci8_make_ocinumber(&r, errhp); } break; case RBOCI8_T_ORANUMBER: - oci_lc(OCINumberSub(errhp, _NUMBER(lhs), _NUMBER(rhs), &r)); + chkerr(OCINumberSub(errhp, _NUMBER(lhs), _NUMBER(rhs), &r)); return oci8_make_ocinumber(&r, errhp); case T_FLOAT: return rb_funcall(onum_to_f(lhs), oci8_id_sub_op, 1, rhs); @@ -831,12 +831,12 @@ case T_FIXNUM: case T_BIGNUM: if (set_oci_number_from_num(&n, rhs, 0, errhp)) { - oci_lc(OCINumberMul(errhp, _NUMBER(lhs), &n, &r)); + chkerr(OCINumberMul(errhp, _NUMBER(lhs), &n, &r)); return oci8_make_ocinumber(&r, errhp); } break; case RBOCI8_T_ORANUMBER: - oci_lc(OCINumberMul(errhp, _NUMBER(lhs), _NUMBER(rhs), &r)); + chkerr(OCINumberMul(errhp, _NUMBER(lhs), _NUMBER(rhs), &r)); return oci8_make_ocinumber(&r, errhp); case T_FLOAT: return rb_funcall(onum_to_f(lhs), oci8_id_mul_op, 1, rhs); @@ -869,16 +869,16 @@ } case T_BIGNUM: if (set_oci_number_from_num(&n, rhs, 0, errhp)) { - oci_lc(OCINumberDiv(errhp, _NUMBER(lhs), &n, &r)); + chkerr(OCINumberDiv(errhp, _NUMBER(lhs), &n, &r)); return oci8_make_ocinumber(&r, errhp); } break; case RBOCI8_T_ORANUMBER: - oci_lc(OCINumberIsZero(errhp, _NUMBER(rhs), &is_zero)); + chkerr(OCINumberIsZero(errhp, _NUMBER(rhs), &is_zero)); if (is_zero) { rb_num_zerodiv(); } - oci_lc(OCINumberDiv(errhp, _NUMBER(lhs), _NUMBER(rhs), &r)); + chkerr(OCINumberDiv(errhp, _NUMBER(lhs), _NUMBER(rhs), &r)); return oci8_make_ocinumber(&r, errhp); case T_FLOAT: return rb_funcall(onum_to_f(lhs), oci8_id_div_op, 1, rhs); @@ -907,11 +907,11 @@ if (!set_oci_number_from_num(&n, rhs, 0, errhp)) return rb_num_coerce_bin(lhs, rhs, '%'); /* check whether argument is not zero. */ - oci_lc(OCINumberIsZero(errhp, &n, &is_zero)); + chkerr(OCINumberIsZero(errhp, &n, &is_zero)); if (is_zero) rb_num_zerodiv(); /* modulo */ - oci_lc(OCINumberMod(errhp, _NUMBER(lhs), &n, &r)); + chkerr(OCINumberMod(errhp, _NUMBER(lhs), &n, &r)); return oci8_make_ocinumber(&r, errhp); } @@ -928,12 +928,12 @@ OCINumber r; if (FIXNUM_P(rhs)) { - oci_lc(OCINumberIntPower(errhp, _NUMBER(lhs), FIX2INT(rhs), &r)); + chkerr(OCINumberIntPower(errhp, _NUMBER(lhs), FIX2INT(rhs), &r)); } else { /* change to OCINumber */ if (!set_oci_number_from_num(&n, rhs, 0, errhp)) return rb_num_coerce_bin(lhs, rhs, id_power); - oci_lc(OCINumberPower(errhp, _NUMBER(lhs), &n, &r)); + chkerr(OCINumberPower(errhp, _NUMBER(lhs), &n, &r)); } return oci8_make_ocinumber(&r, errhp); } @@ -956,7 +956,7 @@ if (!set_oci_number_from_num(&n, rhs, 0, errhp)) return rb_num_coerce_cmp(lhs, rhs, id_cmp); /* compare */ - oci_lc(OCINumberCmp(errhp, _NUMBER(lhs), &n, &r)); + chkerr(OCINumberCmp(errhp, _NUMBER(lhs), &n, &r)); if (r > 0) { return INT2FIX(1); } else if (r == 0) { @@ -977,7 +977,7 @@ OCIError *errhp = oci8_errhp; OCINumber r; - oci_lc(OCINumberFloor(errhp, _NUMBER(self), &r)); + chkerr(OCINumberFloor(errhp, _NUMBER(self), &r)); return oci8_make_integer(&r, errhp); } @@ -993,7 +993,7 @@ OCIError *errhp = oci8_errhp; OCINumber r; - oci_lc(OCINumberCeil(errhp, _NUMBER(self), &r)); + chkerr(OCINumberCeil(errhp, _NUMBER(self), &r)); return oci8_make_integer(&r, errhp); } @@ -1016,7 +1016,7 @@ OCINumber r; rb_scan_args(argc, argv, "01", &decplace /* 0 */); - oci_lc(OCINumberRound(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r)); + chkerr(OCINumberRound(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r)); if (argc == 0) { return oci8_make_integer(&r, errhp); } else { @@ -1039,7 +1039,7 @@ OCINumber r; rb_scan_args(argc, argv, "01", &decplace /* 0 */); - oci_lc(OCINumberTrunc(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r)); + chkerr(OCINumberTrunc(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r)); return oci8_make_ocinumber(&r, errhp); } @@ -1059,7 +1059,7 @@ OCIError *errhp = oci8_errhp; OCINumber r; - oci_lc(OCINumberPrec(errhp, _NUMBER(self), NUM2INT(ndigs), &r)); + chkerr(OCINumberPrec(errhp, _NUMBER(self), NUM2INT(ndigs), &r)); return oci8_make_ocinumber(&r, errhp); } @@ -1115,7 +1115,7 @@ if (NIL_P(fmt)) /* implicit conversion */ return rb_usascii_str_new_cstr("overflow"); } - oci8_raise(errhp, rv, NULL); + chkerr(rv); } return rb_usascii_str_new(buf, buf_size); } @@ -1142,7 +1142,7 @@ OCIError *errhp = oci8_errhp; OCINumber num; - oci_lc(OCINumberTrunc(errhp, _NUMBER(self), 0, &num)); + chkerr(OCINumberTrunc(errhp, _NUMBER(self), 0, &num)); return oci8_make_integer(&num, errhp); } @@ -1173,15 +1173,15 @@ int current = 0; boolean is_int; - oci_lc(OCINumberAssign(oci8_errhp, _NUMBER(self), &onum[0])); + chkerr(OCINumberAssign(oci8_errhp, _NUMBER(self), &onum[0])); for (;;) { - oci_lc(OCINumberIsInt(oci8_errhp, &onum[current], &is_int)); + chkerr(OCINumberIsInt(oci8_errhp, &onum[current], &is_int)); if (is_int) { break; } nshift++; - oci_lc(OCINumberShift(oci8_errhp, &onum[current], 1, &onum[1 - current])); + chkerr(OCINumberShift(oci8_errhp, &onum[current], 1, &onum[1 - current])); current = 1 - current; } x = oci8_make_integer(&onum[current], oci8_errhp); @@ -1224,7 +1224,7 @@ rb_require("bigdecimal"); cBigDecimal = rb_const_get(rb_cObject, id_BigDecimal); } - oci_lc(OCINumberToText(errhp, num, (const oratext *)fmt, strlen(fmt), + chkerr(OCINumberToText(errhp, num, (const oratext *)fmt, strlen(fmt), NULL, 0, &buf_size, TO_ORATEXT(buf))); return rb_funcall(rb_cObject, id_BigDecimal, 1, rb_usascii_str_new(buf, buf_size)); } @@ -1243,7 +1243,7 @@ OCIError *errhp = oci8_errhp; boolean result; - oci_lc(OCINumberIsInt(errhp, _NUMBER(self), &result)); + chkerr(OCINumberIsInt(errhp, _NUMBER(self), &result)); return result ? Qfalse : Qtrue; } @@ -1271,7 +1271,7 @@ OCIError *errhp = oci8_errhp; boolean result; - oci_lc(OCINumberIsZero(errhp, _NUMBER(self), &result)); + chkerr(OCINumberIsZero(errhp, _NUMBER(self), &result)); return result ? Qtrue : Qfalse; } @@ -1287,7 +1287,7 @@ OCIError *errhp = oci8_errhp; OCINumber result; - oci_lc(OCINumberAbs(errhp, _NUMBER(self), &result)); + chkerr(OCINumberAbs(errhp, _NUMBER(self), &result)); return oci8_make_ocinumber(&result, errhp); } @@ -1303,7 +1303,7 @@ OCIError *errhp = oci8_errhp; OCINumber result; - oci_lc(OCINumberShift(errhp, _NUMBER(self), NUM2INT(exp), &result)); + chkerr(OCINumberShift(errhp, _NUMBER(self), NUM2INT(exp), &result)); return oci8_make_ocinumber(&result, errhp); } @@ -1423,7 +1423,8 @@ OCINumber num; set_oci_number_from_num(&num, val, 1, errhp); - oci_lc(OCINumberTrunc(errhp, &num, 0, (OCINumber*)data)); + chker2(OCINumberTrunc(errhp, &num, 0, (OCINumber*)data), + &obind->base); } static void bind_ocinumber_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length) Modified: trunk/ruby-oci8/ext/oci8/stmt.c =================================================================== --- trunk/ruby-oci8/ext/oci8/stmt.c 2011-10-22 11:21:44 UTC (rev 458) +++ trunk/ruby-oci8/ext/oci8/stmt.c 2011-10-22 13:32:49 UTC (rev 459) @@ -87,7 +87,7 @@ if (argc > 1) { rv = OCIStmtPrepare(stmt->base.hp.stmt, oci8_errhp, RSTRING_ORATEXT(sql), RSTRING_LEN(sql), OCI_NTV_SYNTAX, OCI_DEFAULT); if (IS_OCI_ERROR(rv)) { - oci8_raise(oci8_errhp, rv, stmt->base.hp.stmt); + chker3(rv, &stmt->base, stmt->base.hp.stmt); } } oci8_link_to_parent((oci8_base_t*)stmt, (oci8_base_t*)DATA_PTR(svc)); @@ -110,7 +110,7 @@ vptr = (const oci8_bind_vtable_t *)obind->base.vptr; status = OCIDefineByPos(stmt->base.hp.stmt, &obind->base.hp.dfn, oci8_errhp, position, obind->valuep, obind->value_sz, vptr->dty, NIL_P(obind->tdo) ? obind->u.inds : NULL, NULL, 0, OCI_DEFAULT); if (status != OCI_SUCCESS) { - oci8_raise(oci8_errhp, status, stmt->base.hp.ptr); + chker3(status, &stmt->base, stmt->base.hp.ptr); } obind->base.type = OCI_HTYPE_DEFINE; /* link to the parent as soon as possible to preserve deallocation order. */ @@ -118,7 +118,7 @@ oci8_link_to_parent((oci8_base_t*)obind, (oci8_base_t*)stmt); if (NIL_P(obind->tdo) && obind->maxar_sz > 0) { - oci_lc(OCIDefineArrayOfStruct(obind->base.hp.dfn, oci8_errhp, obind->alloc_sz, sizeof(sb2), 0, 0)); + chker2(OCIDefineArrayOfStruct(obind->base.hp.dfn, oci8_errhp, obind->alloc_sz, sizeof(sb2), 0, 0), &stmt->base); } if (vptr->post_bind_hook != NULL) { vptr->post_bind_hook(obind); @@ -181,7 +181,7 @@ status = OCIBindByName(stmt->base.hp.stmt, &obind->base.hp.bnd, oci8_errhp, TO_ORATEXT(placeholder_ptr), placeholder_len, obind->valuep, obind->value_sz, vptr->dty, indp, NULL, 0, 0, 0, OCI_DEFAULT); } if (status != OCI_SUCCESS) { - oci8_raise(oci8_errhp, status, stmt->base.hp.stmt); + chker3(status, &stmt->base, stmt->base.hp.stmt); } obind->base.type = OCI_HTYPE_BIND; /* link to the parent as soon as possible to preserve deallocation order. */ @@ -189,7 +189,8 @@ oci8_link_to_parent((oci8_base_t*)obind, (oci8_base_t*)stmt); if (NIL_P(obind->tdo) && obind->maxar_sz > 0) { - oci_lc(OCIBindArrayOfStruct(obind->base.hp.bnd, oci8_errhp, obind->alloc_sz, sizeof(sb2), 0, 0)); + chker2(OCIBindArrayOfStruct(obind->base.hp.bnd, oci8_errhp, obind->alloc_sz, sizeof(sb2), 0, 0), + &stmt->base); } if (vptr->post_bind_hook != NULL) { vptr->post_bind_hook(obind); @@ -225,9 +226,8 @@ oci8_svcctx_t *svcctx = oci8_get_svcctx(stmt->svc); ub4 iters; ub4 mode; - sword rv; - if (oci8_get_ub2_attr(&stmt->base, OCI_ATTR_STMT_TYPE) == INT2FIX(OCI_STMT_SELECT)) { + if (oci8_get_ub2_attr(&stmt->base, OCI_ATTR_STMT_TYPE, stmt->base.hp.stmt) == INT2FIX(OCI_STMT_SELECT)) { iters = 0; mode = OCI_DEFAULT; } else { @@ -237,10 +237,8 @@ iters = 1; mode = svcctx->is_autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT; } - rv = oci8_call_stmt_execute(svcctx, stmt, iters, mode); - if (IS_OCI_ERROR(rv)) { - oci8_raise(oci8_errhp, rv, stmt->base.hp.stmt); - } + chker3(oci8_call_stmt_execute(svcctx, stmt, iters, mode), + &stmt->base, stmt->base.hp.stmt); return self; } @@ -294,9 +292,7 @@ if (rv == OCI_NO_DATA) { return Qnil; } - if (IS_OCI_ERROR(rv)) { - oci8_raise(oci8_errhp, rv, stmt->base.hp.stmt); - } + chker3(rv, &svcctx->base, stmt->base.hp.stmt); ary = rb_ary_new2(RARRAY_LEN(stmt->defns)); for (idx = 0; idx < RARRAY_LEN(stmt->defns); idx++) { rb_ary_store(ary, idx, oci8_bind_get_data(RARRAY_PTR(stmt->defns)[idx])); @@ -343,7 +339,7 @@ Check_Type(pos, T_FIXNUM); /* 1 */ rv = OCIParamGet(stmt->base.hp.stmt, OCI_HTYPE_STMT, oci8_errhp, (dvoid *)&parmhp, FIX2INT(pos)); if (rv != OCI_SUCCESS) { - oci8_raise(oci8_errhp, rv, NULL); + chker3(rv, &stmt->base, stmt->base.hp.stmt); } return oci8_metadata_create(parmhp, stmt->svc, self); } @@ -368,7 +364,8 @@ */ static VALUE oci8_stmt_get_stmt_type(VALUE self) { - VALUE stmt_type = oci8_get_ub2_attr(oci8_get_handle(self, cOCIStmt), OCI_ATTR_STMT_TYPE); + oci8_base_t *base = oci8_get_handle(self, cOCIStmt); + VALUE stmt_type = oci8_get_ub2_attr(base, OCI_ATTR_STMT_TYPE, base->hp.stmt); switch (FIX2INT(stmt_type)) { case OCI_STMT_SELECT: return oci8_sym_select_stmt; @@ -398,7 +395,8 @@ */ static VALUE oci8_stmt_get_row_count(VALUE self) { - return oci8_get_ub4_attr(oci8_get_handle(self, cOCIStmt), OCI_ATTR_ROW_COUNT); + oci8_base_t *base = oci8_get_handle(self, cOCIStmt); + return oci8_get_ub4_attr(base, OCI_ATTR_ROW_COUNT, base->hp.stmt); } /* @@ -417,12 +415,14 @@ */ static VALUE oci8_stmt_get_rowid(VALUE self) { - return oci8_get_rowid_attr(oci8_get_handle(self, cOCIStmt), OCI_ATTR_ROWID); + oci8_base_t *base = oci8_get_handle(self, cOCIStmt); + return oci8_get_rowid_attr(base, OCI_ATTR_ROWID, base->hp.stmt); } static VALUE oci8_stmt_get_param_count(VALUE self) { - return oci8_get_ub4_attr(oci8_get_handle(self, cOCIStmt), OCI_ATTR_PARAM_COUNT); + oci8_base_t *base = oci8_get_handle(self, cOCIStmt); + return oci8_get_ub4_attr(base, OCI_ATTR_PARAM_COUNT, base->hp.stmt); } /* @@ -566,7 +566,8 @@ oci8_stmt_t *stmt = TO_STMT(self); ub4 num = NUM2UINT(rows); - oci_lc(OCIAttrSet(stmt->base.hp.ptr, OCI_HTYPE_STMT, &num, 0, OCI_ATTR_PREFETCH_ROWS, oci8_errhp)); + chker2(OCIAttrSet(stmt->base.hp.ptr, OCI_HTYPE_STMT, &num, 0, OCI_ATTR_PREFETCH_ROWS, oci8_errhp), + &stmt->base); return Qfalse; } From nobody at rubyforge.org Sat Oct 29 07:57:00 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 29 Oct 2011 07:57:00 -0400 (EDT) Subject: [ruby-oci8-commit] [460] trunk/ruby-oci8: use RbConfig::CONFIG instead of obsolete Config:: CONFIG. Message-ID: <20111029115700.E31CD185837B@rubyforge.org> Revision: 460 Author: kubo Date: 2011-10-29 07:57:00 -0400 (Sat, 29 Oct 2011) Log Message: ----------- use RbConfig::CONFIG instead of obsolete Config::CONFIG. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/oraconf.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-10-22 13:32:49 UTC (rev 459) +++ trunk/ruby-oci8/ChangeLog 2011-10-29 11:57:00 UTC (rev 460) @@ -1,3 +1,7 @@ +2011-10-29 KUBO Takehiro + * ext/oci8/oraconf.rb: use RbConfig::CONFIG instead of obsolete + Config::CONFIG. + 2011-10-22 KUBO Takehiro * ext/oci8/attr.c, ext/oci8/bind.c, ext/oci8/connection_pool.c, ext/oci8/error.c, ext/oci8/lob.c, ext/oci8/metadata.c, Modified: trunk/ruby-oci8/ext/oci8/oraconf.rb =================================================================== --- trunk/ruby-oci8/ext/oci8/oraconf.rb 2011-10-22 13:32:49 UTC (rev 459) +++ trunk/ruby-oci8/ext/oci8/oraconf.rb 2011-10-29 11:57:00 UTC (rev 460) @@ -1,36 +1,8 @@ require 'mkmf' -unless defined? macro_defined? - # ruby 1.6 doesn't have 'macro_defined?'. - def macro_defined?(macro, src, opt="") - try_cpp(src + <<"SRC", opt) -#ifndef #{macro} -# error -#endif -SRC - end -end +# compatibility for ruby-1.9 +RbConfig = Config unless defined? RbConfig -module Logging - unless Logging.respond_to?(:open) - # emulate Logging::open of ruby 1.6.8 or later. - - if $log.nil? # ruby 1.6.2 doesn't have $log. - $log = open('mkmf.log', 'w') - end - def Logging::open - begin - $stderr.reopen($log) - $stdout.reopen($log) - yield - ensure - $stderr.reopen($orgerr) - $stdout.reopen($orgout) - end - end - end -end # module Logging - module MiniRegistry class MiniRegistryError < StandardError attr_reader :api_name @@ -635,20 +607,20 @@ def check_ruby_header print "checking for ruby header... " STDOUT.flush - rubyhdrdir = Config::CONFIG["rubyhdrdir"] || Config::CONFIG['archdir'] + rubyhdrdir = RbConfig::CONFIG["rubyhdrdir"] || RbConfig::CONFIG['archdir'] unless File.exist?(rubyhdrdir + '/ruby.h') puts "ng" - if RUBY_PLATFORM =~ /darwin/ and File.exist?("#{Config::CONFIG['archdir']}/../universal-darwin8.0/ruby.h") + if RUBY_PLATFORM =~ /darwin/ and File.exist?("#{RbConfig::CONFIG['archdir']}/../universal-darwin8.0/ruby.h") raise < Revision: 461 Author: kubo Date: 2011-10-29 08:37:04 -0400 (Sat, 29 Oct 2011) Log Message: ----------- reset OCI8#last_error when OCI8#parse or OCI8#exec is called. fix bugs added by the last commit but one. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/error.c trunk/ruby-oci8/ext/oci8/oci8.c trunk/ruby-oci8/lib/oci8/object.rb trunk/ruby-oci8/lib/oci8/oci8.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-10-29 11:57:00 UTC (rev 460) +++ trunk/ruby-oci8/ChangeLog 2011-10-29 12:37:04 UTC (rev 461) @@ -1,4 +1,9 @@ 2011-10-29 KUBO Takehiro + * ext/oci8/error.c, ext/oci8/oci8.c, lib/oci8/object.rb, lib/oci8/oci8.rb: + reset OCI8#last_error when OCI8#parse or OCI8#exec is called. + fix bugs added by the last commit but one. + +2011-10-29 KUBO Takehiro * ext/oci8/oraconf.rb: use RbConfig::CONFIG instead of obsolete Config::CONFIG. Modified: trunk/ruby-oci8/ext/oci8/error.c =================================================================== --- trunk/ruby-oci8/ext/oci8/error.c 2011-10-29 11:57:00 UTC (rev 460) +++ trunk/ruby-oci8/ext/oci8/error.c 2011-10-29 12:37:04 UTC (rev 461) @@ -276,7 +276,7 @@ VALUE exc = oci8_make_exc(oci8_errhp, status, OCI_HTYPE_ERROR, stmthp, file, line); while (base != NULL) { if (base->type == OCI_HTYPE_SVCCTX) { - rb_ivar_set(exc, oci8_id_at_last_error, exc); + rb_ivar_set(base->self, oci8_id_at_last_error, exc); break; } base = base->parent; Modified: trunk/ruby-oci8/ext/oci8/oci8.c =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8.c 2011-10-29 11:57:00 UTC (rev 460) +++ trunk/ruby-oci8/ext/oci8/oci8.c 2011-10-29 12:37:04 UTC (rev 461) @@ -96,6 +96,7 @@ #endif } } + svcctx->base.type = 0; } static void oci8_svcctx_init(oci8_base_t *base) @@ -358,13 +359,13 @@ } /* logon */ + svcctx->base.type = OCI_HTYPE_SVCCTX; chker2(OCILogon_nb(svcctx, oci8_envhp, oci8_errhp, &svcctx->base.hp.svc, RSTRING_ORATEXT(username), RSTRING_LEN(username), RSTRING_ORATEXT(password), RSTRING_LEN(password), NIL_P(dbname) ? NULL : RSTRING_ORATEXT(dbname), NIL_P(dbname) ? 0 : RSTRING_LEN(dbname)), &svcctx->base); - svcctx->base.type = OCI_HTYPE_SVCCTX; svcctx->logoff_strategy = &simple_logoff; /* setup the session handle */ @@ -547,22 +548,6 @@ /* * call-seq: - * parse(sql_text) -> an instance of OCI8::Cursor - * - * Prepares the SQL statement and returns a new OCI8::Cursor. - */ -static VALUE oci8_svcctx_parse(VALUE self, VALUE sql) -{ - VALUE obj = rb_funcall(cOCIStmt, oci8_id_new, 2, self, sql); - VALUE prefetch_rows = rb_ivar_get(self, id_at_prefetch_rows); - if (!NIL_P(prefetch_rows)) { - rb_funcall(obj, id_set_prefetch_rows, 1, prefetch_rows); - } - return obj; -} - -/* - * call-seq: * commit * * Commits the transaction. @@ -1125,7 +1110,6 @@ rb_define_private_method(cOCI8, "server_attach", oci8_server_attach, 2); rb_define_private_method(cOCI8, "session_begin", oci8_session_begin, 2); rb_define_method(cOCI8, "logoff", oci8_svcctx_logoff, 0); - rb_define_method(cOCI8, "parse", oci8_svcctx_parse, 1); rb_define_method(cOCI8, "commit", oci8_commit, 0); rb_define_method(cOCI8, "rollback", oci8_rollback, 0); rb_define_method(cOCI8, "non_blocking?", oci8_non_blocking_p, 0); Modified: trunk/ruby-oci8/lib/oci8/object.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/object.rb 2011-10-29 11:57:00 UTC (rev 460) +++ trunk/ruby-oci8/lib/oci8/object.rb 2011-10-29 12:37:04 UTC (rev 461) @@ -147,7 +147,7 @@ :self := #{tdo.typename}(#{bind_arg_helper.arg_str}); END; EOS - csr = @con.parse(sql) + csr = @con.parse_internal(sql) begin csr.bind_param(:self, nil, :named_type_internal, tdo) bind_arg_helper.exec(@con, csr) @@ -174,7 +174,7 @@ #{tdo.typename}.#{method_id}(#{bind_arg_helper.arg_str}); END; EOS - csr = con.parse(sql) + csr = con.parse_internal(sql) begin bind_arg_helper.exec(con, csr) ensure @@ -190,7 +190,7 @@ :rv := #{tdo.typename}.#{method_id}(#{bind_arg_helper.arg_str}); END; EOS - csr = con.parse(sql) + csr = con.parse_internal(sql) begin csr.bind_param(:rv, nil, return_type) bind_arg_helper.exec(con, csr) @@ -243,7 +243,7 @@ :self := val; END; EOS - csr = @con.parse(sql) + csr = @con.parse_internal(sql) begin csr.bind_param(:self, nil, :named_type_internal, tdo) csr[:self].attributes = self @@ -264,7 +264,7 @@ :self := val; END; EOS - csr = @con.parse(sql) + csr = @con.parse_internal(sql) begin csr.bind_param(:self, nil, :named_type_internal, tdo) csr.bind_param(:rv, nil, return_type) @@ -376,7 +376,7 @@ result_type = nil if type_method.has_result? # function - con.exec("select result_type_owner, result_type_name from all_method_results where OWNER = :1 and TYPE_NAME = :2 and METHOD_NO = :3", metadata.schema_name, metadata.name, i + 1) do |r| + con.exec_internal("select result_type_owner, result_type_name from all_method_results where OWNER = :1 and TYPE_NAME = :2 and METHOD_NO = :3", metadata.schema_name, metadata.name, i + 1) do |r| if r[0].nil? result_type = @@result_type_to_bindtype[r[1]] else Modified: trunk/ruby-oci8/lib/oci8/oci8.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/oci8.rb 2011-10-29 11:57:00 UTC (rev 460) +++ trunk/ruby-oci8/lib/oci8/oci8.rb 2011-10-29 12:37:04 UTC (rev 461) @@ -137,6 +137,22 @@ @username = nil end + # call-seq: + # parse(sql_text) -> an OCI8::Cursor + # + # Returns a prepared SQL handle. + def parse(sql) + @last_error = nil + parse_internal(sql) + end + + # same with OCI8#parse except that this doesn't reset OCI8#last_error. + def parse_internal(sql) + cursor = OCI8::Cursor.new(self, sql) + cursor.prefetch_rows = @prefetch_rows if @prefetch_rows + cursor + end + # Executes the sql statement. The type of return value depends on # the type of sql statement: select; insert, update and delete; # create, alter and drop; and PL/SQL. @@ -222,7 +238,13 @@ # conn.exec('CREATE TABLE test (col1 CHAR(6))') # => 0 # conn.logoff # - def exec(sql, *bindvars) + def exec(sql, *bindvars, &block) + @last_error = nil + exec_internal(sql, *bindvars, &block) + end + + # same with OCI8#exec except that this doesn't reset OCI8#last_error. + def exec_internal(sql, *bindvars) begin cursor = parse(sql) ret = cursor.exec(*bindvars)