From nobody at rubyforge.org Sat Apr 4 03:32:50 2009 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 4 Apr 2009 03:32:50 -0400 (EDT) Subject: [ruby-oci8-commit] [331] trunk/ruby-oci8: * ext/oci8/bind.c: fix an error when executing " select NULL from dual". Message-ID: <20090404073250.917AE18580EA@rubyforge.org> Revision: 331 Author: kubo Date: 2009-04-04 03:32:50 -0400 (Sat, 04 Apr 2009) Log Message: ----------- * ext/oci8/bind.c: fix an error when executing "select NULL from dual". http://rubyforge.org/forum/forum.php?thread_id=32468&forum_id=1078 (contributed by Raimonds Simanovskis) Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/bind.c Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2009-03-24 15:08:37 UTC (rev 330) +++ trunk/ruby-oci8/ChangeLog 2009-04-04 07:32:50 UTC (rev 331) @@ -1,3 +1,8 @@ +2009-04-04 KUBO Takehiro + * ext/oci8/bind.c: fix an error when executing "select NULL from dual". + http://rubyforge.org/forum/forum.php?thread_id=32468&forum_id=1078 + (contributed by Raimonds Simanovskis) + 2009-03-24 KUBO Takehiro * ext/oci8/extconf.rb, ext/oci8/oci8.h, ext/oci8/oraconf.rb: fix a problem when compiling with Oracle 8.0. Modified: trunk/ruby-oci8/ext/oci8/bind.c =================================================================== --- trunk/ruby-oci8/ext/oci8/bind.c 2009-03-24 15:08:37 UTC (rev 330) +++ trunk/ruby-oci8/ext/oci8/bind.c 2009-04-04 07:32:50 UTC (rev 331) @@ -46,7 +46,7 @@ } else { sz = NUM2INT(length); } - if (sz <= 0) { + if (sz < 0) { rb_raise(rb_eArgError, "invalid bind length %d", sz); } sz += sizeof(sb4); From nobody at rubyforge.org Sat Apr 11 22:36:40 2009 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 11 Apr 2009 22:36:40 -0400 (EDT) Subject: [ruby-oci8-commit] [332] branches/ruby-oci8-1.0: * ext/oci8/extconf.rb, ext/oci8/oci8.h, ext/ oci8/oraconf.rb: Message-ID: <20090412023640.7111C18581DF@rubyforge.org> Revision: 332 Author: kubo Date: 2009-04-11 22:36:39 -0400 (Sat, 11 Apr 2009) Log Message: ----------- * ext/oci8/extconf.rb, ext/oci8/oci8.h, ext/oci8/oraconf.rb: fix a problem when compiling for Oracle 8.0. (reported by Axel Reinhold as a ruby-oci8 2.0 issue) * lib/dbd/OCI8.rb: fix DBI::DBD::OCI8::BindType::DBIStatementHandle to pass a newly added sanity check in dbi 0.4.1. (reported by Dirk Herzhauser as a ruby-oci8 2.0 issue) * test/test_all.rb: fix to use dbi installed as a rubygem. Modified Paths: -------------- branches/ruby-oci8-1.0/ChangeLog branches/ruby-oci8-1.0/ext/oci8/extconf.rb branches/ruby-oci8-1.0/ext/oci8/oci8.h branches/ruby-oci8-1.0/ext/oci8/oraconf.rb branches/ruby-oci8-1.0/lib/dbd/OCI8.rb branches/ruby-oci8-1.0/test/test_all.rb Modified: branches/ruby-oci8-1.0/ChangeLog =================================================================== --- branches/ruby-oci8-1.0/ChangeLog 2009-04-04 07:32:50 UTC (rev 331) +++ branches/ruby-oci8-1.0/ChangeLog 2009-04-12 02:36:39 UTC (rev 332) @@ -1,3 +1,12 @@ +2009-04-12 KUBO Takehiro + * ext/oci8/extconf.rb, ext/oci8/oci8.h, ext/oci8/oraconf.rb: + fix a problem when compiling for Oracle 8.0. + (reported by Axel Reinhold as a ruby-oci8 2.0 issue) + * lib/dbd/OCI8.rb: fix DBI::DBD::OCI8::BindType::DBIStatementHandle + to pass a newly added sanity check in dbi 0.4.1. + (reported by Dirk Herzhauser as a ruby-oci8 2.0 issue) + * test/test_all.rb: fix to use dbi installed as a rubygem. + 2009-03-17 KUBO Takehiro * NEWS: add changes between 1.0.4 and 1.0.5. * VERSION: change version to 1.0.5. Modified: branches/ruby-oci8-1.0/ext/oci8/extconf.rb =================================================================== --- branches/ruby-oci8-1.0/ext/oci8/extconf.rb 2009-04-04 07:32:50 UTC (rev 331) +++ branches/ruby-oci8-1.0/ext/oci8/extconf.rb 2009-04-12 02:36:39 UTC (rev 332) @@ -44,6 +44,8 @@ $CFLAGS += oraconf.cflags $libs += oraconf.libs +have_type('oratext', 'ociap.h') + # OCIEnvCreate # 8.0.5 - NG # 9.0.1 - OK Modified: branches/ruby-oci8-1.0/ext/oci8/oci8.h =================================================================== --- branches/ruby-oci8-1.0/ext/oci8/oci8.h 2009-04-04 07:32:50 UTC (rev 331) +++ branches/ruby-oci8-1.0/ext/oci8/oci8.h 2009-04-12 02:36:39 UTC (rev 332) @@ -52,6 +52,10 @@ #define RARRAY_LEN(obj) RARRAY(obj)->len #endif +#ifndef HAVE_TYPE_ORATEXT +typedef unsigned char oratext; +#endif + #define IS_OCI_ERROR(v) (((v) != OCI_SUCCESS) && ((v) != OCI_SUCCESS_WITH_INFO)) #if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) Modified: branches/ruby-oci8-1.0/ext/oci8/oraconf.rb =================================================================== --- branches/ruby-oci8-1.0/ext/oci8/oraconf.rb 2009-04-04 07:32:50 UTC (rev 331) +++ branches/ruby-oci8-1.0/ext/oci8/oraconf.rb 2009-04-12 02:36:39 UTC (rev 332) @@ -944,21 +944,18 @@ end end - # remove object files from libs. - objs = [] - libs.gsub!(/\S+\.o\b/) do |obj| - objs << obj - "" - end - # change object files to an archive file to work around. - if objs.length > 0 - Logging::open do - puts "change object files to an archive file." - command = Config::CONFIG["AR"] + " cru oracle_objs.a " + objs.join(" ") - puts command - system(command) - libs = "oracle_objs.a " + libs + # check whether object files are included. + if /\S+\.o\b/ =~ libs + + # monkey patching! + Object.module_eval do + alias :orig_link_command :link_command + def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH) + opt = "" if opt == $libs + orig_link_command(ldflags, opt, libpath) + end end + end libs end # get_libs Modified: branches/ruby-oci8-1.0/lib/dbd/OCI8.rb =================================================================== --- branches/ruby-oci8-1.0/lib/dbd/OCI8.rb 2009-04-04 07:32:50 UTC (rev 331) +++ branches/ruby-oci8-1.0/lib/dbd/OCI8.rb 2009-04-12 02:36:39 UTC (rev 332) @@ -401,6 +401,21 @@ end end +# DBI_STMT_NEW_ARGS is DBI::StatementHandle.new's arguments except +handle+. +# +# FYI: DBI::StatementHandle.new method signatures are follows: +# 0.2.2: handle, fetchable=false, prepared=true +# 0.4.0: handle, fetchable=false, prepared=true, convert_types=true +# 0.4.1: handle, fetchable=false, prepared=true, convert_types=true, executed=false +begin + DBI::StatementHandle.new(nil, false, true, true, true) + # dbi 0.4.1 + DBI_STMT_NEW_ARGS = [true, true, true, true] # :nodoc: +rescue ArgumentError + # dbi 0.4.0 or lower + DBI_STMT_NEW_ARGS = [true] # :nodoc: +end + if defined? ::OCI8::BindType::Base ## ## ruby-oci8 2.0 bind classes. @@ -490,7 +505,7 @@ val = super return nil if val.nil? stmt = DBI::DBD::OCI8::Statement.new(val) - DBI::StatementHandle.new(stmt, true, false) + DBI::StatementHandle.new(stmt, *DBI_STMT_NEW_ARGS) end end end # BindType @@ -559,7 +574,7 @@ return val if val.nil? cur = ::OCI8::Cursor.new(@env, @svc, @ctx, val) stmt = DBI::DBD::OCI8::Statement.new(cur) - DBI::StatementHandle.new(stmt, true, false) + DBI::StatementHandle.new(stmt, *DBI_STMT_NEW_ARGS) end end end Modified: branches/ruby-oci8-1.0/test/test_all.rb =================================================================== --- branches/ruby-oci8-1.0/test/test_all.rb 2009-04-04 07:32:50 UTC (rev 331) +++ branches/ruby-oci8-1.0/test/test_all.rb 2009-04-12 02:36:39 UTC (rev 332) @@ -23,11 +23,15 @@ # Ruby/DBI begin require 'dbi' - is_dbi_loaded = true rescue LoadError - is_dbi_loaded = false + begin + require 'rubygems' + require 'dbi' + rescue LoadError + dbi_not_found = false + end end -if is_dbi_loaded +unless dbi_not_found require "#{srcdir}/test_dbi" if $test_clob require "#{srcdir}/test_dbi_clob" From nobody at rubyforge.org Sat Apr 11 22:51:50 2009 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 11 Apr 2009 22:51:50 -0400 (EDT) Subject: [ruby-oci8-commit] [333] trunk/ruby-oci8: * lib/dbd/OCI8.rb: fix DBI::DBD::OCI8::BindType:: DBIStatementHandle Message-ID: <20090412025150.3D0B418580E4@rubyforge.org> Revision: 333 Author: kubo Date: 2009-04-11 22:51:49 -0400 (Sat, 11 Apr 2009) Log Message: ----------- * lib/dbd/OCI8.rb: fix DBI::DBD::OCI8::BindType::DBIStatementHandle to pass a newly added sanity check in dbi 0.4.1. (reported by Dirk Herzhauser) * test/test_all.rb: fix to use dbi installed as a rubygem. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/lib/dbd/OCI8.rb trunk/ruby-oci8/test/test_all.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2009-04-12 02:36:39 UTC (rev 332) +++ trunk/ruby-oci8/ChangeLog 2009-04-12 02:51:49 UTC (rev 333) @@ -1,3 +1,9 @@ +2009-04-12 KUBO Takehiro + * lib/dbd/OCI8.rb: fix DBI::DBD::OCI8::BindType::DBIStatementHandle + to pass a newly added sanity check in dbi 0.4.1. + (reported by Dirk Herzhauser) + * test/test_all.rb: fix to use dbi installed as a rubygem. + 2009-04-04 KUBO Takehiro * ext/oci8/bind.c: fix an error when executing "select NULL from dual". http://rubyforge.org/forum/forum.php?thread_id=32468&forum_id=1078 Modified: trunk/ruby-oci8/lib/dbd/OCI8.rb =================================================================== --- trunk/ruby-oci8/lib/dbd/OCI8.rb 2009-04-12 02:36:39 UTC (rev 332) +++ trunk/ruby-oci8/lib/dbd/OCI8.rb 2009-04-12 02:51:49 UTC (rev 333) @@ -402,6 +402,21 @@ end end +# DBI_STMT_NEW_ARGS is DBI::StatementHandle.new's arguments except +handle+. +# +# FYI: DBI::StatementHandle.new method signatures are follows: +# 0.2.2: handle, fetchable=false, prepared=true +# 0.4.0: handle, fetchable=false, prepared=true, convert_types=true +# 0.4.1: handle, fetchable=false, prepared=true, convert_types=true, executed=false +begin + DBI::StatementHandle.new(nil, false, true, true, true) + # dbi 0.4.1 + DBI_STMT_NEW_ARGS = [true, true, true, true] # :nodoc: +rescue ArgumentError + # dbi 0.4.0 or lower + DBI_STMT_NEW_ARGS = [true] # :nodoc: +end + if defined? ::OCI8::BindType::Base ## ## ruby-oci8 2.0 bind classes. @@ -491,7 +506,7 @@ val = super return nil if val.nil? stmt = DBI::DBD::OCI8::Statement.new(val) - DBI::StatementHandle.new(stmt, true, false) + DBI::StatementHandle.new(stmt, *DBI_STMT_NEW_ARGS) end end end # BindType @@ -560,7 +575,7 @@ return val if val.nil? cur = ::OCI8::Cursor.new(@env, @svc, @ctx, val) stmt = DBI::DBD::OCI8::Statement.new(cur) - DBI::StatementHandle.new(stmt, true, false) + DBI::StatementHandle.new(stmt, *DBI_STMT_NEW_ARGS) end end end Modified: trunk/ruby-oci8/test/test_all.rb =================================================================== --- trunk/ruby-oci8/test/test_all.rb 2009-04-12 02:36:39 UTC (rev 332) +++ trunk/ruby-oci8/test/test_all.rb 2009-04-12 02:51:49 UTC (rev 333) @@ -24,11 +24,15 @@ # Ruby/DBI begin require 'dbi' - is_dbi_loaded = true rescue LoadError - is_dbi_loaded = false + begin + require 'rubygems' + require 'dbi' + rescue LoadError + dbi_not_found = false + end end -if is_dbi_loaded +unless dbi_not_found require "#{srcdir}/test_dbi" if $test_clob require "#{srcdir}/test_dbi_clob" From nobody at rubyforge.org Sat Apr 11 22:59:35 2009 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 11 Apr 2009 22:59:35 -0400 (EDT) Subject: [ruby-oci8-commit] [334] branches/ruby-oci8-1.0: * lib/dbd/OCI8.rb: A data dictionary all_constraints doesn't have Message-ID: <20090412025935.1D18818580E4@rubyforge.org> Revision: 334 Author: kubo Date: 2009-04-11 22:59:34 -0400 (Sat, 11 Apr 2009) Log Message: ----------- * lib/dbd/OCI8.rb: A data dictionary all_constraints doesn't have index_name column on Oracle 8i or lower. Rewrite DBI::DBD::OCI8::Database#column by using all_cons_columns. (backport from ruby-oci8 trunk) Modified Paths: -------------- branches/ruby-oci8-1.0/ChangeLog branches/ruby-oci8-1.0/lib/dbd/OCI8.rb Modified: branches/ruby-oci8-1.0/ChangeLog =================================================================== --- branches/ruby-oci8-1.0/ChangeLog 2009-04-12 02:51:49 UTC (rev 333) +++ branches/ruby-oci8-1.0/ChangeLog 2009-04-12 02:59:34 UTC (rev 334) @@ -1,4 +1,10 @@ 2009-04-12 KUBO Takehiro + * lib/dbd/OCI8.rb: A data dictionary all_constraints doesn't have + index_name column on Oracle 8i or lower. Rewrite + DBI::DBD::OCI8::Database#column by using all_cons_columns. + (backport from ruby-oci8 trunk) + +2009-04-12 KUBO Takehiro * ext/oci8/extconf.rb, ext/oci8/oci8.h, ext/oci8/oraconf.rb: fix a problem when compiling for Oracle 8.0. (reported by Axel Reinhold as a ruby-oci8 2.0 issue) Modified: branches/ruby-oci8-1.0/lib/dbd/OCI8.rb =================================================================== --- branches/ruby-oci8-1.0/lib/dbd/OCI8.rb 2009-04-12 02:51:49 UTC (rev 333) +++ branches/ruby-oci8-1.0/lib/dbd/OCI8.rb 2009-04-12 02:59:34 UTC (rev 334) @@ -245,19 +245,21 @@ dbh = DBI::DatabaseHandle.new(self) - pk_index_name = nil + primaries = {} dbh.select_all(< Revision: 335 Author: kubo Date: 2009-04-12 05:03:24 -0400 (Sun, 12 Apr 2009) Log Message: ----------- * ext/oci8/lob.c: OCI8::BLOB#read should return ASCII-8BIT. OCI8::BLOB#write should not convert the specified string to OCI8.encoding. * test/test_dbi.rb: suppress warning: "shadowing outer local variable - i" * test/test_all.rb, test/test_encoding.rb: add string encoding tests. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/lob.c trunk/ruby-oci8/test/test_all.rb trunk/ruby-oci8/test/test_dbi.rb Added Paths: ----------- trunk/ruby-oci8/test/test_encoding.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2009-04-12 02:59:34 UTC (rev 334) +++ trunk/ruby-oci8/ChangeLog 2009-04-12 09:03:24 UTC (rev 335) @@ -1,4 +1,13 @@ 2009-04-12 KUBO Takehiro + * ext/oci8/lob.c: OCI8::BLOB#read should return ASCII-8BIT. + OCI8::BLOB#write should not convert the specified string + to OCI8.encoding. + * test/test_dbi.rb: suppress warning: "shadowing outer local + variable - i" + * test/test_all.rb, test/test_encoding.rb: add string encoding + tests. + +2009-04-12 KUBO Takehiro * lib/dbd/OCI8.rb: fix DBI::DBD::OCI8::BindType::DBIStatementHandle to pass a newly added sanity check in dbi 0.4.1. (reported by Dirk Herzhauser) Modified: trunk/ruby-oci8/ext/oci8/lob.c =================================================================== --- trunk/ruby-oci8/ext/oci8/lob.c 2009-04-12 02:59:34 UTC (rev 334) +++ trunk/ruby-oci8/ext/oci8/lob.c 2009-04-12 09:03:24 UTC (rev 335) @@ -26,6 +26,7 @@ ub4 pos; int char_width; ub1 csfrm; + ub1 lobtype; enum state state; } oci8_lob_t; @@ -149,6 +150,7 @@ lob->pos = 0; lob->char_width = 1; lob->csfrm = csfrm; + lob->lobtype = lobtype; lob->state = S_NO_OPEN_CLOSE; oci8_link_to_parent((oci8_base_t*)lob, (oci8_base_t*)DATA_PTR(svc)); if (!NIL_P(val)) { @@ -360,8 +362,14 @@ } v = rb_ary_join(v, Qnil); OBJ_TAINT(v); - rb_enc_associate(v, oci8_encoding); - return rb_str_conv_enc(v, oci8_encoding, rb_default_internal_encoding()); + if (lob->lobtype == OCI_TEMP_CLOB) { + /* set encoding */ + rb_enc_associate(v, oci8_encoding); + return rb_str_conv_enc(v, oci8_encoding, rb_default_internal_encoding()); + } else { + /* ASCII-8BIT */ + return v; + } } static VALUE oci8_lob_write(VALUE self, VALUE data) @@ -371,7 +379,11 @@ ub4 amt; lob_open(lob); - OCI8StringValue(data); + if (lob->lobtype == OCI_TEMP_CLOB) { + OCI8StringValue(data); + } else { + StringValue(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)); lob->pos += amt; @@ -503,6 +515,7 @@ lob->pos = 0; lob->char_width = 1; lob->csfrm = SQLCS_IMPLICIT; + lob->lobtype = OCI_TEMP_BLOB; lob->state = S_BFILE_CLOSE; if (argc != 1) { OCI8SafeStringValue(dir_alias); Modified: trunk/ruby-oci8/test/test_all.rb =================================================================== --- trunk/ruby-oci8/test/test_all.rb 2009-04-12 02:59:34 UTC (rev 334) +++ trunk/ruby-oci8/test/test_all.rb 2009-04-12 09:03:24 UTC (rev 335) @@ -21,6 +21,10 @@ require "#{srcdir}/test_rowid" require "#{srcdir}/test_oracle_version" +if OCI8.respond_to? :encoding + require "#{srcdir}/test_encoding" +end + # Ruby/DBI begin require 'dbi' Modified: trunk/ruby-oci8/test/test_dbi.rb =================================================================== --- trunk/ruby-oci8/test/test_dbi.rb 2009-04-12 02:59:34 UTC (rev 334) +++ trunk/ruby-oci8/test/test_dbi.rb 2009-04-12 09:03:24 UTC (rev 335) @@ -252,7 +252,7 @@ drop_table('test_table') @dbh.execute(<<-EOS) -CREATE TABLE test_table (#{i = 0; coldef.collect do |c| i += 1; "C#{i} " + c[1] + (c[8] ? ' PRIMARY KEY' : ''); end.join(',')}) +CREATE TABLE test_table (#{n = 0; coldef.collect do |c| n += 1; "C#{n} " + c[1] + (c[8] ? ' PRIMARY KEY' : ''); end.join(',')}) STORAGE ( INITIAL 100k NEXT 100k Added: trunk/ruby-oci8/test/test_encoding.rb =================================================================== --- trunk/ruby-oci8/test/test_encoding.rb (rev 0) +++ trunk/ruby-oci8/test/test_encoding.rb 2009-04-12 09:03:24 UTC (rev 335) @@ -0,0 +1,77 @@ +require 'oci8' +require 'test/unit' +require File.dirname(__FILE__) + '/config' + +class TestEncoding < Test::Unit::TestCase + def setup + @conn = get_oci8_connection + end + + def test_select + drop_table('test_table') + @conn.exec(< Revision: 336 Author: kubo Date: 2009-04-12 09:00:56 -0400 (Sun, 12 Apr 2009) Log Message: ----------- * lib/oci8/oci8.rb, test/test_encoding.rb: The string bind length should be got from the string bytesize converted to OCI8.encoding. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/lib/oci8/oci8.rb trunk/ruby-oci8/test/test_encoding.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2009-04-12 09:03:24 UTC (rev 335) +++ trunk/ruby-oci8/ChangeLog 2009-04-12 13:00:56 UTC (rev 336) @@ -1,4 +1,8 @@ 2009-04-12 KUBO Takehiro + * lib/oci8/oci8.rb, test/test_encoding.rb: The string bind length should + be got from the string bytesize converted to OCI8.encoding. + +2009-04-12 KUBO Takehiro * ext/oci8/lob.c: OCI8::BLOB#read should return ASCII-8BIT. OCI8::BLOB#write should not convert the specified string to OCI8.encoding. Modified: trunk/ruby-oci8/lib/oci8/oci8.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/oci8.rb 2009-04-12 09:03:24 UTC (rev 335) +++ trunk/ruby-oci8/lib/oci8/oci8.rb 2009-04-12 13:00:56 UTC (rev 336) @@ -218,15 +218,36 @@ end class String + # 1333 <= ceil(4000 / 3). 4000 is max size of char. 3 is NLS ratio of UTF-8. + @@minimum_bind_length = 1333 + + def self.minimum_bind_length + @@minimum_bind_length + end + + def self.minimum_bind_length=(val) + @@minimum_bind_length = val + end + def self.create(con, val, param, max_array_size) case param when Hash - # 1333 = ceil(4000 (max size of char) / 3 (NLS ratio of UTF8)) - length = 1333 # default length if param[:length] + # If length is passed explicitly, use it. length = param[:length] - elsif val.respond_to? :to_str and val.to_str.size > length - length = val.to_str.size + elsif val.is_a? String or (val.respond_to? :to_str and val = val.to_str) + if OCI8.respond_to? :encoding and OCI8.encoding != val.encoding + # If the string encoding is different with NLS_LANG character set, + # convert it to get the length. + val = val.encode(OCI8.encoding) + end + if val.respond_to? :bytesize + # ruby 1.8.7 or upper + length = val.bytesize + else + # ruby 1.8.6 or lower + length = val.size + end end when OCI8::Metadata::Base case param.data_type @@ -239,10 +260,9 @@ when :raw # HEX needs twice space. length = param.data_size * 2 - else - length = 100 end end + length = @@minimum_bind_length if length.nil? or length < @@minimum_bind_length self.new(con, val, length, max_array_size) end end Modified: trunk/ruby-oci8/test/test_encoding.rb =================================================================== --- trunk/ruby-oci8/test/test_encoding.rb 2009-04-12 09:03:24 UTC (rev 335) +++ trunk/ruby-oci8/test/test_encoding.rb 2009-04-12 13:00:56 UTC (rev 336) @@ -71,6 +71,29 @@ drop_table('test_table') end + if OCI8.encoding.name == "UTF-8" + def test_bind_string_with_code_conversion + drop_table('test_table') + @conn.exec(< Revision: 337 Author: kubo Date: 2009-04-14 07:07:01 -0400 (Tue, 14 Apr 2009) Log Message: ----------- * ext/oci8/oraconf.rb: Gets ORACLE_HOME from the Windows regitry by enumerating subkeys of \\HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE. Modified Paths: -------------- branches/ruby-oci8-1.0/ChangeLog branches/ruby-oci8-1.0/ext/oci8/oraconf.rb trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/oraconf.rb Modified: branches/ruby-oci8-1.0/ChangeLog =================================================================== --- branches/ruby-oci8-1.0/ChangeLog 2009-04-12 13:00:56 UTC (rev 336) +++ branches/ruby-oci8-1.0/ChangeLog 2009-04-14 11:07:01 UTC (rev 337) @@ -1,3 +1,7 @@ +2009-04-14 KUBO Takehiro + * ext/oci8/oraconf.rb: Gets ORACLE_HOME from the Windows regitry + by enumerating subkeys of \\HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE. + 2009-04-12 KUBO Takehiro * lib/dbd/OCI8.rb: A data dictionary all_constraints doesn't have index_name column on Oracle 8i or lower. Rewrite Modified: branches/ruby-oci8-1.0/ext/oci8/oraconf.rb =================================================================== --- branches/ruby-oci8-1.0/ext/oci8/oraconf.rb 2009-04-12 13:00:56 UTC (rev 336) +++ branches/ruby-oci8-1.0/ext/oci8/oraconf.rb 2009-04-14 11:07:01 UTC (rev 337) @@ -48,48 +48,69 @@ # copy the minimum code and reorganize it. ERROR_SUCCESS = 0 ERROR_FILE_NOT_FOUND = 2 + ERROR_NO_MORE_ITEMS = 259 HKEY_LOCAL_MACHINE = 0x80000002 + KEY_ENUMERATE_SUB_KEYS = 0x0008 + KEY_QUERY_VALUE = 0x0001 RegOpenKeyExA = Win32API.new('advapi32', 'RegOpenKeyExA', 'LPLLP', 'L') + RegEnumKeyExA = Win32API.new('advapi32', 'RegEnumKeyExA', 'LLPPPPPP', 'L') RegQueryValueExA = Win32API.new('advapi32','RegQueryValueExA','LPPPPP','L') RegCloseKey = Win32API.new('advapi32', 'RegCloseKey', 'L', 'L') - def get_reg_value(root, subkey, name) - result = [0].pack('L') - code = RegOpenKeyExA.call(root, subkey, 0, 0x20019, result) + def self.get_str_value(hKey, name) + lpcbData = [0].pack('L') + code = RegQueryValueExA.call(hKey, name, nil, nil, nil, lpcbData) + if code == ERROR_FILE_NOT_FOUND + return nil + elsif code != ERROR_SUCCESS + raise MiniRegistryError.new("Win32::RegQueryValueExA",code) + end + len = lpcbData.unpack('L')[0] + lpType = [0].pack('L') + lpData = "\0"*len + lpcbData = [len].pack('L') + code = RegQueryValueExA.call(hKey, name, nil, lpType, lpData, lpcbData) if code != ERROR_SUCCESS + raise MiniRegistryError.new("Win32::RegQueryValueExA",code) + end + lpData.unpack('Z*')[0] + end + + def self.enum_homes + phkResult = [0].pack('L') + code = RegOpenKeyExA.call(HKEY_LOCAL_MACHINE, 'SOFTWARE\ORACLE', 0, 0x20019, phkResult) + if code != ERROR_SUCCESS raise MiniRegistryError.new("Win32::RegOpenKeyExA", code) end - hkey = result.unpack('L')[0] - begin - lpcbData = [0].pack('L') - code = RegQueryValueExA.call(hkey, name, nil, nil, nil, lpcbData) - if code == ERROR_FILE_NOT_FOUND - return nil - elsif code != ERROR_SUCCESS - raise MiniRegistryError.new("Win32::RegQueryValueExA",code) + hKey = phkResult.unpack('L')[0] + idx = 0 + maxkeylen = 256 + loop do + lpName = "\0" * maxkeylen + lpcName = [maxkeylen].pack('L') + code = RegEnumKeyExA.call(hKey, idx, lpName, lpcName, nil, nil, nil, nil); + break if code == ERROR_NO_MORE_ITEMS + if code != ERROR_SUCCESS + RegCloseKey.call(hKey) + raise MiniRegistryError.new("Win32::RegEnumKeyEx", code) end - len = lpcbData.unpack('L')[0] - lpType = "\0\0\0\0" - lpData = "\0"*len - lpcbData = [len].pack('L') - code = RegQueryValueExA.call(hkey, name, nil, lpType, lpData, lpcbData) + code = RegOpenKeyExA.call(hKey, lpName, 0, KEY_QUERY_VALUE, phkResult) if code != ERROR_SUCCESS - raise MiniRegistryError.new("Win32::RegQueryValueExA",code) + RegCloseKey.call(hKey) + raise MiniRegistryError.new("Win32::RegEnumKeyEx", code) end - lpData.unpack('Z*')[0] - ensure - RegCloseKey.call(hkey) + hSubkey = phkResult.unpack('L')[0] + + name = get_str_value(hSubkey, 'ORACLE_HOME_NAME') + path = get_str_value(hSubkey, 'ORACLE_HOME') + yield name, path + RegCloseKey.call(hSubkey) + idx += 1 end + RegCloseKey.call(hKey) end - def get_local_registry(subkey, name) - get_reg_value(HKEY_LOCAL_MACHINE, subkey, name) - end - else - # UNIX - def get_local_registry(subkey, name) - nil - end + end end # module MiniRegistry @@ -293,8 +314,6 @@ end class OraConf - include MiniRegistry - attr_reader :cc_is_gcc attr_reader :version attr_reader :cflags @@ -717,6 +736,7 @@ sqlplus = "sqlplus" end Logging::open do + ENV['NLS_LANG'] = 'american_america.us7ascii' open("|#{@oracle_home}/bin/#{sqlplus} < #{dev_null}") do |f| while line = f.gets print line @@ -755,26 +775,10 @@ if oracle_home.nil? struct = Struct.new("OracleHome", :name, :path) oracle_homes = [] - begin - last_home = get_local_registry("SOFTWARE\\ORACLE\\ALL_HOMES", 'LAST_HOME') - 0.upto last_home.to_i do |id| - oracle_homes << "HOME#{id}" - end - rescue MiniRegistryError + MiniRegistry.enum_homes do |name, path| + path.chomp!("\\") if path + oracle_homes << struct.new(name, path) if is_valid_home?(path) end - oracle_homes << "KEY_XE" - oracle_homes << "KEY_XEClient" - oracle_homes.collect! do |home| - begin - name = get_local_registry("SOFTWARE\\ORACLE\\#{home}", 'ORACLE_HOME_NAME') - path = get_local_registry("SOFTWARE\\ORACLE\\#{home}", 'ORACLE_HOME') - path.chomp!("\\") - struct.new(name, path) if is_valid_home?(path) - rescue MiniRegistryError - nil - end - end - oracle_homes.compact! if oracle_homes.empty? raise < + * ext/oci8/oraconf.rb: Gets ORACLE_HOME from the Windows regitry + by enumerating subkeys of \\HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE. + 2009-04-12 KUBO Takehiro * lib/oci8/oci8.rb, test/test_encoding.rb: The string bind length should be got from the string bytesize converted to OCI8.encoding. Modified: trunk/ruby-oci8/ext/oci8/oraconf.rb =================================================================== --- trunk/ruby-oci8/ext/oci8/oraconf.rb 2009-04-12 13:00:56 UTC (rev 336) +++ trunk/ruby-oci8/ext/oci8/oraconf.rb 2009-04-14 11:07:01 UTC (rev 337) @@ -48,48 +48,69 @@ # copy the minimum code and reorganize it. ERROR_SUCCESS = 0 ERROR_FILE_NOT_FOUND = 2 + ERROR_NO_MORE_ITEMS = 259 HKEY_LOCAL_MACHINE = 0x80000002 + KEY_ENUMERATE_SUB_KEYS = 0x0008 + KEY_QUERY_VALUE = 0x0001 RegOpenKeyExA = Win32API.new('advapi32', 'RegOpenKeyExA', 'LPLLP', 'L') + RegEnumKeyExA = Win32API.new('advapi32', 'RegEnumKeyExA', 'LLPPPPPP', 'L') RegQueryValueExA = Win32API.new('advapi32','RegQueryValueExA','LPPPPP','L') RegCloseKey = Win32API.new('advapi32', 'RegCloseKey', 'L', 'L') - def get_reg_value(root, subkey, name) - result = [0].pack('L') - code = RegOpenKeyExA.call(root, subkey, 0, 0x20019, result) + def self.get_str_value(hKey, name) + lpcbData = [0].pack('L') + code = RegQueryValueExA.call(hKey, name, nil, nil, nil, lpcbData) + if code == ERROR_FILE_NOT_FOUND + return nil + elsif code != ERROR_SUCCESS + raise MiniRegistryError.new("Win32::RegQueryValueExA",code) + end + len = lpcbData.unpack('L')[0] + lpType = [0].pack('L') + lpData = "\0"*len + lpcbData = [len].pack('L') + code = RegQueryValueExA.call(hKey, name, nil, lpType, lpData, lpcbData) if code != ERROR_SUCCESS + raise MiniRegistryError.new("Win32::RegQueryValueExA",code) + end + lpData.unpack('Z*')[0] + end + + def self.enum_homes + phkResult = [0].pack('L') + code = RegOpenKeyExA.call(HKEY_LOCAL_MACHINE, 'SOFTWARE\ORACLE', 0, 0x20019, phkResult) + if code != ERROR_SUCCESS raise MiniRegistryError.new("Win32::RegOpenKeyExA", code) end - hkey = result.unpack('L')[0] - begin - lpcbData = [0].pack('L') - code = RegQueryValueExA.call(hkey, name, nil, nil, nil, lpcbData) - if code == ERROR_FILE_NOT_FOUND - return nil - elsif code != ERROR_SUCCESS - raise MiniRegistryError.new("Win32::RegQueryValueExA",code) + hKey = phkResult.unpack('L')[0] + idx = 0 + maxkeylen = 256 + loop do + lpName = "\0" * maxkeylen + lpcName = [maxkeylen].pack('L') + code = RegEnumKeyExA.call(hKey, idx, lpName, lpcName, nil, nil, nil, nil); + break if code == ERROR_NO_MORE_ITEMS + if code != ERROR_SUCCESS + RegCloseKey.call(hKey) + raise MiniRegistryError.new("Win32::RegEnumKeyEx", code) end - len = lpcbData.unpack('L')[0] - lpType = "\0\0\0\0" - lpData = "\0"*len - lpcbData = [len].pack('L') - code = RegQueryValueExA.call(hkey, name, nil, lpType, lpData, lpcbData) + code = RegOpenKeyExA.call(hKey, lpName, 0, KEY_QUERY_VALUE, phkResult) if code != ERROR_SUCCESS - raise MiniRegistryError.new("Win32::RegQueryValueExA",code) + RegCloseKey.call(hKey) + raise MiniRegistryError.new("Win32::RegEnumKeyEx", code) end - lpData.unpack('Z*')[0] - ensure - RegCloseKey.call(hkey) + hSubkey = phkResult.unpack('L')[0] + + name = get_str_value(hSubkey, 'ORACLE_HOME_NAME') + path = get_str_value(hSubkey, 'ORACLE_HOME') + yield name, path + RegCloseKey.call(hSubkey) + idx += 1 end + RegCloseKey.call(hKey) end - def get_local_registry(subkey, name) - get_reg_value(HKEY_LOCAL_MACHINE, subkey, name) - end - else - # UNIX - def get_local_registry(subkey, name) - nil - end + end end # module MiniRegistry @@ -293,8 +314,6 @@ end class OraConf - include MiniRegistry - attr_reader :cc_is_gcc attr_reader :version attr_reader :cflags @@ -756,26 +775,10 @@ if oracle_home.nil? struct = Struct.new("OracleHome", :name, :path) oracle_homes = [] - begin - last_home = get_local_registry("SOFTWARE\\ORACLE\\ALL_HOMES", 'LAST_HOME') - 0.upto last_home.to_i do |id| - oracle_homes << "HOME#{id}" - end - rescue MiniRegistryError + MiniRegistry.enum_homes do |name, path| + path.chomp!("\\") if path + oracle_homes << struct.new(name, path) if is_valid_home?(path) end - oracle_homes << "KEY_XE" - oracle_homes << "KEY_XEClient" - oracle_homes.collect! do |home| - begin - name = get_local_registry("SOFTWARE\\ORACLE\\#{home}", 'ORACLE_HOME_NAME') - path = get_local_registry("SOFTWARE\\ORACLE\\#{home}", 'ORACLE_HOME') - path.chomp!("\\") - struct.new(name, path) if is_valid_home?(path) - rescue MiniRegistryError - nil - end - end - oracle_homes.compact! if oracle_homes.empty? raise < Revision: 338 Author: kubo Date: 2009-04-14 07:58:26 -0400 (Tue, 14 Apr 2009) Log Message: ----------- * ext/oci8/oci8.h, ext/oci8/oci8lib.c, ext/oci8/ocinumber.c, ext/oci8/metadata.c, ext/oci8/object.c: pass an OCIError to OraNumber functions if it can. (This is the first step to delay OCIEnv initialization.) Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/metadata.c trunk/ruby-oci8/ext/oci8/object.c trunk/ruby-oci8/ext/oci8/oci8.h trunk/ruby-oci8/ext/oci8/oci8lib.c trunk/ruby-oci8/ext/oci8/ocinumber.c Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2009-04-14 11:07:01 UTC (rev 337) +++ trunk/ruby-oci8/ChangeLog 2009-04-14 11:58:26 UTC (rev 338) @@ -1,4 +1,10 @@ 2009-04-14 KUBO Takehiro + * ext/oci8/oci8.h, ext/oci8/oci8lib.c, ext/oci8/ocinumber.c, + ext/oci8/metadata.c, ext/oci8/object.c: pass an OCIError to + OraNumber functions if it can. (This is the first step to + delay OCIEnv initialization.) + +2009-04-14 KUBO Takehiro * ext/oci8/oraconf.rb: Gets ORACLE_HOME from the Windows regitry by enumerating subkeys of \\HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE. Modified: trunk/ruby-oci8/ext/oci8/metadata.c =================================================================== --- trunk/ruby-oci8/ext/oci8/metadata.c 2009-04-14 11:07:01 UTC (rev 337) +++ trunk/ruby-oci8/ext/oci8/metadata.c 2009-04-14 11:58:26 UTC (rev 338) @@ -2,7 +2,7 @@ /* * metadata.c * - * Copyright (C) 2006-2007 KUBO Takehiro + * Copyright (C) 2006-2009 KUBO Takehiro * * implement private methods of classes in OCI8::Metadata module. * @@ -210,7 +210,7 @@ memset(&on, 0, sizeof(on)); on.OCINumberPart[0] = size; memcpy(&on.OCINumberPart[1], value, size); - return oci8_make_integer(&on); + return oci8_make_integer(&on, oci8_errhp); } static VALUE metadata_get_param(VALUE self, VALUE idx) Modified: trunk/ruby-oci8/ext/oci8/object.c =================================================================== --- trunk/ruby-oci8/ext/oci8/object.c 2009-04-14 11:07:01 UTC (rev 337) +++ trunk/ruby-oci8/ext/oci8/object.c 2009-04-14 11:58:26 UTC (rev 338) @@ -1,5 +1,10 @@ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */ /* + * Copyright (C) 2002-2009 KUBO Takehiro + */ + +/* + * * Document-class: OCI8::TDO * * OCI8::TDO is the class for Type Descriptor Object, which describe @@ -157,11 +162,11 @@ return rb_str_new(TO_CHARPTR(OCIRawPtr(oci8_envhp, *(OCIRaw **)data)), OCIRawSize(oci8_envhp, *(OCIRaw **)data)); case ATTR_OCINUMBER: - return oci8_make_ocinumber((OCINumber *)data); + return oci8_make_ocinumber((OCINumber *)data, oci8_errhp); case ATTR_FLOAT: - return oci8_make_float((OCINumber *)data); + return oci8_make_float((OCINumber *)data, oci8_errhp); case ATTR_INTEGER: - return oci8_make_integer((OCINumber *)data); + return oci8_make_integer((OCINumber *)data, oci8_errhp); case ATTR_BINARY_DOUBLE: return rb_float_new(*(double*)data); case ATTR_BINARY_FLOAT: @@ -431,10 +436,10 @@ break; case ATTR_OCINUMBER: case ATTR_FLOAT: - oci8_set_ocinumber((OCINumber*)data, val); + oci8_set_ocinumber((OCINumber*)data, val, oci8_errhp); break; case ATTR_INTEGER: - oci8_set_integer((OCINumber*)data, val); + oci8_set_integer((OCINumber*)data, val, oci8_errhp); break; case ATTR_BINARY_DOUBLE: *(double*)data = NUM2DBL(val); Modified: trunk/ruby-oci8/ext/oci8/oci8.h =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8.h 2009-04-14 11:07:01 UTC (rev 337) +++ trunk/ruby-oci8/ext/oci8/oci8.h 2009-04-14 11:58:26 UTC (rev 338) @@ -1,9 +1,9 @@ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */ /* - oci8.h - part of ruby-oci8 - - Copyright (C) 2002-2009 KUBO Takehiro -*/ + * oci8.h - part of ruby-oci8 + * + * Copyright (C) 2002-2009 KUBO Takehiro + */ #ifndef _RUBY_OCI_H_ #define _RUBY_OCI_H_ 1 @@ -434,13 +434,13 @@ void Init_ora_date(void); /* ocinumber.c */ -void Init_oci_number(VALUE mOCI); +void Init_oci_number(VALUE mOCI, OCIError *errhp); OCINumber *oci8_get_ocinumber(VALUE num); -VALUE oci8_make_ocinumber(OCINumber *s); -VALUE oci8_make_integer(OCINumber *s); -VALUE oci8_make_float(OCINumber *s); -OCINumber *oci8_set_ocinumber(OCINumber *result, VALUE self); -OCINumber *oci8_set_integer(OCINumber *result, VALUE self); +VALUE oci8_make_ocinumber(OCINumber *s, OCIError *errhp); +VALUE oci8_make_integer(OCINumber *s, OCIError *errhp); +VALUE oci8_make_float(OCINumber *s, OCIError *errhp); +OCINumber *oci8_set_ocinumber(OCINumber *result, VALUE self, OCIError *errhp); +OCINumber *oci8_set_integer(OCINumber *result, VALUE self, OCIError *errhp); /* ocidatetim.c */ void Init_oci_datetime(void); Modified: trunk/ruby-oci8/ext/oci8/oci8lib.c =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8lib.c 2009-04-14 11:07:01 UTC (rev 337) +++ trunk/ruby-oci8/ext/oci8/oci8lib.c 2009-04-14 11:58:26 UTC (rev 338) @@ -1,6 +1,6 @@ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */ /* - * Copyright (C) 2002-2008 KUBO Takehiro + * Copyright (C) 2002-2009 KUBO Takehiro */ #include "oci8.h" @@ -155,7 +155,7 @@ Init_oci8_lob(cOCI8); Init_ora_date(); - Init_oci_number(cOCI8); + Init_oci_number(cOCI8, oci8_errhp); Init_oci_datetime(); Init_oci_object(cOCI8); Init_oci_xmldb(); Modified: trunk/ruby-oci8/ext/oci8/ocinumber.c =================================================================== --- trunk/ruby-oci8/ext/oci8/ocinumber.c 2009-04-14 11:07:01 UTC (rev 337) +++ trunk/ruby-oci8/ext/oci8/ocinumber.c 2009-04-14 11:58:26 UTC (rev 338) @@ -2,11 +2,8 @@ /* * ocinumber.c * - * $Author$ - * $Date$ + * Copyright (C) 2005-2009 KUBO Takehiro * - * Copyright (C) 2005-2008 KUBO Takehiro - * */ #include "oci8.h" #include @@ -61,40 +58,40 @@ } /* construct an ruby object(OCI::Number) from C structure (OCINumber). */ -VALUE oci8_make_ocinumber(OCINumber *s) +VALUE oci8_make_ocinumber(OCINumber *s, OCIError *errhp) { VALUE obj; OCINumber *d; obj = Data_Make_Struct(cOCINumber, OCINumber, NULL, xfree, d); - oci_lc(OCINumberAssign(oci8_errhp, s, d)); + oci_lc(OCINumberAssign(errhp, s, d)); return obj; } -VALUE oci8_make_integer(OCINumber *s) +VALUE oci8_make_integer(OCINumber *s, OCIError *errhp) { signed long sl; char buf[512]; ub4 buf_size = sizeof(buf); - if (OCINumberToInt(oci8_errhp, s, sizeof(sl), OCI_NUMBER_SIGNED, &sl) == OCI_SUCCESS) { + if (OCINumberToInt(errhp, s, sizeof(sl), OCI_NUMBER_SIGNED, &sl) == OCI_SUCCESS) { return LONG2NUM(sl); } - oci_lc(OCINumberToText(oci8_errhp, s, NUMBER_FORMAT2, NUMBER_FORMAT2_LEN, + oci_lc(OCINumberToText(errhp, s, NUMBER_FORMAT2, NUMBER_FORMAT2_LEN, NULL, 0, &buf_size, TO_ORATEXT(buf))); return rb_cstr2inum(buf, 10); } -VALUE oci8_make_float(OCINumber *s) +VALUE oci8_make_float(OCINumber *s, OCIError *errhp) { double dbl; - oci_lc(OCINumberToReal(oci8_errhp, s, sizeof(double), &dbl)); + oci_lc(OCINumberToReal(errhp, s, sizeof(double), &dbl)); return rb_float_new(dbl); } /* fill C structure (OCINumber) from a string. */ -static void set_oci_number_from_str(OCINumber *result, VALUE str, VALUE fmt, VALUE nls_params) +static void set_oci_number_from_str(OCINumber *result, VALUE str, VALUE fmt, VALUE nls_params, OCIError *errhp) { oratext *fmt_ptr; oratext *nls_params_ptr; @@ -135,7 +132,7 @@ nls_params_ptr = RSTRING_ORATEXT(nls_params); nls_params_len = RSTRING_LEN(nls_params); } - oci_lc(OCINumberFromText(oci8_errhp, + oci_lc(OCINumberFromText(errhp, RSTRING_ORATEXT(str), RSTRING_LEN(str), fmt_ptr, fmt_len, nls_params_ptr, nls_params_len, result)); @@ -143,7 +140,7 @@ /* fill C structure (OCINumber) from a numeric object. */ /* 1 - success, 0 - error */ -static int set_oci_number_from_num(OCINumber *result, VALUE num, int force) +static int set_oci_number_from_num(OCINumber *result, VALUE num, int force, OCIError *errhp) { signed long sl; double dbl; @@ -154,45 +151,46 @@ case T_FIXNUM: /* set from long. */ sl = NUM2LONG(num); - oci_lc(OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, result)); + oci_lc(OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, result)); return 1; case T_FLOAT: /* set from double. */ dbl = NUM2DBL(num); - oci_lc(OCINumberFromReal(oci8_errhp, &dbl, sizeof(dbl), result)); + oci_lc(OCINumberFromReal(errhp, &dbl, sizeof(dbl), result)); return 1; case T_BIGNUM: /* change via string. */ num = rb_big2str(num, 10); - set_oci_number_from_str(result, num, Qnil, Qnil); + set_oci_number_from_str(result, num, Qnil, Qnil, errhp); return 1; } if (RTEST(rb_obj_is_instance_of(num, cOCINumber))) { /* OCI::Number */ - oci_lc(OCINumberAssign(oci8_errhp, DATA_PTR(num), result)); + oci_lc(OCINumberAssign(errhp, DATA_PTR(num), result)); return 1; } if (force) { /* change via string as a last resort. */ /* TODO: if error, raise TypeError instead of OCI::Error */ - set_oci_number_from_str(result, num, Qnil, Qnil); + set_oci_number_from_str(result, num, Qnil, Qnil, errhp); return 1; } return 0; } -OCINumber *oci8_set_ocinumber(OCINumber *result, VALUE self) +OCINumber *oci8_set_ocinumber(OCINumber *result, VALUE self, OCIError *errhp) { - set_oci_number_from_num(result, self, 1); + set_oci_number_from_num(result, self, 1, errhp); return result; } -#define TO_OCINUM(on, val) oci8_set_ocinumber((on), (val)) +#define TO_OCINUM oci8_set_ocinumber -OCINumber *oci8_set_integer(OCINumber *result, VALUE self) +OCINumber *oci8_set_integer(OCINumber *result, VALUE self, OCIError *errhp) { OCINumber work; - set_oci_number_from_num(&work, self, 1); - oci_lc(OCINumberTrunc(oci8_errhp, &work, 0, result)); + + set_oci_number_from_num(&work, self, 1, errhp); + oci_lc(OCINumberTrunc(errhp, &work, 0, result)); return result; } @@ -205,30 +203,31 @@ */ static VALUE omath_atan2(VALUE self, VALUE Ycoordinate, VALUE Xcoordinate) { + OCIError *errhp = oci8_errhp; OCINumber nY; OCINumber nX; OCINumber rv; boolean is_zero; sword sign; - set_oci_number_from_num(&nX, Xcoordinate, 1); - set_oci_number_from_num(&nY, Ycoordinate, 1); + set_oci_number_from_num(&nX, Xcoordinate, 1, errhp); + set_oci_number_from_num(&nY, Ycoordinate, 1, errhp); /* check zero */ - oci_lc(OCINumberIsZero(oci8_errhp, &nX, &is_zero)); + oci_lc(OCINumberIsZero(errhp, &nX, &is_zero)); if (is_zero) { - oci_lc(OCINumberSign(oci8_errhp, &nY, &sign)); + oci_lc(OCINumberSign(errhp, &nY, &sign)); switch (sign) { case 0: return INT2FIX(0); /* atan2(0, 0) => 0 or ERROR? */ case 1: - return oci8_make_ocinumber(&const_PI2); /* atan2(positive, 0) => PI/2 */ + return oci8_make_ocinumber(&const_PI2, errhp); /* atan2(positive, 0) => PI/2 */ case -1: - return oci8_make_ocinumber(&const_mPI2); /* atan2(negative, 0) => -PI/2 */ + return oci8_make_ocinumber(&const_mPI2, errhp); /* atan2(negative, 0) => -PI/2 */ } } /* atan2 */ - oci_lc(OCINumberArcTan2(oci8_errhp, &nY, &nX, &rv)); - return oci8_make_ocinumber(&rv); + oci_lc(OCINumberArcTan2(errhp, &nY, &nX, &rv)); + return oci8_make_ocinumber(&rv, errhp); } /* @@ -240,11 +239,12 @@ */ static VALUE omath_cos(VALUE obj, VALUE radian) { + OCIError *errhp = oci8_errhp; OCINumber r; OCINumber rv; - oci_lc(OCINumberCos(oci8_errhp, TO_OCINUM(&r, radian), &rv)); - return oci8_make_ocinumber(&rv); + oci_lc(OCINumberCos(errhp, TO_OCINUM(&r, radian, errhp), &rv)); + return oci8_make_ocinumber(&rv, errhp); } /* @@ -256,11 +256,12 @@ */ static VALUE omath_sin(VALUE obj, VALUE radian) { + OCIError *errhp = oci8_errhp; OCINumber r; OCINumber rv; - oci_lc(OCINumberSin(oci8_errhp, TO_OCINUM(&r, radian), &rv)); - return oci8_make_ocinumber(&rv); + oci_lc(OCINumberSin(errhp, TO_OCINUM(&r, radian, errhp), &rv)); + return oci8_make_ocinumber(&rv, errhp); } /* @@ -271,11 +272,12 @@ */ static VALUE omath_tan(VALUE obj, VALUE radian) { + OCIError *errhp = oci8_errhp; OCINumber r; OCINumber rv; - oci_lc(OCINumberTan(oci8_errhp, TO_OCINUM(&r, radian), &rv)); - return oci8_make_ocinumber(&rv); + oci_lc(OCINumberTan(errhp, TO_OCINUM(&r, radian, errhp), &rv)); + return oci8_make_ocinumber(&rv, errhp); } /* @@ -286,22 +288,23 @@ */ static VALUE omath_acos(VALUE obj, VALUE num) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; sword sign; - set_oci_number_from_num(&n, num, 1); + set_oci_number_from_num(&n, num, 1, errhp); /* check upper bound */ - oci_lc(OCINumberCmp(oci8_errhp, &n, &const_p1, &sign)); + oci_lc(OCINumberCmp(errhp, &n, &const_p1, &sign)); if (sign > 0) rb_raise(rb_eRangeError, "out of range for acos"); /* check lower bound */ - oci_lc(OCINumberCmp(oci8_errhp, &n, &const_m1, &sign)); + oci_lc(OCINumberCmp(errhp, &n, &const_m1, &sign)); if (sign < 0) rb_raise(rb_eRangeError, "out of range for acos"); /* acos */ - oci_lc(OCINumberArcCos(oci8_errhp, &n, &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberArcCos(errhp, &n, &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -312,22 +315,23 @@ */ static VALUE omath_asin(VALUE obj, VALUE num) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; sword sign; - set_oci_number_from_num(&n, num, 1); + set_oci_number_from_num(&n, num, 1, errhp); /* check upper bound */ - oci_lc(OCINumberCmp(oci8_errhp, &n, &const_p1, &sign)); + oci_lc(OCINumberCmp(errhp, &n, &const_p1, &sign)); if (sign > 0) rb_raise(rb_eRangeError, "out of range for asin"); /* check lower bound */ - oci_lc(OCINumberCmp(oci8_errhp, &n, &const_m1, &sign)); + oci_lc(OCINumberCmp(errhp, &n, &const_m1, &sign)); if (sign < 0) rb_raise(rb_eRangeError, "out of range for asin"); /* asin */ - oci_lc(OCINumberArcSin(oci8_errhp, &n, &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberArcSin(errhp, &n, &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -338,11 +342,12 @@ */ static VALUE omath_atan(VALUE obj, VALUE num) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; - oci_lc(OCINumberArcTan(oci8_errhp, TO_OCINUM(&n, num), &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberArcTan(errhp, TO_OCINUM(&n, num, errhp), &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -353,11 +358,12 @@ */ static VALUE omath_cosh(VALUE obj, VALUE num) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; - oci_lc(OCINumberHypCos(oci8_errhp, TO_OCINUM(&n, num), &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberHypCos(errhp, TO_OCINUM(&n, num, errhp), &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -369,11 +375,12 @@ */ static VALUE omath_sinh(VALUE obj, VALUE num) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; - oci_lc(OCINumberHypSin(oci8_errhp, TO_OCINUM(&n, num), &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberHypSin(errhp, TO_OCINUM(&n, num, errhp), &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -385,11 +392,12 @@ */ static VALUE omath_tanh(VALUE obj, VALUE num) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; - oci_lc(OCINumberHypTan(oci8_errhp, TO_OCINUM(&n, num), &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberHypTan(errhp, TO_OCINUM(&n, num, errhp), &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -400,11 +408,12 @@ */ static VALUE omath_exp(VALUE obj, VALUE num) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; - oci_lc(OCINumberExp(oci8_errhp, TO_OCINUM(&n, num), &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberExp(errhp, TO_OCINUM(&n, num, errhp), &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -417,6 +426,7 @@ */ static VALUE omath_log(int argc, VALUE *argv, VALUE obj) { + OCIError *errhp = oci8_errhp; VALUE num, base; OCINumber n; OCINumber b; @@ -424,23 +434,23 @@ sword sign; rb_scan_args(argc, argv, "11", &num, &base); - set_oci_number_from_num(&n, num, 1); - oci_lc(OCINumberSign(oci8_errhp, &n, &sign)); + set_oci_number_from_num(&n, num, 1, errhp); + oci_lc(OCINumberSign(errhp, &n, &sign)); if (sign <= 0) rb_raise(rb_eRangeError, "nonpositive value for log"); if (NIL_P(base)) { - oci_lc(OCINumberLn(oci8_errhp, &n, &r)); + oci_lc(OCINumberLn(errhp, &n, &r)); } else { - set_oci_number_from_num(&b, base, 1); - oci_lc(OCINumberSign(oci8_errhp, &b, &sign)); + set_oci_number_from_num(&b, base, 1, errhp); + oci_lc(OCINumberSign(errhp, &b, &sign)); if (sign <= 0) rb_raise(rb_eRangeError, "nonpositive value for the base of log"); - oci_lc(OCINumberCmp(oci8_errhp, &b, &const_p1, &sign)); + oci_lc(OCINumberCmp(errhp, &b, &const_p1, &sign)); if (sign == 0) rb_raise(rb_eRangeError, "base 1 for log"); - oci_lc(OCINumberLog(oci8_errhp, &b, &n, &r)); + oci_lc(OCINumberLog(errhp, &b, &n, &r)); } - return oci8_make_ocinumber(&r); + return oci8_make_ocinumber(&r, errhp); } /* @@ -451,16 +461,17 @@ */ static VALUE omath_log10(VALUE obj, VALUE num) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; sword sign; - set_oci_number_from_num(&n, num, 1); - oci_lc(OCINumberSign(oci8_errhp, &n, &sign)); + set_oci_number_from_num(&n, num, 1, errhp); + oci_lc(OCINumberSign(errhp, &n, &sign)); if (sign <= 0) rb_raise(rb_eRangeError, "nonpositive value for log10"); - oci_lc(OCINumberLog(oci8_errhp, &const_p10, &n, &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberLog(errhp, &const_p10, &n, &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -471,33 +482,35 @@ */ static VALUE omath_sqrt(VALUE obj, VALUE num) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; sword sign; - set_oci_number_from_num(&n, num, 1); + set_oci_number_from_num(&n, num, 1, errhp); /* check whether num is negative */ - oci_lc(OCINumberSign(oci8_errhp, &n, &sign)); + oci_lc(OCINumberSign(errhp, &n, &sign)); if (sign < 0) { errno = EDOM; rb_sys_fail("sqrt"); } - oci_lc(OCINumberSqrt(oci8_errhp, &n, &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberSqrt(errhp, &n, &r)); + return oci8_make_ocinumber(&r, errhp); } static VALUE onum_initialize(int argc, VALUE *argv, VALUE self) { + OCIError *errhp = oci8_errhp; VALUE val; VALUE fmt; VALUE nls_params; if (rb_scan_args(argc, argv, "03", &val /* 0 */, &fmt /* nil */, &nls_params /* nil */) == 0) { - OCINumberSetZero(oci8_errhp, _NUMBER(self)); + OCINumberSetZero(errhp, _NUMBER(self)); } else if (RTEST(rb_obj_is_kind_of(val, rb_cNumeric))) { - set_oci_number_from_num(_NUMBER(self), val, 1); + set_oci_number_from_num(_NUMBER(self), val, 1, errhp); } else { - set_oci_number_from_str(_NUMBER(self), val, fmt, nls_params); + set_oci_number_from_str(_NUMBER(self), val, fmt, nls_params, errhp); } return Qnil; } @@ -514,11 +527,12 @@ static VALUE onum_coerce(VALUE self, VALUE other) { + OCIError *errhp = oci8_errhp; OCINumber n; if (RTEST(rb_obj_is_kind_of(other, rb_cNumeric))) - if (set_oci_number_from_num(&n, other, 0)) - return rb_assoc_new(oci8_make_ocinumber(&n), self); + if (set_oci_number_from_num(&n, other, 0, errhp)) + return rb_assoc_new(oci8_make_ocinumber(&n, errhp), self); rb_raise(rb_eTypeError, "Can't coerce %s to %s", rb_class2name(CLASS_OF(other)), rb_class2name(cOCINumber)); } @@ -531,10 +545,11 @@ */ static VALUE onum_neg(VALUE self) { + OCIError *errhp = oci8_errhp; OCINumber r; - oci_lc(OCINumberNeg(oci8_errhp, _NUMBER(self), &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberNeg(errhp, _NUMBER(self), &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -546,15 +561,16 @@ */ static VALUE onum_add(VALUE lhs, VALUE rhs) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; /* change to OCINumber */ - if (!set_oci_number_from_num(&n, rhs, 0)) + if (!set_oci_number_from_num(&n, rhs, 0, errhp)) return rb_num_coerce_bin(lhs, rhs, '+'); /* add */ - oci_lc(OCINumberAdd(oci8_errhp, _NUMBER(lhs), &n, &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberAdd(errhp, _NUMBER(lhs), &n, &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -566,15 +582,16 @@ */ static VALUE onum_sub(VALUE lhs, VALUE rhs) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; /* change to OCINumber */ - if (!set_oci_number_from_num(&n, rhs, 0)) + if (!set_oci_number_from_num(&n, rhs, 0, errhp)) return rb_num_coerce_bin(lhs, rhs, '-'); /* subtracting */ - oci_lc(OCINumberSub(oci8_errhp, _NUMBER(lhs), &n, &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberSub(errhp, _NUMBER(lhs), &n, &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -586,15 +603,16 @@ */ static VALUE onum_mul(VALUE lhs, VALUE rhs) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; /* change to OCINumber */ - if (!set_oci_number_from_num(&n, rhs, 0)) + if (!set_oci_number_from_num(&n, rhs, 0, errhp)) return rb_num_coerce_bin(lhs, rhs, '*'); /* multiply */ - oci_lc(OCINumberMul(oci8_errhp, _NUMBER(lhs), &n, &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberMul(errhp, _NUMBER(lhs), &n, &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -606,20 +624,21 @@ */ static VALUE onum_div(VALUE lhs, VALUE rhs) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; boolean is_zero; /* change to OCINumber */ - if (!set_oci_number_from_num(&n, rhs, 0)) + 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(oci8_errhp, &n, &is_zero)); + oci_lc(OCINumberIsZero(errhp, &n, &is_zero)); if (is_zero) rb_num_zerodiv(); /* division */ - oci_lc(OCINumberDiv(oci8_errhp, _NUMBER(lhs), &n, &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberDiv(errhp, _NUMBER(lhs), &n, &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -630,20 +649,21 @@ */ static VALUE onum_mod(VALUE lhs, VALUE rhs) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; boolean is_zero; /* change to OCINumber */ - if (!set_oci_number_from_num(&n, rhs, 0)) + 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(oci8_errhp, &n, &is_zero)); + oci_lc(OCINumberIsZero(errhp, &n, &is_zero)); if (is_zero) rb_num_zerodiv(); /* modulo */ - oci_lc(OCINumberMod(oci8_errhp, _NUMBER(lhs), &n, &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberMod(errhp, _NUMBER(lhs), &n, &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -654,18 +674,19 @@ */ static VALUE onum_power(VALUE lhs, VALUE rhs) { + OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; if (FIXNUM_P(rhs)) { - oci_lc(OCINumberIntPower(oci8_errhp, _NUMBER(lhs), FIX2INT(rhs), &r)); + oci_lc(OCINumberIntPower(errhp, _NUMBER(lhs), FIX2INT(rhs), &r)); } else { /* change to OCINumber */ - if (!set_oci_number_from_num(&n, rhs, 0)) + if (!set_oci_number_from_num(&n, rhs, 0, errhp)) return rb_num_coerce_bin(lhs, rhs, id_power); - oci_lc(OCINumberPower(oci8_errhp, _NUMBER(lhs), &n, &r)); + oci_lc(OCINumberPower(errhp, _NUMBER(lhs), &n, &r)); } - return oci8_make_ocinumber(&r); + return oci8_make_ocinumber(&r, errhp); } /* @@ -678,14 +699,15 @@ */ static VALUE onum_cmp(VALUE lhs, VALUE rhs) { + OCIError *errhp = oci8_errhp; OCINumber n; sword r; /* change to OCINumber */ - if (!set_oci_number_from_num(&n, rhs, 0)) + if (!set_oci_number_from_num(&n, rhs, 0, errhp)) return rb_num_coerce_cmp(lhs, rhs, id_cmp); /* compare */ - oci_lc(OCINumberCmp(oci8_errhp, _NUMBER(lhs), &n, &r)); + oci_lc(OCINumberCmp(errhp, _NUMBER(lhs), &n, &r)); if (r > 0) { return INT2FIX(1); } else if (r == 0) { @@ -703,10 +725,11 @@ */ static VALUE onum_floor(VALUE self) { + OCIError *errhp = oci8_errhp; OCINumber r; - oci_lc(OCINumberFloor(oci8_errhp, _NUMBER(self), &r)); - return oci8_make_integer(&r); + oci_lc(OCINumberFloor(errhp, _NUMBER(self), &r)); + return oci8_make_integer(&r, errhp); } /* @@ -718,10 +741,11 @@ */ static VALUE onum_ceil(VALUE self) { + OCIError *errhp = oci8_errhp; OCINumber r; - oci_lc(OCINumberCeil(oci8_errhp, _NUMBER(self), &r)); - return oci8_make_integer(&r); + oci_lc(OCINumberCeil(errhp, _NUMBER(self), &r)); + return oci8_make_integer(&r, errhp); } /* @@ -738,15 +762,16 @@ */ static VALUE onum_round(int argc, VALUE *argv, VALUE self) { + OCIError *errhp = oci8_errhp; VALUE decplace; OCINumber r; rb_scan_args(argc, argv, "01", &decplace /* 0 */); - oci_lc(OCINumberRound(oci8_errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r)); + oci_lc(OCINumberRound(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r)); if (argc == 0) { - return oci8_make_integer(&r); + return oci8_make_integer(&r, errhp); } else { - return oci8_make_ocinumber(&r); + return oci8_make_ocinumber(&r, errhp); } } @@ -760,12 +785,13 @@ */ static VALUE onum_trunc(int argc, VALUE *argv, VALUE self) { + OCIError *errhp = oci8_errhp; VALUE decplace; OCINumber r; rb_scan_args(argc, argv, "01", &decplace /* 0 */); - oci_lc(OCINumberTrunc(oci8_errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberTrunc(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -781,10 +807,11 @@ */ static VALUE onum_round_prec(VALUE self, VALUE ndigs) { + OCIError *errhp = oci8_errhp; OCINumber r; - oci_lc(OCINumberPrec(oci8_errhp, _NUMBER(self), NUM2INT(ndigs), &r)); - return oci8_make_ocinumber(&r); + oci_lc(OCINumberPrec(errhp, _NUMBER(self), NUM2INT(ndigs), &r)); + return oci8_make_ocinumber(&r, errhp); } /* @@ -797,6 +824,7 @@ */ static VALUE onum_to_char(int argc, VALUE *argv, VALUE self) { + OCIError *errhp = oci8_errhp; VALUE fmt; VALUE nls_params; char buf[512]; @@ -813,13 +841,13 @@ sword sign; boolean is_int; - oci_lc(OCINumberIsInt(oci8_errhp, _NUMBER(self), &is_int)); + oci_lc(OCINumberIsInt(errhp, _NUMBER(self), &is_int)); if (is_int) { fmt_ptr = NUMBER_FORMAT_INT; fmt_len = NUMBER_FORMAT_INT_LEN; } else { - oci_lc(OCINumberAbs(oci8_errhp, _NUMBER(self), &absval)); - oci_lc(OCINumberCmp(oci8_errhp, &absval, &const_shreshold, &sign)); + oci_lc(OCINumberAbs(errhp, _NUMBER(self), &absval)); + oci_lc(OCINumberCmp(errhp, &absval, &const_shreshold, &sign)); if (sign >= 0) { fmt_ptr = NUMBER_FORMAT2; fmt_len = NUMBER_FORMAT2_LEN; @@ -841,18 +869,18 @@ nls_params_ptr = RSTRING_ORATEXT(nls_params); nls_params_len = RSTRING_LEN(nls_params); } - rv = OCINumberToText(oci8_errhp, _NUMBER(self), + rv = OCINumberToText(errhp, _NUMBER(self), fmt_ptr, fmt_len, nls_params_ptr, nls_params_len, &buf_size, TO_ORATEXT(buf)); if (rv == OCI_ERROR) { sb4 errcode; - OCIErrorGet(oci8_errhp, 1, NULL, &errcode, NULL, 0, OCI_HTYPE_ERROR); + OCIErrorGet(errhp, 1, NULL, &errcode, NULL, 0, OCI_HTYPE_ERROR); if (errcode == 22065) { /* OCI-22065: number to text translation for the given format causes overflow */ if (NIL_P(fmt)) /* implicit conversion */ return rb_usascii_str_new_cstr("overflow"); } - oci8_raise(oci8_errhp, rv, NULL); + oci8_raise(errhp, rv, NULL); } return rb_usascii_str_new(buf, buf_size); } @@ -876,10 +904,11 @@ */ static VALUE onum_to_i(VALUE self) { + OCIError *errhp = oci8_errhp; OCINumber num; - oci_lc(OCINumberTrunc(oci8_errhp, _NUMBER(self), 0, &num)); - return oci8_make_integer(&num); + oci_lc(OCINumberTrunc(errhp, _NUMBER(self), 0, &num)); + return oci8_make_integer(&num, errhp); } /* @@ -891,9 +920,10 @@ */ static VALUE onum_to_f(VALUE self) { + OCIError *errhp = oci8_errhp; double dbl; - oci_lc(OCINumberToReal(oci8_errhp, _NUMBER(self), sizeof(dbl), &dbl)); + oci_lc(OCINumberToReal(errhp, _NUMBER(self), sizeof(dbl), &dbl)); return rb_float_new(dbl); } @@ -916,9 +946,10 @@ */ static VALUE onum_zero_p(VALUE self) { + OCIError *errhp = oci8_errhp; boolean result; - oci_lc(OCINumberIsZero(oci8_errhp, _NUMBER(self), &result)); + oci_lc(OCINumberIsZero(errhp, _NUMBER(self), &result)); return result ? Qtrue : Qfalse; } @@ -931,10 +962,11 @@ */ static VALUE onum_abs(VALUE self) { + OCIError *errhp = oci8_errhp; OCINumber result; - oci_lc(OCINumberAbs(oci8_errhp, _NUMBER(self), &result)); - return oci8_make_ocinumber(&result); + oci_lc(OCINumberAbs(errhp, _NUMBER(self), &result)); + return oci8_make_ocinumber(&result, errhp); } /* @@ -946,10 +978,11 @@ */ static VALUE onum_shift(VALUE self, VALUE exp) { + OCIError *errhp = oci8_errhp; OCINumber result; - oci_lc(OCINumberShift(oci8_errhp, _NUMBER(self), NUM2INT(exp), &result)); - return oci8_make_ocinumber(&result); + oci_lc(OCINumberShift(errhp, _NUMBER(self), NUM2INT(exp), &result)); + return oci8_make_ocinumber(&result, errhp); } static VALUE onum_hash(VALUE self) @@ -1018,7 +1051,7 @@ } memset(&num, 0, sizeof(num)); memcpy(&num, c, size); - return oci8_make_ocinumber(&num); + return oci8_make_ocinumber(&num, oci8_errhp); } /* @@ -1026,25 +1059,26 @@ */ static VALUE bind_ocinumber_get(oci8_bind_t *obind, void *data, void *null_struct) { - return oci8_make_ocinumber((OCINumber*)data); + return oci8_make_ocinumber((OCINumber*)data, oci8_errhp); } static VALUE bind_integer_get(oci8_bind_t *obind, void *data, void *null_struct) { - return oci8_make_integer((OCINumber*)data); + return oci8_make_integer((OCINumber*)data, oci8_errhp); } static void bind_ocinumber_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val) { - set_oci_number_from_num((OCINumber*)data, val, 1); + set_oci_number_from_num((OCINumber*)data, val, 1, oci8_errhp); } static void bind_integer_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val) { + OCIError *errhp = oci8_errhp; OCINumber num; - set_oci_number_from_num(&num, val, 1); - oci_lc(OCINumberTrunc(oci8_errhp, &num, 0, (OCINumber*)data)); + set_oci_number_from_num(&num, val, 1, errhp); + oci_lc(OCINumberTrunc(errhp, &num, 0, (OCINumber*)data)); } static void bind_ocinumber_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length) @@ -1055,10 +1089,11 @@ static void bind_ocinumber_init_elem(oci8_bind_t *obind, VALUE svc) { + OCIError *errhp = oci8_errhp; ub4 idx = 0; do { - OCINumberSetZero(oci8_errhp, (OCINumber*)obind->valuep + idx); + OCINumberSetZero(errhp, (OCINumber*)obind->valuep + idx); } while (++idx < obind->maxar_sz); } @@ -1095,7 +1130,7 @@ }; void -Init_oci_number(VALUE cOCI8) +Init_oci_number(VALUE cOCI8, OCIError *errhp) { VALUE mMath; OCINumber num1, num2; @@ -1111,27 +1146,27 @@ /* constants for internal use. */ /* set const_p1 */ sl = 1; - OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p1); + OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p1); /* set const_p10 */ sl = 10; - OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p10); + OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_p10); /* set const_m1 */ sl = -1; - OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_m1); + OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &const_m1); /* set const_PI2 */ sl = 2; - OCINumberSetPi(oci8_errhp, &num1); - OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &num2); - OCINumberDiv(oci8_errhp, &num1 /* PI */, &num2 /* 2 */, &const_PI2); + OCINumberSetPi(errhp, &num1); + OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &num2); + OCINumberDiv(errhp, &num1 /* PI */, &num2 /* 2 */, &const_PI2); /* set const_mPI2 */ - OCINumberNeg(oci8_errhp, &const_PI2 /* PI/2 */, &const_mPI2); + OCINumberNeg(errhp, &const_PI2 /* PI/2 */, &const_mPI2); /* set const_shreshold */ - OCINumberFromText(oci8_errhp, SHRESHOLD_VAL, SHRESHOLD_VAL_LEN, SHRESHOLD_FMT, SHRESHOLD_FMT_LEN, + OCINumberFromText(errhp, SHRESHOLD_VAL, SHRESHOLD_VAL_LEN, SHRESHOLD_FMT, SHRESHOLD_FMT_LEN, NULL, 0, &const_shreshold); /* PI */ - OCINumberSetPi(oci8_errhp, &num1); - obj_PI = oci8_make_ocinumber(&num1); + OCINumberSetPi(errhp, &num1); + obj_PI = oci8_make_ocinumber(&num1, errhp); /* The ratio of the circumference of a circle to its diameter. */ rb_define_const(mMath, "PI", obj_PI); From nobody at rubyforge.org Fri Apr 17 04:17:44 2009 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Fri, 17 Apr 2009 04:17:44 -0400 (EDT) Subject: [ruby-oci8-commit] [339] trunk/ruby-oci8: * ext/oci8/apiwrap.yml, ext/oci8/env.c, ext/oci8/ extconf.rb, Message-ID: <20090417081745.0D58516782A2@rubyforge.org> Revision: 339 Author: kubo Date: 2009-04-17 04:17:44 -0400 (Fri, 17 Apr 2009) Log Message: ----------- * ext/oci8/apiwrap.yml, ext/oci8/env.c, ext/oci8/extconf.rb, ext/oci8/oci8.h, ext/oci8/oci8lib.c: OCIEnv is initialized when it is needed. This makes a basis to enable an event notification after "require 'oci8'." * test/test_all.rb: fix a bug added four days ago. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/apiwrap.yml trunk/ruby-oci8/ext/oci8/env.c trunk/ruby-oci8/ext/oci8/extconf.rb trunk/ruby-oci8/ext/oci8/oci8.h trunk/ruby-oci8/ext/oci8/oci8lib.c trunk/ruby-oci8/test/test_all.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2009-04-14 11:58:26 UTC (rev 338) +++ trunk/ruby-oci8/ChangeLog 2009-04-17 08:17:44 UTC (rev 339) @@ -1,3 +1,10 @@ +2009-04-17 KUBO Takehiro + * ext/oci8/apiwrap.yml, ext/oci8/env.c, ext/oci8/extconf.rb, + ext/oci8/oci8.h, ext/oci8/oci8lib.c: OCIEnv is initialized + when it is needed. This makes a basis to enable an event + notification after "require 'oci8'." + * test/test_all.rb: fix a bug added four days ago. + 2009-04-14 KUBO Takehiro * ext/oci8/oci8.h, ext/oci8/oci8lib.c, ext/oci8/ocinumber.c, ext/oci8/metadata.c, ext/oci8/object.c: pass an OCIError to Modified: trunk/ruby-oci8/ext/oci8/apiwrap.yml =================================================================== --- trunk/ruby-oci8/ext/oci8/apiwrap.yml 2009-04-14 11:58:26 UTC (rev 338) +++ trunk/ruby-oci8/ext/oci8/apiwrap.yml 2009-04-17 08:17:44 UTC (rev 339) @@ -884,6 +884,18 @@ # Oracle 8.1 # +# round trip: 0 +OCIEnvCreate: + :version: 810 + :args: - OCIEnv **envp + - ub4 mode + - dvoid *ctxp + - dvoid *(*malocfp)(dvoid *ctxp, size_t size) + - dvoid *(*ralocfp)(dvoid *ctxp, dvoid *memptr, size_t newsize) + - void (*mfreefp)(dvoid *ctxp, dvoid *memptr) + - size_t xtramem_sz + - dvoid **usrmempp + # round trip: 1 OCILobClose_nb: :version: 810 Modified: trunk/ruby-oci8/ext/oci8/env.c =================================================================== --- trunk/ruby-oci8/ext/oci8/env.c 2009-04-14 11:58:26 UTC (rev 338) +++ trunk/ruby-oci8/ext/oci8/env.c 2009-04-17 08:17:44 UTC (rev 339) @@ -1,10 +1,9 @@ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */ /* - env.c - part of ruby-oci8 - - Copyright (C) 2002-2008 KUBO Takehiro - -*/ + * env.c - part of ruby-oci8 + * + * Copyright (C) 2002-2009 KUBO Takehiro + */ #include "oci8.h" #if !defined(RUBY_VM) @@ -12,8 +11,38 @@ #include #endif -OCIEnv *oci8_envhp; +#ifdef _WIN32 +#ifdef HAVE_RUBY_WIN32_H +#include /* for rb_w32_getenv() */ +#else +#include /* for rb_w32_getenv() */ +#endif +#endif + +#ifdef HAVE_RUBY_UTIL_H +#include +#endif + #ifdef RUBY_VM +ub4 oci8_env_mode = OCI_OBJECT | OCI_THREADED; +#else +ub4 oci8_env_mode = OCI_OBJECT; +#endif + +OCIEnv *oci8_global_envhp; + +OCIEnv *oci8_make_envhp(void) +{ + sword rv; + + rv = OCIEnvCreate(&oci8_global_envhp, oci8_env_mode, NULL, NULL, NULL, NULL, 0, NULL); + if (rv != OCI_SUCCESS) { + oci8_raise_init_error(); + } + return oci8_global_envhp; +} + +#ifdef RUBY_VM /* * oci8_errhp is a thread local object in ruby 1.9. */ @@ -53,17 +82,23 @@ /* * oci8_errhp is global in ruby 1.8. */ -OCIError *oci8_errhp; +OCIError *oci8_global_errhp; + +OCIError *oci8_make_errhp(void) +{ + sword rv; + + rv = OCIHandleAlloc(oci8_envhp, (dvoid *)&oci8_global_errhp, OCI_HTYPE_ERROR, 0, NULL); + if (rv != OCI_SUCCESS) + oci8_env_raise(oci8_envhp, rv); + return oci8_global_errhp; +} #endif void Init_oci8_env(void) { - sword rv; #ifdef RUBY_VM - ub4 mode = OCI_OBJECT | OCI_THREADED; int error; -#else - ub4 mode = OCI_OBJECT; #endif #if !defined(RUBY_VM) && !defined(_WIN32) @@ -85,23 +120,38 @@ } } #endif /* WIN32 */ - rv = OCIInitialize(mode, NULL, NULL, NULL, NULL); - if (rv != OCI_SUCCESS) { - oci8_raise_init_error(); + + /* workaround code. + * + * When ORACLE_HOME ends with '/' and the Oracle client is + * an instant client lower than 10.2.0.3, OCIEvnCreate() + * doesn't work even though the combination of OCIInitialize() + * and OCIEnvInit() works fine. Delete the last slash for + * a workaround. + */ + if (oracle_client_version < ORAVERNUM(10, 2, 0, 3, 0)) { +#ifdef _WIN32 +#define DIR_SEP '\\' +#else +#define DIR_SEP '/' +#endif + char *home = getenv("ORACLE_HOME"); + if (home != NULL) { + size_t homelen = strlen(home); + if (homelen > 0 && home[homelen - 1] == DIR_SEP) { + home = ruby_strdup(home); + home[homelen - 1] = '\0'; + ruby_setenv("ORACLE_HOME", home); + xfree(home); + } + } } - rv = OCIEnvInit(&oci8_envhp, OCI_DEFAULT, 0, NULL); - if (rv != OCI_SUCCESS) { - oci8_raise_init_error(); - } + #ifdef RUBY_VM id_thread_key = rb_intern("__oci8_errhp__"); error = oci8_tls_key_init(&oci8_tls_key); if (error != 0) { rb_raise(rb_eRuntimeError, "Cannot create thread local key (errno = %d)", error); } -#else /* RUBY_VM */ - rv = OCIHandleAlloc(oci8_envhp, (dvoid *)&oci8_errhp, OCI_HTYPE_ERROR, 0, NULL); - if (rv != OCI_SUCCESS) - oci8_env_raise(oci8_envhp, rv); #endif } Modified: trunk/ruby-oci8/ext/oci8/extconf.rb =================================================================== --- trunk/ruby-oci8/ext/oci8/extconf.rb 2009-04-14 11:58:26 UTC (rev 338) +++ trunk/ruby-oci8/ext/oci8/extconf.rb 2009-04-17 08:17:44 UTC (rev 339) @@ -103,7 +103,6 @@ have_header("intern.h") have_header("util.h") # ruby 1.9 headers -have_header("ruby/util.h") have_type('rb_encoding', ['ruby/ruby.h', 'ruby/encoding.h']) # $! in C API Modified: trunk/ruby-oci8/ext/oci8/oci8.h =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8.h 2009-04-14 11:58:26 UTC (rev 338) +++ trunk/ruby-oci8/ext/oci8/oci8.h 2009-04-17 08:17:44 UTC (rev 339) @@ -344,12 +344,24 @@ #define UB4_TO_NUM UINT2NUM #endif -/* env.c */ -extern OCIEnv *oci8_envhp; +/* The folloiwng macros oci8_envhp and oci8_errhp are used + * as if they are defined as follows: + * + * extern OCIEnv *oci8_envhp; + * extern OCIError *oci8_errhp; + */ +#define oci8_envhp (LIKELY(oci8_global_envhp != NULL) ? oci8_global_envhp : oci8_make_envhp()) #ifdef RUBY_VM -/* oci8_errhp is a thread local object in ruby 1.9. */ #define oci8_errhp oci8_get_errhp() +#else +#define oci8_errhp (LIKELY(oci8_global_errhp != NULL) ? oci8_global_errhp : oci8_make_errhp()) +#endif +/* env.c */ +extern ub4 oci8_env_mode; +extern OCIEnv *oci8_global_envhp; +OCIEnv *oci8_make_envhp(void); +#ifdef RUBY_VM extern oci8_tls_key_t oci8_tls_key; /* native thread key */ OCIError *oci8_make_errhp(void); @@ -360,8 +372,8 @@ } #else -/* oci8_errhp is global in ruby 1.8. */ -extern OCIError *oci8_errhp; +extern OCIError *oci8_global_errhp; +OCIError *oci8_make_errhp(void); #endif void Init_oci8_env(void); Modified: trunk/ruby-oci8/ext/oci8/oci8lib.c =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8lib.c 2009-04-14 11:58:26 UTC (rev 338) +++ trunk/ruby-oci8/ext/oci8/oci8lib.c 2009-04-17 08:17:44 UTC (rev 339) @@ -108,6 +108,9 @@ { VALUE cOCI8; VALUE obj; + OCIEnv *envhp; + OCIError *errhp; + sword rv; #ifdef RUNTIME_API_CHECK Init_oci8_apiwrap(); @@ -154,8 +157,35 @@ Init_oci8_metadata(cOCI8); Init_oci8_lob(cOCI8); + /* allocate a temporary errhp to pass Init_oci_number() */ + if (have_OCIEnvCreate) { + rv = OCIEnvCreate(&envhp, oci8_env_mode, NULL, NULL, NULL, NULL, 0, NULL); + if (rv != OCI_SUCCESS) { + oci8_raise_init_error(); + } + } else { + rv = OCIInitialize(oci8_env_mode, NULL, NULL, NULL, NULL); + if (rv != OCI_SUCCESS) { + oci8_raise_init_error(); + } + rv = OCIEnvInit(&oci8_global_envhp, OCI_DEFAULT, 0, NULL); + if (rv != OCI_SUCCESS) { + oci8_raise_init_error(); + } + } + rv = OCIHandleAlloc(envhp, (dvoid *)&errhp, OCI_HTYPE_ERROR, 0, NULL); + if (rv != OCI_SUCCESS) + oci8_env_raise(envhp, rv); + Init_oci_number(cOCI8, errhp); + OCIHandleFree(errhp, OCI_HTYPE_ERROR); + if (have_OCIEnvCreate) { + OCIHandleFree(envhp, OCI_HTYPE_ENV); + } else { + /* Delayed OCIEnv initialization cannot be used on Oracle 8.0. */ + oci8_global_envhp = envhp; + } + Init_ora_date(); - Init_oci_number(cOCI8, oci8_errhp); Init_oci_datetime(); Init_oci_object(cOCI8); Init_oci_xmldb(); @@ -167,6 +197,10 @@ #ifdef DEBUG_CORE_FILE signal(SIGSEGV, SIG_DFL); #endif + + if (have_OCIEnvCreate && oci8_global_envhp != NULL) { + rb_raise(rb_eRuntimeError, "Internal Error: OCIEnv should not be initialized here."); + } } VALUE oci8_define_class(const char *name, oci8_base_class_t *base_class) Modified: trunk/ruby-oci8/test/test_all.rb =================================================================== --- trunk/ruby-oci8/test/test_all.rb 2009-04-14 11:58:26 UTC (rev 338) +++ trunk/ruby-oci8/test/test_all.rb 2009-04-17 08:17:44 UTC (rev 339) @@ -33,7 +33,7 @@ require 'rubygems' require 'dbi' rescue LoadError - dbi_not_found = false + dbi_not_found = true end end unless dbi_not_found From nobody at rubyforge.org Fri Apr 17 07:49:38 2009 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Fri, 17 Apr 2009 07:49:38 -0400 (EDT) Subject: [ruby-oci8-commit] [340] trunk/ruby-oci8: * ext/oci8/encoding.c, ext/oci8/lob.c, ext/oci8/ metadata.c, Message-ID: <20090417114938.1F98618580FA@rubyforge.org> Revision: 340 Author: kubo Date: 2009-04-17 07:49:37 -0400 (Fri, 17 Apr 2009) Log Message: ----------- * ext/oci8/encoding.c, ext/oci8/lob.c, ext/oci8/metadata.c, ext/oci8/oci8.c: suppress "warning C4761: integral size mismatch in argument; conversion supplied" when compiled by Visual C++. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/encoding.c trunk/ruby-oci8/ext/oci8/lob.c trunk/ruby-oci8/ext/oci8/metadata.c trunk/ruby-oci8/ext/oci8/oci8.c Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2009-04-17 08:17:44 UTC (rev 339) +++ trunk/ruby-oci8/ChangeLog 2009-04-17 11:49:37 UTC (rev 340) @@ -1,4 +1,9 @@ 2009-04-17 KUBO Takehiro + * ext/oci8/encoding.c, ext/oci8/lob.c, ext/oci8/metadata.c, + ext/oci8/oci8.c: suppress "warning C4761: integral size mismatch + in argument; conversion supplied" when compiled by Visual C++. + +2009-04-17 KUBO Takehiro * ext/oci8/apiwrap.yml, ext/oci8/env.c, ext/oci8/extconf.rb, ext/oci8/oci8.h, ext/oci8/oci8lib.c: OCIEnv is initialized when it is needed. This makes a basis to enable an event Modified: trunk/ruby-oci8/ext/oci8/encoding.c =================================================================== --- trunk/ruby-oci8/ext/oci8/encoding.c 2009-04-17 08:17:44 UTC (rev 339) +++ trunk/ruby-oci8/ext/oci8/encoding.c 2009-04-17 11:49:37 UTC (rev 340) @@ -45,7 +45,7 @@ char buf[OCI_NLS_MAXBUFSZ]; sword rv; - rv = OCINlsCharSetIdToName(oci8_envhp, TO_ORATEXT(buf), sizeof(buf), FIX2INT(csid)); + rv = OCINlsCharSetIdToName(oci8_envhp, TO_ORATEXT(buf), sizeof(buf), (ub2)FIX2INT(csid)); if (rv != OCI_SUCCESS) { return Qnil; } Modified: trunk/ruby-oci8/ext/oci8/lob.c =================================================================== --- trunk/ruby-oci8/ext/oci8/lob.c 2009-04-17 08:17:44 UTC (rev 339) +++ trunk/ruby-oci8/ext/oci8/lob.c 2009-04-17 11:49:37 UTC (rev 340) @@ -495,9 +495,15 @@ oci8_lob_t *lob = DATA_PTR(self); bfile_close(lob); + if (RSTRING_LEN(dir_alias) > UB2MAXVAL) { + rb_raise(rb_eRuntimeError, "dir_alias is too long."); + } + if (RSTRING_LEN(filename) > UB2MAXVAL) { + rb_raise(rb_eRuntimeError, "filename is too long."); + } oci_lc(OCILobFileSetName(oci8_envhp, oci8_errhp, &lob->base.hp.lob, - RSTRING_ORATEXT(dir_alias), RSTRING_LEN(dir_alias), - RSTRING_ORATEXT(filename), RSTRING_LEN(filename))); + RSTRING_ORATEXT(dir_alias), (ub2)RSTRING_LEN(dir_alias), + RSTRING_ORATEXT(filename), (ub2)RSTRING_LEN(filename))); } static VALUE oci8_bfile_initialize(int argc, VALUE *argv, VALUE self) Modified: trunk/ruby-oci8/ext/oci8/metadata.c =================================================================== --- trunk/ruby-oci8/ext/oci8/metadata.c 2009-04-17 08:17:44 UTC (rev 339) +++ trunk/ruby-oci8/ext/oci8/metadata.c 2009-04-17 11:49:37 UTC (rev 340) @@ -277,7 +277,7 @@ oci_lc(OCIAttrSet(desc->hp.dschp, OCI_HTYPE_DESCRIBE, &val, 0, OCI_ATTR_DESC_PUBLIC, oci8_errhp)); } oci_lc(OCIDescribeAny_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, objptr, objlen, - objtype, OCI_DEFAULT, FIX2INT(type), desc->hp.dschp)); + 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)); return oci8_metadata_create(parmhp, self, obj); } Modified: trunk/ruby-oci8/ext/oci8/oci8.c =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8.c 2009-04-17 08:17:44 UTC (rev 339) +++ trunk/ruby-oci8/ext/oci8/oci8.c 2009-04-17 11:49:37 UTC (rev 340) @@ -538,11 +538,11 @@ if (have_OCIServerRelease) { /* Oracle 9i or later */ - oci_lc(OCIServerRelease(svcctx->base.hp.ptr, oci8_errhp, (text*)buf, sizeof(buf), svcctx->base.type, &version)); + 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), svcctx->base.type)); + 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 != ' ') { From nobody at rubyforge.org Sat Apr 18 08:52:21 2009 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 18 Apr 2009 08:52:21 -0400 (EDT) Subject: [ruby-oci8-commit] [341] trunk/ruby-oci8: * lib/oci8/oci8.rb: move OCI8:: BindType module to bindtype.rb. Message-ID: <20090418125221.B2E9E1598076@rubyforge.org> Revision: 341 Author: kubo Date: 2009-04-18 08:52:21 -0400 (Sat, 18 Apr 2009) Log Message: ----------- * lib/oci8/oci8.rb: move OCI8::BindType module to bindtype.rb. * lib/oci8/bindtype.rb: added. This defines OCI8::BindType. * lib/oci8.rb.in: require 'oci8/bindtype.rb' Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/lib/oci8/oci8.rb trunk/ruby-oci8/lib/oci8.rb.in Added Paths: ----------- trunk/ruby-oci8/lib/oci8/bindtype.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2009-04-17 11:49:37 UTC (rev 340) +++ trunk/ruby-oci8/ChangeLog 2009-04-18 12:52:21 UTC (rev 341) @@ -1,3 +1,8 @@ +2009-04-18 KUBO Takehiro + * lib/oci8/oci8.rb: move OCI8::BindType module to bindtype.rb. + * lib/oci8/bindtype.rb: added. This defines OCI8::BindType. + * lib/oci8.rb.in: require 'oci8/bindtype.rb' + 2009-04-17 KUBO Takehiro * ext/oci8/encoding.c, ext/oci8/lob.c, ext/oci8/metadata.c, ext/oci8/oci8.c: suppress "warning C4761: integral size mismatch Added: trunk/ruby-oci8/lib/oci8/bindtype.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/bindtype.rb (rev 0) +++ trunk/ruby-oci8/lib/oci8/bindtype.rb 2009-04-18 12:52:21 UTC (rev 341) @@ -0,0 +1,295 @@ +#-- +# bindtype.rb -- OCI8::BindType +# +# Copyright (C) 2009 KUBO Takehiro +#++ + +class OCI8 + module BindType + Mapping = {} + + class Base + def self.create(con, val, param, max_array_size) + self.new(con, val, param, max_array_size) + end + end + + # get/set Date + class Date < OCI8::BindType::OraDate + def set(val) + super(val && ::OraDate.new(val.year, val.mon, val.mday)) + end + def get() + (val = super()) && val.to_date + end + end + + # get/set Number (for OCI8::SQLT_NUM) + class Number + def self.create(con, val, param, max_array_size) + if param.is_a? OCI8::Metadata::Base + precision = param.precision + scale = param.scale + end + if scale == -127 + if precision == 0 + # NUMBER declared without its scale and precision. (Oracle 9.2.0.3 or above) + klass = OCI8::BindType::Mapping[:number_no_prec_setting] + else + # FLOAT or FLOAT(p) + klass = OCI8::BindType::Float + end + elsif scale == 0 + if precision == 0 + # NUMBER whose scale and precision is unknown + # or + # NUMBER declared without its scale and precision. (Oracle 9.2.0.2 or below) + klass = OCI8::BindType::Mapping[:number_unknown_prec] + else + # NUMBER(p, 0) + klass = OCI8::BindType::Integer + end + else + # NUMBER(p, s) + if precision < 15 # the precision of double. + klass = OCI8::BindType::Float + else + # use BigDecimal instead? + klass = OCI8::BindType::OraNumber + end + end + klass.new(con, val, nil, max_array_size) + end + end + + class String + # 1333 <= ceil(4000 / 3). 4000 is max size of char. 3 is NLS ratio of UTF-8. + @@minimum_bind_length = 1333 + + def self.minimum_bind_length + @@minimum_bind_length + end + + def self.minimum_bind_length=(val) + @@minimum_bind_length = val + end + + def self.create(con, val, param, max_array_size) + case param + when Hash + if param[:length] + # If length is passed explicitly, use it. + length = param[:length] + elsif val.is_a? String or (val.respond_to? :to_str and val = val.to_str) + if OCI8.respond_to? :encoding and OCI8.encoding != val.encoding + # If the string encoding is different with NLS_LANG character set, + # convert it to get the length. + val = val.encode(OCI8.encoding) + end + if val.respond_to? :bytesize + # ruby 1.8.7 or upper + length = val.bytesize + else + # ruby 1.8.6 or lower + length = val.size + end + end + when OCI8::Metadata::Base + case param.data_type + when :char, :varchar2 + length = param.data_size + # character size may become large on character set conversion. + # The length of a Japanese half-width kana is one in Shift_JIS, + # two in EUC-JP, three in UTF-8. + length *= 3 unless param.char_used? + when :raw + # HEX needs twice space. + length = param.data_size * 2 + end + end + length = @@minimum_bind_length if length.nil? or length < @@minimum_bind_length + self.new(con, val, length, max_array_size) + end + end + + class RAW + def self.create(con, val, param, max_array_size) + case param + when Hash + length = 400 # default length + if param[:length] + length = param[:length] + elsif val.respond_to? :to_str and val.to_str.size > length + length = val.to_str.size + end + when OCI8::Metadata::Base + length = param.data_size + end + self.new(con, val, length, max_array_size) + end + end + + class Long < OCI8::BindType::String + def self.create(con, val, param, max_array_size) + self.new(con, val, con.long_read_len, max_array_size) + end + end + + class LongRaw < OCI8::BindType::RAW + def self.create(con, val, param, max_array_size) + self.new(con, val, con.long_read_len, max_array_size) + end + end + + class CLOB + def self.create(con, val, param, max_array_size) + if param.is_a? OCI8::Metadata::Base and param.charset_form == :nchar + OCI8::BindType::NCLOB.new(con, val, nil, max_array_size) + else + OCI8::BindType::CLOB.new(con, val, nil, max_array_size) + end + end + end + end # BindType +end + +# bind or explicitly define +OCI8::BindType::Mapping[String] = OCI8::BindType::String +OCI8::BindType::Mapping[OraNumber] = OCI8::BindType::OraNumber +OCI8::BindType::Mapping[Fixnum] = OCI8::BindType::Integer +OCI8::BindType::Mapping[Float] = OCI8::BindType::Float +OCI8::BindType::Mapping[Integer] = OCI8::BindType::Integer +OCI8::BindType::Mapping[Bignum] = OCI8::BindType::Integer +OCI8::BindType::Mapping[OraDate] = OCI8::BindType::OraDate +OCI8::BindType::Mapping[Time] = OCI8::BindType::Time +OCI8::BindType::Mapping[Date] = OCI8::BindType::Date +OCI8::BindType::Mapping[DateTime] = OCI8::BindType::DateTime +OCI8::BindType::Mapping[OCI8::CLOB] = OCI8::BindType::CLOB +OCI8::BindType::Mapping[OCI8::NCLOB] = OCI8::BindType::NCLOB +OCI8::BindType::Mapping[OCI8::BLOB] = OCI8::BindType::BLOB +OCI8::BindType::Mapping[OCI8::BFILE] = OCI8::BindType::BFILE +OCI8::BindType::Mapping[OCI8::Cursor] = OCI8::BindType::Cursor + +# implicitly define + +# datatype type size prec scale +# ------------------------------------------------- +# CHAR(1) SQLT_AFC 1 0 0 +# CHAR(10) SQLT_AFC 10 0 0 +OCI8::BindType::Mapping[:char] = OCI8::BindType::String + +# datatype type size prec scale +# ------------------------------------------------- +# VARCHAR(1) SQLT_CHR 1 0 0 +# VARCHAR(10) SQLT_CHR 10 0 0 +# VARCHAR2(1) SQLT_CHR 1 0 0 +# VARCHAR2(10) SQLT_CHR 10 0 0 +OCI8::BindType::Mapping[:varchar2] = OCI8::BindType::String + +# datatype type size prec scale +# ------------------------------------------------- +# RAW(1) SQLT_BIN 1 0 0 +# RAW(10) SQLT_BIN 10 0 0 +OCI8::BindType::Mapping[:raw] = OCI8::BindType::RAW + +# datatype type size prec scale +# ------------------------------------------------- +# LONG SQLT_LNG 0 0 0 +OCI8::BindType::Mapping[:long] = OCI8::BindType::Long + +# datatype type size prec scale +# ------------------------------------------------- +# LONG RAW SQLT_LBI 0 0 0 +OCI8::BindType::Mapping[:long_raw] = OCI8::BindType::LongRaw + +# datatype type size prec scale +# ------------------------------------------------- +# CLOB SQLT_CLOB 4000 0 0 +OCI8::BindType::Mapping[:clob] = OCI8::BindType::CLOB +OCI8::BindType::Mapping[:nclob] = OCI8::BindType::NCLOB + +# datatype type size prec scale +# ------------------------------------------------- +# BLOB SQLT_BLOB 4000 0 0 +OCI8::BindType::Mapping[:blob] = OCI8::BindType::BLOB + +# datatype type size prec scale +# ------------------------------------------------- +# BFILE SQLT_BFILE 4000 0 0 +OCI8::BindType::Mapping[:bfile] = OCI8::BindType::BFILE + +# datatype type size prec scale +# ------------------------------------------------- +# DATE SQLT_DAT 7 0 0 +OCI8::BindType::Mapping[:date] = OCI8::BindType::Time + +if OCI8.oracle_client_version >= OCI8::ORAVER_9_0 + OCI8::BindType::Mapping[:timestamp] = OCI8::BindType::Time + OCI8::BindType::Mapping[:timestamp_tz] = OCI8::BindType::Time + OCI8::BindType::Mapping[:timestamp_ltz] = OCI8::BindType::Time + OCI8::BindType::Mapping[:interval_ym] = OCI8::BindType::IntervalYM + OCI8::BindType::Mapping[:interval_ds] = OCI8::BindType::IntervalDS +end + +# datatype type size prec scale +# ------------------------------------------------- +# ROWID SQLT_RDD 4 0 0 +OCI8::BindType::Mapping[:rowid] = OCI8::BindType::String + +# datatype type size prec scale +# ----------------------------------------------------- +# FLOAT SQLT_NUM 22 126 -127 +# FLOAT(1) SQLT_NUM 22 1 -127 +# FLOAT(126) SQLT_NUM 22 126 -127 +# DOUBLE PRECISION SQLT_NUM 22 126 -127 +# REAL SQLT_NUM 22 63 -127 +# NUMBER SQLT_NUM 22 0 0 +# NUMBER(1) SQLT_NUM 22 1 0 +# NUMBER(38) SQLT_NUM 22 38 0 +# NUMBER(1, 0) SQLT_NUM 22 1 0 +# NUMBER(38, 0) SQLT_NUM 22 38 0 +# NUMERIC SQLT_NUM 22 38 0 +# INT SQLT_NUM 22 38 0 +# INTEGER SQLT_NUM 22 38 0 +# SMALLINT SQLT_NUM 22 38 0 +OCI8::BindType::Mapping[:number] = OCI8::BindType::Number + +# mapping for calculated number values. +# +# for example: +# select col1 * 1.1 from tab1; +# +# For Oracle 9.2.0.2 or below, this is also used for NUMBER +# datatypes that have no explicit setting of their precision +# and scale. +# +# The default mapping is Float for ruby-oci8 1.0. It is OraNumber +# for ruby-oci8 2.0. +OCI8::BindType::Mapping[:number_unknown_prec] = OCI8::BindType::OraNumber + +# mapping for number without precision and scale. +# +# for example: +# create table tab1 (col1 number); +# select col1 from tab1; +# +# note: This is available only on Oracle 9.2.0.3 or above. +# see: Oracle 9.2.0.x Patch Set Notes. +# +# The default mapping is Float for ruby-oci8 1.0. It is OraNumber +# for ruby-oci8 2.0. +OCI8::BindType::Mapping[:number_no_prec_setting] = OCI8::BindType::OraNumber + +if defined? OCI8::BindType::BinaryDouble + OCI8::BindType::Mapping[:binary_float] = OCI8::BindType::BinaryDouble + OCI8::BindType::Mapping[:binary_double] = OCI8::BindType::BinaryDouble +else + OCI8::BindType::Mapping[:binary_float] = OCI8::BindType::Float + OCI8::BindType::Mapping[:binary_double] = OCI8::BindType::Float +end + +# Cursor +OCI8::BindType::Mapping[:cursor] = OCI8::BindType::Cursor + +# XMLType (This mapping will be changed before release.) +OCI8::BindType::Mapping[:xmltype] = OCI8::BindType::Long Modified: trunk/ruby-oci8/lib/oci8/oci8.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/oci8.rb 2009-04-17 11:49:37 UTC (rev 340) +++ trunk/ruby-oci8/lib/oci8/oci8.rb 2009-04-18 12:52:21 UTC (rev 341) @@ -1,5 +1,12 @@ -# --*- ruby -*-- -# This is based on yoshidam's oracle.rb. +#-- +# oci8.rb -- OCI8 and OCI8::Cursor +# +# Copyright (C) 2002-2009 KUBO Takehiro +# +# Original Copyright is: +# Oracle module for Ruby +# 1998-2000 by yoshidam +#++ require 'date' @@ -160,153 +167,6 @@ @oracle_server_version end - module BindType - Mapping = {} - - class Base - def self.create(con, val, param, max_array_size) - self.new(con, val, param, max_array_size) - end - end - - # get/set Date - class Date < OCI8::BindType::OraDate - def set(val) - super(val && ::OraDate.new(val.year, val.mon, val.mday)) - end - def get() - (val = super()) && val.to_date - end - end - - # get/set Number (for OCI8::SQLT_NUM) - class Number - def self.create(con, val, param, max_array_size) - if param.is_a? OCI8::Metadata::Base - precision = param.precision - scale = param.scale - end - if scale == -127 - if precision == 0 - # NUMBER declared without its scale and precision. (Oracle 9.2.0.3 or above) - klass = OCI8::BindType::Mapping[:number_no_prec_setting] - else - # FLOAT or FLOAT(p) - klass = OCI8::BindType::Float - end - elsif scale == 0 - if precision == 0 - # NUMBER whose scale and precision is unknown - # or - # NUMBER declared without its scale and precision. (Oracle 9.2.0.2 or below) - klass = OCI8::BindType::Mapping[:number_unknown_prec] - else - # NUMBER(p, 0) - klass = OCI8::BindType::Integer - end - else - # NUMBER(p, s) - if precision < 15 # the precision of double. - klass = OCI8::BindType::Float - else - # use BigDecimal instead? - klass = OCI8::BindType::OraNumber - end - end - klass.new(con, val, nil, max_array_size) - end - end - - class String - # 1333 <= ceil(4000 / 3). 4000 is max size of char. 3 is NLS ratio of UTF-8. - @@minimum_bind_length = 1333 - - def self.minimum_bind_length - @@minimum_bind_length - end - - def self.minimum_bind_length=(val) - @@minimum_bind_length = val - end - - def self.create(con, val, param, max_array_size) - case param - when Hash - if param[:length] - # If length is passed explicitly, use it. - length = param[:length] - elsif val.is_a? String or (val.respond_to? :to_str and val = val.to_str) - if OCI8.respond_to? :encoding and OCI8.encoding != val.encoding - # If the string encoding is different with NLS_LANG character set, - # convert it to get the length. - val = val.encode(OCI8.encoding) - end - if val.respond_to? :bytesize - # ruby 1.8.7 or upper - length = val.bytesize - else - # ruby 1.8.6 or lower - length = val.size - end - end - when OCI8::Metadata::Base - case param.data_type - when :char, :varchar2 - length = param.data_size - # character size may become large on character set conversion. - # The length of a Japanese half-width kana is one in Shift_JIS, - # two in EUC-JP, three in UTF-8. - length *= 3 unless param.char_used? - when :raw - # HEX needs twice space. - length = param.data_size * 2 - end - end - length = @@minimum_bind_length if length.nil? or length < @@minimum_bind_length - self.new(con, val, length, max_array_size) - end - end - - class RAW - def self.create(con, val, param, max_array_size) - case param - when Hash - length = 400 # default length - if param[:length] - length = param[:length] - elsif val.respond_to? :to_str and val.to_str.size > length - length = val.to_str.size - end - when OCI8::Metadata::Base - length = param.data_size - end - self.new(con, val, length, max_array_size) - end - end - - class Long < OCI8::BindType::String - def self.create(con, val, param, max_array_size) - self.new(con, val, con.long_read_len, max_array_size) - end - end - - class LongRaw < OCI8::BindType::RAW - def self.create(con, val, param, max_array_size) - self.new(con, val, con.long_read_len, max_array_size) - end - end - - class CLOB - def self.create(con, val, param, max_array_size) - if param.is_a? OCI8::Metadata::Base and param.charset_form == :nchar - OCI8::BindType::NCLOB.new(con, val, nil, max_array_size) - else - OCI8::BindType::CLOB.new(con, val, nil, max_array_size) - end - end - end - end # BindType - # The instance of this class corresponds to cursor in the term of # Oracle, which corresponds to java.sql.Statement of JDBC and statement # handle $sth of Perl/DBI. @@ -675,144 +535,3 @@ OraNumber.new(self, format, nls_params) end end - -# bind or explicitly define -OCI8::BindType::Mapping[String] = OCI8::BindType::String -OCI8::BindType::Mapping[OraNumber] = OCI8::BindType::OraNumber -OCI8::BindType::Mapping[Fixnum] = OCI8::BindType::Integer -OCI8::BindType::Mapping[Float] = OCI8::BindType::Float -OCI8::BindType::Mapping[Integer] = OCI8::BindType::Integer -OCI8::BindType::Mapping[Bignum] = OCI8::BindType::Integer -OCI8::BindType::Mapping[OraDate] = OCI8::BindType::OraDate -OCI8::BindType::Mapping[Time] = OCI8::BindType::Time -OCI8::BindType::Mapping[Date] = OCI8::BindType::Date -OCI8::BindType::Mapping[DateTime] = OCI8::BindType::DateTime -OCI8::BindType::Mapping[OCI8::CLOB] = OCI8::BindType::CLOB -OCI8::BindType::Mapping[OCI8::NCLOB] = OCI8::BindType::NCLOB -OCI8::BindType::Mapping[OCI8::BLOB] = OCI8::BindType::BLOB -OCI8::BindType::Mapping[OCI8::BFILE] = OCI8::BindType::BFILE -OCI8::BindType::Mapping[OCI8::Cursor] = OCI8::BindType::Cursor - -# implicitly define - -# datatype type size prec scale -# ------------------------------------------------- -# CHAR(1) SQLT_AFC 1 0 0 -# CHAR(10) SQLT_AFC 10 0 0 -OCI8::BindType::Mapping[:char] = OCI8::BindType::String - -# datatype type size prec scale -# ------------------------------------------------- -# VARCHAR(1) SQLT_CHR 1 0 0 -# VARCHAR(10) SQLT_CHR 10 0 0 -# VARCHAR2(1) SQLT_CHR 1 0 0 -# VARCHAR2(10) SQLT_CHR 10 0 0 -OCI8::BindType::Mapping[:varchar2] = OCI8::BindType::String - -# datatype type size prec scale -# ------------------------------------------------- -# RAW(1) SQLT_BIN 1 0 0 -# RAW(10) SQLT_BIN 10 0 0 -OCI8::BindType::Mapping[:raw] = OCI8::BindType::RAW - -# datatype type size prec scale -# ------------------------------------------------- -# LONG SQLT_LNG 0 0 0 -OCI8::BindType::Mapping[:long] = OCI8::BindType::Long - -# datatype type size prec scale -# ------------------------------------------------- -# LONG RAW SQLT_LBI 0 0 0 -OCI8::BindType::Mapping[:long_raw] = OCI8::BindType::LongRaw - -# datatype type size prec scale -# ------------------------------------------------- -# CLOB SQLT_CLOB 4000 0 0 -OCI8::BindType::Mapping[:clob] = OCI8::BindType::CLOB -OCI8::BindType::Mapping[:nclob] = OCI8::BindType::NCLOB - -# datatype type size prec scale -# ------------------------------------------------- -# BLOB SQLT_BLOB 4000 0 0 -OCI8::BindType::Mapping[:blob] = OCI8::BindType::BLOB - -# datatype type size prec scale -# ------------------------------------------------- -# BFILE SQLT_BFILE 4000 0 0 -OCI8::BindType::Mapping[:bfile] = OCI8::BindType::BFILE - -# datatype type size prec scale -# ------------------------------------------------- -# DATE SQLT_DAT 7 0 0 -OCI8::BindType::Mapping[:date] = OCI8::BindType::Time - -if OCI8.oracle_client_version >= OCI8::ORAVER_9_0 - OCI8::BindType::Mapping[:timestamp] = OCI8::BindType::Time - OCI8::BindType::Mapping[:timestamp_tz] = OCI8::BindType::Time - OCI8::BindType::Mapping[:timestamp_ltz] = OCI8::BindType::Time - OCI8::BindType::Mapping[:interval_ym] = OCI8::BindType::IntervalYM - OCI8::BindType::Mapping[:interval_ds] = OCI8::BindType::IntervalDS -end - -# datatype type size prec scale -# ------------------------------------------------- -# ROWID SQLT_RDD 4 0 0 -OCI8::BindType::Mapping[:rowid] = OCI8::BindType::String - -# datatype type size prec scale -# ----------------------------------------------------- -# FLOAT SQLT_NUM 22 126 -127 -# FLOAT(1) SQLT_NUM 22 1 -127 -# FLOAT(126) SQLT_NUM 22 126 -127 -# DOUBLE PRECISION SQLT_NUM 22 126 -127 -# REAL SQLT_NUM 22 63 -127 -# NUMBER SQLT_NUM 22 0 0 -# NUMBER(1) SQLT_NUM 22 1 0 -# NUMBER(38) SQLT_NUM 22 38 0 -# NUMBER(1, 0) SQLT_NUM 22 1 0 -# NUMBER(38, 0) SQLT_NUM 22 38 0 -# NUMERIC SQLT_NUM 22 38 0 -# INT SQLT_NUM 22 38 0 -# INTEGER SQLT_NUM 22 38 0 -# SMALLINT SQLT_NUM 22 38 0 -OCI8::BindType::Mapping[:number] = OCI8::BindType::Number - -# mapping for calculated number values. -# -# for example: -# select col1 * 1.1 from tab1; -# -# For Oracle 9.2.0.2 or below, this is also used for NUMBER -# datatypes that have no explicit setting of their precision -# and scale. -# -# The default mapping is Float for ruby-oci8 1.0. It is OraNumber -# for ruby-oci8 2.0. -OCI8::BindType::Mapping[:number_unknown_prec] = OCI8::BindType::OraNumber - -# mapping for number without precision and scale. -# -# for example: -# create table tab1 (col1 number); -# select col1 from tab1; -# -# note: This is available only on Oracle 9.2.0.3 or above. -# see: Oracle 9.2.0.x Patch Set Notes. -# -# The default mapping is Float for ruby-oci8 1.0. It is OraNumber -# for ruby-oci8 2.0. -OCI8::BindType::Mapping[:number_no_prec_setting] = OCI8::BindType::OraNumber - -if defined? OCI8::BindType::BinaryDouble - OCI8::BindType::Mapping[:binary_float] = OCI8::BindType::BinaryDouble - OCI8::BindType::Mapping[:binary_double] = OCI8::BindType::BinaryDouble -else - OCI8::BindType::Mapping[:binary_float] = OCI8::BindType::Float - OCI8::BindType::Mapping[:binary_double] = OCI8::BindType::Float -end - -# Cursor -OCI8::BindType::Mapping[:cursor] = OCI8::BindType::Cursor - -# XMLType (This mapping will be changed before release.) -OCI8::BindType::Mapping[:xmltype] = OCI8::BindType::Long Modified: trunk/ruby-oci8/lib/oci8.rb.in =================================================================== --- trunk/ruby-oci8/lib/oci8.rb.in 2009-04-17 11:49:37 UTC (rev 340) +++ trunk/ruby-oci8/lib/oci8.rb.in 2009-04-18 12:52:21 UTC (rev 341) @@ -71,6 +71,7 @@ require 'oci8/datetime.rb' require 'oci8/oci8.rb' +require 'oci8/bindtype.rb' require 'oci8/metadata.rb' require 'oci8/compat.rb' require 'oci8/object.rb'