From nobody at rubyforge.org Fri Dec 2 22:47:59 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Fri, 2 Dec 2011 22:47:59 -0500 (EST) Subject: [ruby-oci8-commit] [469] trunk/ruby-oci8: fix some issues on compilation. Message-ID: <20111203034800.1061B1D78108@rubyforge.org> Revision: 469 Author: kubo Date: 2011-12-02 22:47:59 -0500 (Fri, 02 Dec 2011) Log Message: ----------- fix some issues on compilation. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/apiwrap.yml trunk/ruby-oci8/ext/oci8/oraconf.rb trunk/ruby-oci8/lib/oci8/connection_pool.rb trunk/ruby-oci8/lib/oci8/properties.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-11-27 06:23:24 UTC (rev 468) +++ trunk/ruby-oci8/ChangeLog 2011-12-03 03:47:59 UTC (rev 469) @@ -1,3 +1,10 @@ +2011-12-03 KUBO Takehiro + * ext/oci8/apiwrap.yml: fix for run-time Oracle function checking. + * ext/oci8/oraconf.rb: fix a bug not to compile for full client on + Windows. The bug was caused by the commit at 2011-10-17. + * lib/oci8/connection_pool.rb, lib/oci8/properties.rb: fix rdoc + comments. + 2011-11-27 KUBO Takehiro * test/test_break.rb: fix test_timeout test for an Oracle server on Windows. Modified: trunk/ruby-oci8/ext/oci8/apiwrap.yml =================================================================== --- trunk/ruby-oci8/ext/oci8/apiwrap.yml 2011-11-27 06:23:24 UTC (rev 468) +++ trunk/ruby-oci8/ext/oci8/apiwrap.yml 2011-12-03 03:47:59 UTC (rev 469) @@ -373,7 +373,7 @@ - ub1 csfrm # round trip: 1 -OCILogoff_nb: +OCILogoff: :version: 800 :args: - OCISvcCtx *svchp @@ -817,7 +817,7 @@ - CONST OCIRaw *raw # round trip: 1 -OCISessionEnd_nb: +OCISessionEnd: :version: 800 :args: - OCISvcCtx *svchp @@ -836,7 +836,7 @@ - ub4 mode # round trip: 1 -OCIServerDetach_nb: +OCIServerDetach: :version: 800 :args: - OCIServer *srvhp @@ -945,6 +945,14 @@ - ub4 flags # round trip: 1 +OCITransRollback: + :version: 800 + :args: + - OCISvcCtx *svchp + - OCIError *errhp + - ub4 flags + +# round trip: 1 OCITransRollback_nb: :version: 800 :args: Modified: trunk/ruby-oci8/ext/oci8/oraconf.rb =================================================================== --- trunk/ruby-oci8/ext/oci8/oraconf.rb 2011-11-27 06:23:24 UTC (rev 468) +++ trunk/ruby-oci8/ext/oci8/oraconf.rb 2011-12-03 03:47:59 UTC (rev 469) @@ -641,12 +641,12 @@ if RUBY_PLATFORM =~ /mswin32|cygwin|mingw32|bccwin32/ # when Windows - def get_libs(base_dir = oci_base_dir) + def get_libs(lib_dir) case RUBY_PLATFORM when /cygwin/ open("OCI.def", "w") do |f| f.puts("EXPORTS") - open("|nm #{base_dir}/LIB/MSVC/OCI.LIB") do |r| + open("|nm #{lib_dir}/MSVC/OCI.LIB") do |r| while line = r.gets f.puts($') if line =~ / T _/ end @@ -661,21 +661,21 @@ when /bccwin32/ # replace '/' to '\\' because bcc linker misunderstands # 'C:/foo/bar/OCI.LIB' as unknown option. - lib = "#{base_dir}/LIB/BORLAND/OCI.LIB" + lib = "#{lib_dir}/BORLAND/OCI.LIB" return lib.tr('/', '\\') if File.exist?(lib) raise < integer # - # Returns the number of busy connections. + # Returns the number of busy physical connections. def busy_count attr_get_ub4(OCI_ATTR_CONN_BUSY_COUNT) end @@ -62,7 +81,7 @@ # call-seq: # open_count -> integer # - # Returns the number of open connections. + # Returns the number of open physical connections. def open_count attr_get_ub4(OCI_ATTR_CONN_OPEN_COUNT) end @@ -70,7 +89,7 @@ # call-seq: # min -> integer # - # Returns the number of minimum connections. + # Returns the number of minimum physical connections. def min attr_get_ub4(OCI_ATTR_CONN_MIN) end @@ -78,7 +97,7 @@ # call-seq: # max -> integer # - # Returns the number of maximum connections. + # Returns the number of maximum physical connections. def max attr_get_ub4(OCI_ATTR_CONN_MAX) end Modified: trunk/ruby-oci8/lib/oci8/properties.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/properties.rb 2011-11-27 06:23:24 UTC (rev 468) +++ trunk/ruby-oci8/lib/oci8/properties.rb 2011-12-03 03:47:59 UTC (rev 469) @@ -51,6 +51,7 @@ # Supported properties are listed below: # # [:length_semantics] + # (new in 2.1.0) # +:char+ when Oracle character length is counted by the number of characters. # +:byte+ when it is counted by the number of bytes. # The default setting is +:byte+ because +:char+ causes unexpected behaviour on From nobody at rubyforge.org Fri Dec 2 23:33:33 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Fri, 2 Dec 2011 23:33:33 -0500 (EST) Subject: [ruby-oci8-commit] [470] trunk/ruby-oci8: Use Gem::Command.build_args to get arguments after ' --'. Message-ID: <20111203043333.319DF1858300@rubyforge.org> Revision: 470 Author: kubo Date: 2011-12-02 23:33:32 -0500 (Fri, 02 Dec 2011) Log Message: ----------- Use Gem::Command.build_args to get arguments after '--'. This may solve issues #4 at http://github.com/kubo/ruby-oci8. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ruby-oci8.gemspec Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-03 03:47:59 UTC (rev 469) +++ trunk/ruby-oci8/ChangeLog 2011-12-03 04:33:32 UTC (rev 470) @@ -1,4 +1,8 @@ 2011-12-03 KUBO Takehiro + * ruby-oci8.gemspec: Use Gem::Command.build_args to get arguments + after '--'. This may solve issues #4 at http://github.com/kubo/ruby-oci8. + +2011-12-03 KUBO Takehiro * ext/oci8/apiwrap.yml: fix for run-time Oracle function checking. * ext/oci8/oraconf.rb: fix a bug not to compile for full client on Windows. The bug was caused by the commit at 2011-10-17. Modified: trunk/ruby-oci8/ruby-oci8.gemspec =================================================================== --- trunk/ruby-oci8/ruby-oci8.gemspec 2011-12-03 03:47:59 UTC (rev 469) +++ trunk/ruby-oci8/ruby-oci8.gemspec 2011-12-03 04:33:32 UTC (rev 470) @@ -8,10 +8,17 @@ # require 'fileutils' -if ARGV.size > 3 - gem_platform = ARGV[3] +build_args = if (defined? Gem::Command and Gem::Command.respond_to? :build_args) + Gem::Command.build_args + else + # for old rubygems + ARGV.include?("--") ? ARGV[(ARGV.index("--") + 1)...ARGV.size] : [] + end + +if build_args.size > 0 + gem_platform = build_args[0] else - gem_platform = Gem::Platform::RUBY + gem_platform = Gem::Platform::RUBY end spec = Gem::Specification.new do |s| From nobody at rubyforge.org Sat Dec 3 00:16:14 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 3 Dec 2011 00:16:14 -0500 (EST) Subject: [ruby-oci8-commit] [471] trunk/ruby-oci8: Check object type availability by querying all_objects data dictionary. Message-ID: <20111203051614.1AF081858300@rubyforge.org> Revision: 471 Author: kubo Date: 2011-12-03 00:16:13 -0500 (Sat, 03 Dec 2011) Log Message: ----------- Check object type availability by querying all_objects data dictionary. Fix #3 at http://github.com/kubo/ruby-oci8. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/test/test_metadata.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-03 04:33:32 UTC (rev 470) +++ trunk/ruby-oci8/ChangeLog 2011-12-03 05:16:13 UTC (rev 471) @@ -1,4 +1,8 @@ 2011-12-03 KUBO Takehiro + * test/test_metadata.rb: Check object type availability by querying + all_objects data dictionary. Fix #3 at http://github.com/kubo/ruby-oci8. + +2011-12-03 KUBO Takehiro * ruby-oci8.gemspec: Use Gem::Command.build_args to get arguments after '--'. This may solve issues #4 at http://github.com/kubo/ruby-oci8. Modified: trunk/ruby-oci8/test/test_metadata.rb =================================================================== --- trunk/ruby-oci8/test/test_metadata.rb 2011-12-03 04:33:32 UTC (rev 470) +++ trunk/ruby-oci8/test/test_metadata.rb 2011-12-03 05:16:13 UTC (rev 471) @@ -59,8 +59,18 @@ @table = hash end - def oraver - @table[:oraver] + def available?(conn) + return false if $oracle_version < @table[:oraver] + if /^(\w+)\.(\w+)$/ =~ @table[:data_type_string] + if conn.select_one('select 1 from all_objects where owner = :1 and object_name = :2', $1, $2) + true + else + warn "skip a test for unsupported datatype: #{@table[:data_type_string]}." + false + end + else + true + end end end @@ -1360,7 +1370,7 @@ end coldef = @@column_test_data.find_all do |c| - $oracle_version >= c.oraver + c.available?(@conn) end drop_table('test_table') From nobody at rubyforge.org Sat Dec 3 03:55:11 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 3 Dec 2011 03:55:11 -0500 (EST) Subject: [ruby-oci8-commit] [472] trunk/ruby-oci8: fix to pass a connection pool test. Message-ID: <20111203085512.017E81858300@rubyforge.org> Revision: 472 Author: kubo Date: 2011-12-03 03:55:11 -0500 (Sat, 03 Dec 2011) Log Message: ----------- fix to pass a connection pool test. OCI8::ConnectionPool#open_count after decrement depends on Oracle version. (reported by Yasuo Honda) Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/test/test_connection_pool.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-03 05:16:13 UTC (rev 471) +++ trunk/ruby-oci8/ChangeLog 2011-12-03 08:55:11 UTC (rev 472) @@ -1,10 +1,17 @@ 2011-12-03 KUBO Takehiro + * test/test_connection_pool.rb: fix to pass a connection pool test. + OCI8::ConnectionPool#open_count after decrement depends on + Oracle version. (reported by Yasuo Honda) + +2011-12-03 KUBO Takehiro * test/test_metadata.rb: Check object type availability by querying all_objects data dictionary. Fix #3 at http://github.com/kubo/ruby-oci8. + (reported by Yasuo Honda) 2011-12-03 KUBO Takehiro * ruby-oci8.gemspec: Use Gem::Command.build_args to get arguments after '--'. This may solve issues #4 at http://github.com/kubo/ruby-oci8. + (reported by jbirdjavi) 2011-12-03 KUBO Takehiro * ext/oci8/apiwrap.yml: fix for run-time Oracle function checking. Modified: trunk/ruby-oci8/test/test_connection_pool.rb =================================================================== --- trunk/ruby-oci8/test/test_connection_pool.rb 2011-12-03 05:16:13 UTC (rev 471) +++ trunk/ruby-oci8/test/test_connection_pool.rb 2011-12-03 08:55:11 UTC (rev 472) @@ -33,18 +33,19 @@ end def check_busy_and_open_count(min_cnt, max_cnt, incr_cnt) + msg = "create_pool(#{min_cnt}, #{max_cnt}, #{incr_cnt})" # Create a connection pool. pool = create_pool(min_cnt, max_cnt, incr_cnt) - assert_equal(min_cnt, pool.open_count) - assert_equal(0, pool.busy_count) + assert_equal(min_cnt, pool.open_count, msg) + assert_equal(0, pool.busy_count, msg) # Create connections from the pool. conns = [] max_cnt.times do conns << OCI8.new($dbuser, $dbpass, pool) end - assert_equal(min_cnt, pool.open_count) - assert_equal(0, pool.busy_count) + assert_equal(min_cnt, pool.open_count, msg) + assert_equal(0, pool.busy_count, msg) # Execute blocking SQL statements sequentially. max_cnt.times do |n| @@ -52,12 +53,12 @@ conns[n].exec "BEGIN DBMS_LOCK.SLEEP(1); END;" end sleep(0.5) - assert_equal(min_cnt, pool.open_count) - assert_equal(1, pool.busy_count) + assert_equal(min_cnt, pool.open_count, msg) + assert_equal(1, pool.busy_count, msg) thread.join end - assert_equal(min_cnt, pool.open_count) - assert_equal(0, pool.busy_count) + assert_equal(min_cnt, pool.open_count, msg) + assert_equal(0, pool.busy_count, msg) # Execute blocking SQL statements parallel to increment open_count. threads = [] @@ -67,8 +68,8 @@ end end sleep(0.5) - assert_equal(min_cnt + incr_cnt, pool.open_count) - assert_equal(min_cnt + 1, pool.busy_count) + assert_equal(min_cnt + incr_cnt, pool.open_count, msg) + assert_equal(min_cnt + 1, pool.busy_count, msg) # Execute blocking SQL statements parallel up to maximum. (min_cnt + 1).upto(max_cnt - 1) do |n| @@ -77,36 +78,34 @@ end end sleep(0.5) - assert_equal(max_cnt, pool.open_count) - assert_equal(max_cnt, pool.busy_count) + assert_equal(max_cnt, pool.open_count, msg) + assert_equal(max_cnt, pool.busy_count, msg) # threads.each do |thr| thr.join end - assert_equal(max_cnt, pool.open_count) - assert_equal(0, pool.busy_count) + assert_equal(max_cnt, pool.open_count, msg) + assert_equal(0, pool.busy_count, msg) # Set timeout pool.timeout = 1 sleep(1.5) - assert_equal(max_cnt, pool.open_count) # open_count doesn't shrink. - assert_equal(0, pool.busy_count) + assert_equal(max_cnt, pool.open_count, msg) # open_count doesn't shrink. + assert_equal(0, pool.busy_count, msg) conns[0].ping # make a network roundtrip. sleep(0.5) - expected_cnt = max_cnt - while expected_cnt - incr_cnt > min_cnt - expected_cnt -= incr_cnt - end - assert_equal(expected_cnt, pool.open_count) # open_count shrinks. - assert_equal(0, pool.busy_count) + # open_count shrinks. + # The decrement count depends on Oracle version. + assert_operator(pool.open_count, :<, max_cnt, msg) + assert_equal(0, pool.busy_count, msg) # Close all conections. conns.each do | conn | conn.logoff end - assert_equal(min_cnt, pool.open_count) - assert_equal(0, pool.busy_count) + assert_equal(min_cnt, pool.open_count, msg) + assert_equal(0, pool.busy_count, msg) end def test_nowait From nobody at rubyforge.org Sat Dec 3 03:57:15 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 3 Dec 2011 03:57:15 -0500 (EST) Subject: [ruby-oci8-commit] [473] trunk/ruby-oci8: fix to work with ruby 2.0. Message-ID: <20111203085715.AC3E51858300@rubyforge.org> Revision: 473 Author: kubo Date: 2011-12-03 03:57:15 -0500 (Sat, 03 Dec 2011) Log Message: ----------- fix to work with ruby 2.0. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/lib/oci8.rb.in Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-03 08:55:11 UTC (rev 472) +++ trunk/ruby-oci8/ChangeLog 2011-12-03 08:57:15 UTC (rev 473) @@ -1,4 +1,7 @@ 2011-12-03 KUBO Takehiro + * lib/oci8.rb.in: fix to work with ruby 2.0. + +2011-12-03 KUBO Takehiro * test/test_connection_pool.rb: fix to pass a connection pool test. OCI8::ConnectionPool#open_count after decrement depends on Oracle version. (reported by Yasuo Honda) Modified: trunk/ruby-oci8/lib/oci8.rb.in =================================================================== --- trunk/ruby-oci8/lib/oci8.rb.in 2011-12-03 08:55:11 UTC (rev 472) +++ trunk/ruby-oci8/lib/oci8.rb.in 2011-12-03 08:57:15 UTC (rev 473) @@ -28,7 +28,7 @@ # 191 - ruby 1.9.1 and 1.9.2 # 19x - ruby 1.9.x future version which will break the API compatibility case RUBY_VERSION -when /^1\.9/ +when /^1\.9/, /^2\.0/ so_basename += '191' when /^1\.8/ so_basename += '18' From nobody at rubyforge.org Sun Dec 4 02:35:20 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sun, 4 Dec 2011 02:35:20 -0500 (EST) Subject: [ruby-oci8-commit] [474] trunk/ruby-oci8: add tests for bind_string_as_nchar property. Message-ID: <20111204073520.2D34C185837A@rubyforge.org> Revision: 474 Author: kubo Date: 2011-12-04 02:35:19 -0500 (Sun, 04 Dec 2011) Log Message: ----------- add tests for bind_string_as_nchar property. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/metadata.c trunk/ruby-oci8/lib/oci8/metadata.rb trunk/ruby-oci8/lib/oci8/oci8.rb trunk/ruby-oci8/test/config.rb trunk/ruby-oci8/test/test_encoding.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-03 08:57:15 UTC (rev 473) +++ trunk/ruby-oci8/ChangeLog 2011-12-04 07:35:19 UTC (rev 474) @@ -1,3 +1,11 @@ +2011-12-04 KUBO Takehiro + * test/config.rb, test/test_encoding.rb: add tests for bind_string_as_nchar + property. + * ext/oci8/metadata.c, lib/oci8/metadata.rb: delete the internally used + OCI8::Metadata::Base#__charset_name method. + * lib/oci8/oci8.rb: add OCI8#database_charset_name. (added to test + bind_string_as_nchar.) + 2011-12-03 KUBO Takehiro * lib/oci8.rb.in: fix to work with ruby 2.0. Modified: trunk/ruby-oci8/ext/oci8/metadata.c =================================================================== --- trunk/ruby-oci8/ext/oci8/metadata.c 2011-12-03 08:57:15 UTC (rev 473) +++ trunk/ruby-oci8/ext/oci8/metadata.c 2011-12-04 07:35:19 UTC (rev 474) @@ -109,13 +109,6 @@ return oci8_metadata_create(value, md->svc, self); } -static VALUE metadata_get_charset_name(VALUE self, VALUE charset_id) -{ - oci8_metadata_t *md = DATA_PTR(self); - - return oci8_charset_id2name(md->svc, charset_id); -} - static VALUE metadata_get_con(VALUE self) { oci8_metadata_t *md = DATA_PTR(self); @@ -222,7 +215,6 @@ rb_define_singleton_method(cOCI8MetadataBase, "register_ptype", metadata_s_register_ptype, 1); rb_define_private_method(cOCI8MetadataBase, "__param", metadata_get_param, 1); rb_define_private_method(cOCI8MetadataBase, "__param_at", metadata_get_param_at, 1); - rb_define_private_method(cOCI8MetadataBase, "__charset_name", metadata_get_charset_name, 1); rb_define_private_method(cOCI8MetadataBase, "__con", metadata_get_con, 0); rb_define_private_method(cOCI8MetadataBase, "__is_implicit?", metadata_is_implicit_p, 0); Modified: trunk/ruby-oci8/lib/oci8/metadata.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/metadata.rb 2011-12-03 08:57:15 UTC (rev 473) +++ trunk/ruby-oci8/lib/oci8/metadata.rb 2011-12-04 07:35:19 UTC (rev 474) @@ -1060,7 +1060,7 @@ # character set name if the type attribute is of a string/character type. def charset_name - __charset_name(charset_id) + __con.charset_id2name(charset_id) end def inspect # :nodoc: Modified: trunk/ruby-oci8/lib/oci8/oci8.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/oci8.rb 2011-12-03 08:57:15 UTC (rev 473) +++ trunk/ruby-oci8/lib/oci8/oci8.rb 2011-12-04 07:35:19 UTC (rev 474) @@ -333,6 +333,16 @@ @oracle_server_version end + # :call-seq: + # database_charset_name -> string + # + # (new in 2.1.0) + # + # Returns the database character set name. + def database_charset_name + charset_id2name(server_handle.send(:attr_get_ub2, OCI_ATTR_CHARSET_ID)) + end + # 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. Modified: trunk/ruby-oci8/test/config.rb =================================================================== --- trunk/ruby-oci8/test/config.rb 2011-12-03 08:57:15 UTC (rev 473) +++ trunk/ruby-oci8/test/config.rb 2011-12-04 07:35:19 UTC (rev 474) @@ -5,6 +5,9 @@ $dbpass = "oci8" $dbname = nil +# for test_bind_string_as_nchar in test_encoding.rb +ENV['ORA_NCHAR_LITERAL_REPLACE'] = 'TRUE' if OCI8.encoding.name == "UTF-8" + # test_clob.rb nls_lang = ENV['NLS_LANG'] Modified: trunk/ruby-oci8/test/test_encoding.rb =================================================================== --- trunk/ruby-oci8/test/test_encoding.rb 2011-12-03 08:57:15 UTC (rev 473) +++ trunk/ruby-oci8/test/test_encoding.rb 2011-12-04 07:35:19 UTC (rev 474) @@ -45,9 +45,9 @@ assert_equal("\xab\xcd", (data = row[6].read), 'BLOB') assert_equal(ascii_8bit, data.encoding); - if OCI8.encoding.name == "UTF-8" - utf_8 = "\u00A1\u00A2\u00A3\u00A4\u00A5\u00A6\u00A7\u00A8\u00A9" - iso_8859_1 = utf_8.encode("ISO-8859-1") + if OCI8.encoding.name == "UTF-8" and ['WE8ISO8859P1', 'WE8ISO8859P15', 'AL32UTF8', 'UTF8'].include? @conn.database_charset_name + utf_8 = "\u00A1\u00A2\u00A3\u00A5\u00A7\u00A9" + iso_8859_1 = utf_8.encode("ISO-8859-15") # CLOB lob = row[4] lob.rewind @@ -66,11 +66,15 @@ lob.write(iso_8859_1) # written without encoding conversion lob.rewind assert_equal(iso_8859_1.force_encoding('ASCII-8BIT'), lob.read) + else + warn "Skip some asserts because the database character set is neither WE8ISO8859P1, WE8ISO8859P15, AL32UTF8 nor UTF8." if OCI8.encoding.name == "UTF-8" end end drop_table('test_table') end + warn "Skip some tests which runs only when NLS_CHARACTERSETS is unicode." if OCI8.encoding.name != "UTF-8" + if OCI8.encoding.name == "UTF-8" def test_bind_string_with_code_conversion drop_table('test_table') @@ -92,6 +96,37 @@ end drop_table('test_table') end + + def test_bind_string_as_nchar + if ['AL32UTF8', 'UTF8', 'ZHS32GB18030'].include? @conn.database_charset_name + warn "Skip test_bind_string_as_nchar. It needs Oracle server whose database chracter set is incompatible with unicode." + else + drop_table('test_table') + @conn.exec("CREATE TABLE test_table (ID NUMBER(5), V VARCHAR2(10), NV1 NVARCHAR2(10), NV2 NVARCHAR2(10))") + + test_data = "a\u00A1\u3042" + orig_prop = OCI8.properties[:bind_string_as_nchar] + begin + OCI8.properties[:bind_string_as_nchar] = false + @conn.exec("INSERT INTO test_table VALUES (1, N'#{test_data}', N'#{test_data}', :1)", test_data) + v, nv1, nv2 = @conn.select_one('select V, NV1, NV2 from test_table where ID = 1') + assert_not_equal(test_data, v) # Some UTF-8 chracters should be garbled. + assert_equal(test_data, nv1) # No garbled characters + assert_equal(v, nv2) # Garbled as VARCHAR2 column. + + OCI8.properties[:bind_string_as_nchar] = true + @conn.exec("INSERT INTO test_table VALUES (2, N'#{test_data}', N'#{test_data}', :1)", test_data) + v, nv1, nv2 = @conn.select_one('select V, NV1, NV2 from test_table where ID = 2') + assert_not_equal(test_data, v) # Some UTF-8 chracters should be garbled. + assert_equal(test_data, nv1) # No garbled characters + assert_equal(nv1, nv2) # Same as NVARCHAR2. + + @conn.commit + ensure + OCI8.properties[:bind_string_as_nchar] = orig_prop + end + end + end end def teardown From nobody at rubyforge.org Mon Dec 5 07:08:51 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Mon, 5 Dec 2011 07:08:51 -0500 (EST) Subject: [ruby-oci8-commit] [475] trunk/ruby-oci8: Add a test for OCI8.properties[:lenght_semantics]. Message-ID: <20111205120851.B1408177994E@rubyforge.org> Revision: 475 Author: kubo Date: 2011-12-05 07:08:51 -0500 (Mon, 05 Dec 2011) Log Message: ----------- Add a test for OCI8.properties[:lenght_semantics]. Add OCI8.client_charset_name. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/lib/oci8/encoding-init.rb trunk/ruby-oci8/lib/oci8/oci8.rb trunk/ruby-oci8/lib/oci8/properties.rb trunk/ruby-oci8/test/config.rb trunk/ruby-oci8/test/test_all.rb trunk/ruby-oci8/test/test_encoding.rb Added Paths: ----------- trunk/ruby-oci8/test/test_bind_string.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-04 07:35:19 UTC (rev 474) +++ trunk/ruby-oci8/ChangeLog 2011-12-05 12:08:51 UTC (rev 475) @@ -1,3 +1,12 @@ +2011-12-05 KUBO Takehiro + * lib/oci8/encoding-init.rb, lib/oci8/oci8.rb: add OCI8.client_charset_name. + * test/config.rb: use OCI8.client_charset_name instead of OCI8.encoding. + Ruby-oci8 compiled for ruby 1.8 doesn't has the latter. + * lib/oci8/properties.rb, test/test_all.rb, test/test_bind_string.rb, + test/test_encoding.rb: add a test for OCI8.properties[:lenght_semantics] + and move the test for OCI8.properties[:bind_string_as_nchar] from + test/test_encoding.rb to test/test_bind_string.rb. + 2011-12-04 KUBO Takehiro * test/config.rb, test/test_encoding.rb: add tests for bind_string_as_nchar property. Modified: trunk/ruby-oci8/lib/oci8/encoding-init.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/encoding-init.rb 2011-12-04 07:35:19 UTC (rev 474) +++ trunk/ruby-oci8/lib/oci8/encoding-init.rb 2011-12-05 12:08:51 UTC (rev 475) @@ -2,73 +2,76 @@ # setup default OCI encoding from NLS_LANG. # -# get the environment variable NLS_LANG. -nls_lang = ENV['NLS_LANG'] +class OCI8 -if nls_lang.is_a? String and nls_lang.length == 0 - nls_lang = nil -end + # get the environment variable NLS_LANG. + nls_lang = ENV['NLS_LANG'] -# if NLS_LANG is not set, get it from the Windows registry. -if nls_lang.nil? and defined? OCI8::Win32Util - dll_path = OCI8::Win32Util.dll_path.upcase - if dll_path =~ %r{\\BIN\\OCI.DLL} - oracle_home = $` - OCI8::Win32Util.enum_homes do |home, lang| - if oracle_home == home.upcase - nls_lang = lang - break + if nls_lang.is_a? String and nls_lang.length == 0 + nls_lang = nil + end + + # if NLS_LANG is not set, get it from the Windows registry. + if nls_lang.nil? and defined? OCI8::Win32Util + dll_path = OCI8::Win32Util.dll_path.upcase + if dll_path =~ %r{\\BIN\\OCI.DLL} + oracle_home = $` + OCI8::Win32Util.enum_homes do |home, lang| + if oracle_home == home.upcase + nls_lang = lang + break + end end end end -end -# extract the charset name. -if nls_lang - if nls_lang =~ /\.([[:alnum:]]+)$/ - charset = $1.upcase + # extract the charset name. + if nls_lang + if nls_lang =~ /\.([[:alnum:]]+)$/ + @@client_charset_name = $1.upcase + else + raise "Invalid NLS_LANG format: #{nls_lang}" + end else - raise "Invalid NLS_LANG format: #{nls_lang}" + warn "Warning: NLS_LANG is not set. fallback to US7ASCII." + @@client_charset_name = 'US7ASCII' end -else - warn "Warning: NLS_LANG is not set. fallback to US7ASCII." - charset = 'US7ASCII' -end -# NLS ratio, maximum number of bytes per one chracter -case charset -when 'UTF8' - OCI8.nls_ratio = 3 -when 'AL16UTF16' - OCI8.nls_ratio = 4 -when /^[[:alpha:]]+(\d+)/ - # convert maximum number of bits per one chracter to NLS ratio. - # charset name max bits max bytes - # ------------ -------- --------- - # US7ASCII 7 1 - # WE8ISO8859P1 8 1 - # JA16SJIS 16 2 - # AL32UTF8 32 4 - # ... - OCI8.nls_ratio = (($1.to_i + 7) >> 3) -else - raise "Unknown NLS character set name format: #{charset}" -end + # NLS ratio, maximum number of bytes per one chracter + case @@client_charset_name + when 'UTF8' + OCI8.nls_ratio = 3 + when 'AL16UTF16' + OCI8.nls_ratio = 4 + when /^[[:alpha:]]+(\d+)/ + # convert maximum number of bits per one chracter to NLS ratio. + # charset name max bits max bytes + # ------------ -------- --------- + # US7ASCII 7 1 + # WE8ISO8859P1 8 1 + # JA16SJIS 16 2 + # AL32UTF8 32 4 + # ... + OCI8.nls_ratio = (($1.to_i + 7) >> 3) + else + raise "Unknown NLS character set name format: #{@@client_charset_name}" + end -# Ruby encoding name for ruby 1.9. -if OCI8.respond_to? :encoding - if defined? DEFAULT_OCI8_ENCODING - enc = DEFAULT_OCI8_ENCODING - else - require 'yaml' - enc = YAML::load_file(File.dirname(__FILE__) + '/encoding.yml')[charset] - if enc.nil? - raise "Ruby encoding name is not found in encoding.yml for NLS_LANG #{nls_lang}." + # Ruby encoding name for ruby 1.9. + if OCI8.respond_to? :encoding + if defined? DEFAULT_OCI8_ENCODING + enc = DEFAULT_OCI8_ENCODING + else + require 'yaml' + enc = YAML::load_file(File.dirname(__FILE__) + '/encoding.yml')[@@client_charset_name] + if enc.nil? + raise "Ruby encoding name is not found in encoding.yml for NLS_LANG #{nls_lang}." + end + if enc.is_a? Array + # Use the first available encoding in the array. + enc = enc.find do |e| Encoding.find(e) rescue false; end + end end - if enc.is_a? Array - # Use the first available encoding in the array. - enc = enc.find do |e| Encoding.find(e) rescue false; end - end + OCI8.encoding = enc end - OCI8.encoding = enc end Modified: trunk/ruby-oci8/lib/oci8/oci8.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/oci8.rb 2011-12-04 07:35:19 UTC (rev 474) +++ trunk/ruby-oci8/lib/oci8/oci8.rb 2011-12-05 12:08:51 UTC (rev 475) @@ -343,6 +343,16 @@ charset_id2name(server_handle.send(:attr_get_ub2, OCI_ATTR_CHARSET_ID)) end + # :call-seq: + # OCI8.client_charset_name -> string + # + # (new in 2.1.0) + # + # Returns the client character set name. + def self.client_charset_name + @@client_charset_name + end + # 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. Modified: trunk/ruby-oci8/lib/oci8/properties.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/properties.rb 2011-12-04 07:35:19 UTC (rev 474) +++ trunk/ruby-oci8/lib/oci8/properties.rb 2011-12-05 12:08:51 UTC (rev 475) @@ -19,7 +19,7 @@ raise IndexError, "No such property name: #{name}" unless @@properties.has_key?(name) case name when :length_semantic - if val != :byte and val != char + if val != :byte and val != :char raise ArgumentError, "Invalid property value #{val} for :length_semantics." end when :bind_string_as_nchar Modified: trunk/ruby-oci8/test/config.rb =================================================================== --- trunk/ruby-oci8/test/config.rb 2011-12-04 07:35:19 UTC (rev 474) +++ trunk/ruby-oci8/test/config.rb 2011-12-05 12:08:51 UTC (rev 475) @@ -6,7 +6,7 @@ $dbname = nil # for test_bind_string_as_nchar in test_encoding.rb -ENV['ORA_NCHAR_LITERAL_REPLACE'] = 'TRUE' if OCI8.encoding.name == "UTF-8" +ENV['ORA_NCHAR_LITERAL_REPLACE'] = 'TRUE' if OCI8.client_charset_name.include? 'UTF8' # test_clob.rb Modified: trunk/ruby-oci8/test/test_all.rb =================================================================== --- trunk/ruby-oci8/test/test_all.rb 2011-12-04 07:35:19 UTC (rev 474) +++ trunk/ruby-oci8/test/test_all.rb 2011-12-05 12:08:51 UTC (rev 475) @@ -6,6 +6,7 @@ require "#{srcdir}/test_oradate" require "#{srcdir}/test_oranumber" +require "#{srcdir}/test_bind_string" require "#{srcdir}/test_bind_time" require "#{srcdir}/test_bind_raw" if $test_clob Added: trunk/ruby-oci8/test/test_bind_string.rb =================================================================== --- trunk/ruby-oci8/test/test_bind_string.rb (rev 0) +++ trunk/ruby-oci8/test/test_bind_string.rb 2011-12-05 12:08:51 UTC (rev 475) @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +require 'oci8' +require 'test/unit' +require File.dirname(__FILE__) + '/config' + +class TestBindString < Test::Unit::TestCase + def setup + @conn = get_oci8_connection + end + + def teardown + @conn.logoff + end + + if OCI8.client_charset_name.include? 'UTF8' + + def test_bind_string_as_nchar + if ['AL32UTF8', 'UTF8', 'ZHS32GB18030'].include? @conn.database_charset_name + warn "Skip test_bind_string_as_nchar. It needs Oracle server whose database chracter set is incompatible with unicode." + else + drop_table('test_table') + @conn.exec("CREATE TABLE test_table (ID NUMBER(5), V VARCHAR2(10), NV1 NVARCHAR2(10), NV2 NVARCHAR2(10))") + + orig_prop = OCI8.properties[:bind_string_as_nchar] + begin + utf8_string = "a??" + + OCI8.properties[:bind_string_as_nchar] = false + @conn.exec("INSERT INTO test_table VALUES (1, N'#{utf8_string}', N'#{utf8_string}', :1)", utf8_string) + v, nv1, nv2 = @conn.select_one('select V, NV1, NV2 from test_table where ID = 1') + assert_not_equal(utf8_string, v) # Some UTF-8 chracters should be garbled. + assert_equal(utf8_string, nv1) # No garbled characters + assert_equal(v, nv2) # Garbled as VARCHAR2 column. + + OCI8.properties[:bind_string_as_nchar] = true + @conn.exec("INSERT INTO test_table VALUES (2, N'#{utf8_string}', N'#{utf8_string}', :1)", utf8_string) + v, nv1, nv2 = @conn.select_one('select V, NV1, NV2 from test_table where ID = 2') + assert_not_equal(utf8_string, v) # Some UTF-8 chracters should be garbled. + assert_equal(utf8_string, nv1) # No garbled characters + assert_equal(nv1, nv2) # Same as NVARCHAR2. + + @conn.commit + ensure + OCI8.properties[:bind_string_as_nchar] = orig_prop + end + end + end + + def test_length_semantics # This test needs to be revised. + orig_prop = OCI8.properties[:length_semantics] + begin + utf8_string = "a??" + + OCI8.properties[:length_semantics] = :byte + assert_equal(:byte, OCI8.properties[:length_semantics]) + cursor = @conn.parse < Revision: 476 Author: kubo Date: 2011-12-05 08:23:21 -0500 (Mon, 05 Dec 2011) Log Message: ----------- add OCI8.properties[:time_zone] and use ENV['TZ'] or the time_zone propery to set Oracle session time zone. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/lib/oci8/oci8.rb trunk/ruby-oci8/lib/oci8/properties.rb trunk/ruby-oci8/test/test_datetime.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-05 12:08:51 UTC (rev 475) +++ trunk/ruby-oci8/ChangeLog 2011-12-05 13:23:21 UTC (rev 476) @@ -1,4 +1,9 @@ 2011-12-05 KUBO Takehiro + * lib/oci8/oci8.rb, lib/oci8/properties.rb, test/test_datetime.rb. + add OCI8.properties[:time_zone] and use ENV['TZ'] or the time_zone + propery to set Oracle session time zone. + +2011-12-05 KUBO Takehiro * lib/oci8/encoding-init.rb, lib/oci8/oci8.rb: add OCI8.client_charset_name. * test/config.rb: use OCI8.client_charset_name instead of OCI8.encoding. Ruby-oci8 compiled for ruby 1.8 doesn't has the latter. Modified: trunk/ruby-oci8/lib/oci8/oci8.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/oci8.rb 2011-12-05 12:08:51 UTC (rev 475) +++ trunk/ruby-oci8/lib/oci8/oci8.rb 2011-12-05 13:23:21 UTC (rev 476) @@ -140,6 +140,9 @@ @prefetch_rows = nil @username = nil + + time_zone = OCI8.properties[:time_zone] || ENV['TZ'] + exec("alter session set time_zone = '#{time_zone}'") if time_zone and time_zone.length > 0 end # call-seq: Modified: trunk/ruby-oci8/lib/oci8/properties.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/properties.rb 2011-12-05 12:08:51 UTC (rev 475) +++ trunk/ruby-oci8/lib/oci8/properties.rb 2011-12-05 13:23:21 UTC (rev 476) @@ -5,6 +5,7 @@ class OCI8 @@properties = { + :time_zone => nil, :length_semantics => :byte, :bind_string_as_nchar => false, :float_conversion_type => :ruby, @@ -18,6 +19,8 @@ def @@properties.[]=(name, val) raise IndexError, "No such property name: #{name}" unless @@properties.has_key?(name) case name + when :time_zone + raise TypeError, "invalid property type #{val.class}" unless val.nil? or val.is_a? String when :length_semantic if val != :byte and val != :char raise ArgumentError, "Invalid property value #{val} for :length_semantics." @@ -50,8 +53,17 @@ # # Supported properties are listed below: # + # [:time_zone] + # (new in 2.1.0) + # + # If your application runs in a time zone which adopt daylight saving time, + # you should set the environment variable TZ or this +time_zone+ property. + # Otherwise, Oracle session time zone is set with current constant + # offset from GMT. + # # [:length_semantics] # (new in 2.1.0) + # # +:char+ when Oracle character length is counted by the number of characters. # +:byte+ when it is counted by the number of bytes. # The default setting is +:byte+ because +:char+ causes unexpected behaviour on @@ -63,9 +75,14 @@ # # [:float_conversion_type] # (new in 2.1.0) - # Specifies who converts decimal to float and vice versa. - # It should be either +:ruby+ or +:oracle+. The default value - # is +:ruby+. + # + # +:ruby+ when Oracle decimal numbers are converted to ruby Float values + # same as Float#to_s does. (default) + # +:oracle:+ when they are done by Oracle OCI functions. + # + # From ruby 1.9.2, a float value converted from Oracle number 15.7 by + # the Oracle function OCINumberToReal() makes a string representation + # 15.700000000000001 by Float#to_s. # See: http://rubyforge.org/forum/forum.php?thread_id=50030&forum_id=1078 # def self.properties Modified: trunk/ruby-oci8/test/test_datetime.rb =================================================================== --- trunk/ruby-oci8/test/test_datetime.rb 2011-12-05 12:08:51 UTC (rev 475) +++ trunk/ruby-oci8/test/test_datetime.rb 2011-12-05 13:23:21 UTC (rev 476) @@ -579,4 +579,34 @@ end end end + + def test_time_zone_property + orig_prop = OCI8.properties[:time_zone] + orig_env = ENV['TZ'] + conn = nil + begin + assert_raise(TypeError) do + OCI8.properties[:time_zone] = 1 + end + + OCI8.properties[:time_zone] = 'America/New_York' + ENV['TZ'] = nil + conn = get_oci8_connection + assert_equal('America/New_York', conn.select_one('select sessiontimezone from dual')[0]) + conn.logoff + conn = nil + + OCI8.properties[:time_zone] = nil + ENV['TZ'] = 'Europe/Riga' + conn = get_oci8_connection + assert_equal('Europe/Riga', conn.select_one('select sessiontimezone from dual')[0]) + conn.logoff + conn = nil + + ensure + conn.logoff if conn + OCI8.properties[:time_zone] = orig_prop + ENV['TZ'] = orig_env + end + end end # TestOCI8 From nobody at rubyforge.org Mon Dec 5 08:25:24 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Mon, 5 Dec 2011 08:25:24 -0500 (EST) Subject: [ruby-oci8-commit] [477] trunk/ruby-oci8/ChangeLog: Message-ID: <20111205132524.F1C271779951@rubyforge.org> Revision: 477 Author: kubo Date: 2011-12-05 08:25:24 -0500 (Mon, 05 Dec 2011) Log Message: ----------- Modified Paths: -------------- trunk/ruby-oci8/ChangeLog Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-05 13:23:21 UTC (rev 476) +++ trunk/ruby-oci8/ChangeLog 2011-12-05 13:25:24 UTC (rev 477) @@ -2,6 +2,8 @@ * lib/oci8/oci8.rb, lib/oci8/properties.rb, test/test_datetime.rb. add OCI8.properties[:time_zone] and use ENV['TZ'] or the time_zone propery to set Oracle session time zone. + Fix #3 at http://github.com/kubo/ruby-oci8. + (reported by Yasuo Honda) 2011-12-05 KUBO Takehiro * lib/oci8/encoding-init.rb, lib/oci8/oci8.rb: add OCI8.client_charset_name. From nobody at rubyforge.org Tue Dec 6 06:10:34 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Tue, 6 Dec 2011 06:10:34 -0500 (EST) Subject: [ruby-oci8-commit] [478] trunk/ruby-oci8: raise a RuntimeError when non-blocking mode is set to a connection allocated from OCI8 ::ConnectionPool on ruby 1.8. Message-ID: <20111206111035.5A8361D782A1@rubyforge.org> Revision: 478 Author: kubo Date: 2011-12-06 06:10:34 -0500 (Tue, 06 Dec 2011) Log Message: ----------- raise a RuntimeError when non-blocking mode is set to a connection allocated from OCI8::ConnectionPool on ruby 1.8. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/oci8.c trunk/ruby-oci8/test/test_connection_pool.rb trunk/ruby-oci8/test/test_oranumber.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-05 13:25:24 UTC (rev 477) +++ trunk/ruby-oci8/ChangeLog 2011-12-06 11:10:34 UTC (rev 478) @@ -1,3 +1,10 @@ +2011-12-06 KUBO Takehiro + * ext/oci8/oci8.c: raise a RuntimeError when non-blocking mode is set to a connection + allocated from OCI8::ConnectionPool on ruby 1.8. + Ruby 1.9.x and rubinius don't have the limitation. + * test/test_connection_pool.rb: fix for ruby 1.8. + * test/test_oranumber.rb: fix for ruby 1.9.1 and 1.8. + 2011-12-05 KUBO Takehiro * lib/oci8/oci8.rb, lib/oci8/properties.rb, test/test_datetime.rb. add OCI8.properties[:time_zone] and use ENV['TZ'] or the time_zone @@ -2,3 +9,3 @@ propery to set Oracle session time zone. - Fix #3 at http://github.com/kubo/ruby-oci8. + Fix #2 at http://github.com/kubo/ruby-oci8. (reported by Yasuo Honda) Modified: trunk/ruby-oci8/ext/oci8/oci8.c =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8.c 2011-12-05 13:25:24 UTC (rev 477) +++ trunk/ruby-oci8/ext/oci8/oci8.c 2011-12-06 11:10:34 UTC (rev 478) @@ -33,6 +33,7 @@ #define OCI8_STATE_SESSION_BEGIN_WAS_CALLED 0x01 #define OCI8_STATE_SERVER_ATTACH_WAS_CALLED 0x02 +#define OCI8_STATE_CPOOL 0x04 static VALUE cOCI8; static VALUE cSession; @@ -446,9 +447,10 @@ * * Attachs to the server by the OCI function OCIServerAttach(). */ -static VALUE oci8_server_attach(VALUE self, VALUE dbname, VALUE mode) +static VALUE oci8_server_attach(VALUE self, VALUE dbname, VALUE attach_mode) { oci8_svcctx_t *svcctx = oci8_get_svcctx(self); + ub4 mode = NUM2UINT(attach_mode); if (svcctx->logoff_strategy != &complex_logoff) { rb_raise(rb_eRuntimeError, "Use this method only for the service context handle created by OCI8#server_handle()."); @@ -461,19 +463,21 @@ if (!NIL_P(dbname)) { OCI8SafeStringValue(dbname); } - Check_Type(mode, T_FIXNUM); /* attach to the server */ chker2(OCIServerAttach_nb(svcctx, svcctx->srvhp, oci8_errhp, NIL_P(dbname) ? NULL : RSTRING_ORATEXT(dbname), NIL_P(dbname) ? 0 : RSTRING_LEN(dbname), - FIX2UINT(mode)), + mode), &svcctx->base); chker2(OCIAttrSet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, svcctx->srvhp, 0, OCI_ATTR_SERVER, oci8_errhp), &svcctx->base); svcctx->state |= OCI8_STATE_SERVER_ATTACH_WAS_CALLED; + if (mode & OCI_CPOOL) { + svcctx->state |= OCI8_STATE_CPOOL; + } return self; } @@ -630,6 +634,9 @@ #else sb1 non_blocking; + if (svcctx->state & OCI8_STATE_CPOOL) { + rb_raise(rb_eRuntimeError, "Could not set non-blocking mode to a connection allocated from OCI8::ConnectionPool."); + } chker2(OCIAttrGet(svcctx->srvhp, OCI_HTYPE_SERVER, &non_blocking, 0, OCI_ATTR_NONBLOCKING_MODE, oci8_errhp), &svcctx->base); if ((RTEST(val) && !non_blocking) || (!RTEST(val) && non_blocking)) { /* toggle blocking / non-blocking. */ Modified: trunk/ruby-oci8/test/test_connection_pool.rb =================================================================== --- trunk/ruby-oci8/test/test_connection_pool.rb 2011-12-05 13:25:24 UTC (rev 477) +++ trunk/ruby-oci8/test/test_connection_pool.rb 2011-12-06 11:10:34 UTC (rev 478) @@ -39,10 +39,22 @@ assert_equal(min_cnt, pool.open_count, msg) assert_equal(0, pool.busy_count, msg) + non_blocking = true + # Create connections from the pool. conns = [] - max_cnt.times do - conns << OCI8.new($dbuser, $dbpass, pool) + max_cnt.times do |cnt| + conn = OCI8.new($dbuser, $dbpass, pool) + if cnt == 0 + unless conn.non_blocking? + non_blocking = false + assert_raise(RuntimeError) do + # This should raise "Could not set non-blocking mode to a connection allocated from OCI8::ConnectionPool." + conn.non_blocking = true + end + end + end + conns << conn end assert_equal(min_cnt, pool.open_count, msg) assert_equal(0, pool.busy_count, msg) @@ -54,7 +66,7 @@ end sleep(0.5) assert_equal(min_cnt, pool.open_count, msg) - assert_equal(1, pool.busy_count, msg) + assert_equal(non_blocking ? 1 : 0, pool.busy_count, msg) thread.join end assert_equal(min_cnt, pool.open_count, msg) @@ -68,8 +80,8 @@ end end sleep(0.5) - assert_equal(min_cnt + incr_cnt, pool.open_count, msg) - assert_equal(min_cnt + 1, pool.busy_count, msg) + assert_equal(non_blocking ? (min_cnt + incr_cnt) : min_cnt, pool.open_count, msg) + assert_equal(non_blocking ? (min_cnt + 1) : 0, pool.busy_count, msg) # Execute blocking SQL statements parallel up to maximum. (min_cnt + 1).upto(max_cnt - 1) do |n| @@ -78,20 +90,20 @@ end end sleep(0.5) - assert_equal(max_cnt, pool.open_count, msg) - assert_equal(max_cnt, pool.busy_count, msg) + assert_equal(non_blocking ? max_cnt : min_cnt, pool.open_count, msg) + assert_equal(non_blocking ? max_cnt : 0, pool.busy_count, msg) # threads.each do |thr| thr.join end - assert_equal(max_cnt, pool.open_count, msg) + assert_equal(non_blocking ? max_cnt : min_cnt, pool.open_count, msg) assert_equal(0, pool.busy_count, msg) # Set timeout pool.timeout = 1 sleep(1.5) - assert_equal(max_cnt, pool.open_count, msg) # open_count doesn't shrink. + assert_equal(non_blocking ? max_cnt : min_cnt, pool.open_count, msg) # open_count doesn't shrink. assert_equal(0, pool.busy_count, msg) conns[0].ping # make a network roundtrip. sleep(0.5) Modified: trunk/ruby-oci8/test/test_oranumber.rb =================================================================== --- trunk/ruby-oci8/test/test_oranumber.rb 2011-12-05 13:25:24 UTC (rev 477) +++ trunk/ruby-oci8/test/test_oranumber.rb 2011-12-06 11:10:34 UTC (rev 478) @@ -760,15 +760,25 @@ end cursor.close # Ruby Float -> Oracle Number - cursor = conn.parse('begin :out := :in; end;') - cursor.bind_param(:in, nil, Float) - cursor.bind_param(:out, nil, String, 50) LARGE_RANGE_VALUES.each do |n| - cursor[:in] = n.to_f - cursor.exec - assert_equal(n.to_f, cursor[:out].to_f) + float_val = n.to_f + expected_val = float_val.to_s + # convert + if /(-?)(\d).(\d+)e([+-]?\d+)/ =~ expected_val + sign = $1 + int = $2 + frac = $3 + shift = $4.to_i + if frac.length <= shift + expected_val = sign + int + frac + '0' * (shift - frac.length) + elsif shift < 0 + expected_val = sign + '0.' + '0' * (-shift - 1) + int + frac + expected_val.gsub!(/0+$/, '') + end + end + expected_val.gsub!(/\.0$/, '') + assert_equal(expected_val, OraNumber(float_val).to_s, "n = #{n}, float_val.to_s = #{float_val.to_s}") end - cursor.close ensure OCI8.properties[:float_conversion_type] = orig conn.logoff From nobody at rubyforge.org Tue Dec 6 07:50:43 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Tue, 6 Dec 2011 07:50:43 -0500 (EST) Subject: [ruby-oci8-commit] [479] trunk/ruby-oci8/dist-files: add a new file. Message-ID: <20111206125043.F155D1858386@rubyforge.org> Revision: 479 Author: kubo Date: 2011-12-06 07:50:43 -0500 (Tue, 06 Dec 2011) Log Message: ----------- add a new file. Modified Paths: -------------- trunk/ruby-oci8/dist-files Modified: trunk/ruby-oci8/dist-files =================================================================== --- trunk/ruby-oci8/dist-files 2011-12-06 11:10:34 UTC (rev 478) +++ trunk/ruby-oci8/dist-files 2011-12-06 12:50:43 UTC (rev 479) @@ -66,6 +66,7 @@ test/test_appinfo.rb test/test_array_dml.rb test/test_bind_raw.rb +test/test_bind_string.rb test/test_bind_time.rb test/test_break.rb test/test_clob.rb From nobody at rubyforge.org Tue Dec 6 07:56:44 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Tue, 6 Dec 2011 07:56:44 -0500 (EST) Subject: [ruby-oci8-commit] [480] trunk/ruby-oci8/dist-files: add a new file. Message-ID: <20111206125644.F0F651858386@rubyforge.org> Revision: 480 Author: kubo Date: 2011-12-06 07:56:44 -0500 (Tue, 06 Dec 2011) Log Message: ----------- add a new file. Modified Paths: -------------- trunk/ruby-oci8/dist-files Modified: trunk/ruby-oci8/dist-files =================================================================== --- trunk/ruby-oci8/dist-files 2011-12-06 12:50:43 UTC (rev 479) +++ trunk/ruby-oci8/dist-files 2011-12-06 12:56:44 UTC (rev 480) @@ -70,6 +70,7 @@ test/test_bind_time.rb test/test_break.rb test/test_clob.rb +test/test_connection_pool.rb test/test_connstr.rb test/test_encoding.rb test/test_datetime.rb From nobody at rubyforge.org Sat Dec 10 00:50:41 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 10 Dec 2011 00:50:41 -0500 (EST) Subject: [ruby-oci8-commit] [481] trunk/ruby-oci8: fix test_select when TZ set to daylight saving time. Message-ID: <20111210055041.D97801678364@rubyforge.org> Revision: 481 Author: kubo Date: 2011-12-10 00:50:41 -0500 (Sat, 10 Dec 2011) Log Message: ----------- fix test_select when TZ set to daylight saving time. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/test/test_oci8.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-06 12:56:44 UTC (rev 480) +++ trunk/ruby-oci8/ChangeLog 2011-12-10 05:50:41 UTC (rev 481) @@ -1,3 +1,7 @@ +2011-12-10 KUBO Takehiro + * test/test_oci8.rb: fix test_select when TZ set to daylight saving time. + (reported by Yasuo Honda) + 2011-12-06 KUBO Takehiro * ext/oci8/oci8.c: raise a RuntimeError when non-blocking mode is set to a connection allocated from OCI8::ConnectionPool on ruby 1.8. Modified: trunk/ruby-oci8/test/test_oci8.rb =================================================================== --- trunk/ruby-oci8/test/test_oci8.rb 2011-12-06 12:56:44 UTC (rev 480) +++ trunk/ruby-oci8/test/test_oci8.rb 2011-12-10 05:50:41 UTC (rev 481) @@ -96,9 +96,9 @@ cursor = @conn.parse("INSERT INTO test_table VALUES (:C, :V, :N, :D1, :D2, :D3, :D4, :INT, :BIGNUM)") 1.upto(10) do |i| if i == 1 - dt = [nil, OraDate] + dt = [nil, OraDate] else - dt = OraDate.new(2000 + i, 8, 3, 23, 59, 59) + dt = OraDate.new(2000 + i, i % 2 == 0 ? 7 : 1, 3, 23, 59, 59) end cursor.exec(format("%10d", i * 10), i.to_s, i, dt, dt, dt, dt, i * 11111111111, i * 10000000000) end @@ -122,9 +122,10 @@ assert_nil(rv[5]) assert_nil(rv[6]) else - tm = Time.local(2000 + i, 8, 3, 23, 59, 59) - dt = Date.civil(2000 + i, 8, 3) - dttm = DateTime.civil(2000 + i, 8, 3, 23, 59, 59, Time.now.utc_offset.to_r/86400) + month = i % 2 == 0 ? 7 : 1 + tm = Time.local(2000 + i, month, 3, 23, 59, 59) + dt = Date.civil(2000 + i, month, 3) + dttm = DateTime.civil(2000 + i, month, 3, 23, 59, 59, tm.utc_offset.to_r/86400) assert_equal(tm, rv[3]) assert_equal(tm, rv[4]) assert_equal(dt, rv[5]) @@ -148,9 +149,10 @@ assert_nil(row['D3']) assert_nil(row['D4']) else - tm = Time.local(2000 + i, 8, 3, 23, 59, 59) - dt = Date.civil(2000 + i, 8, 3) - dttm = DateTime.civil(2000 + i, 8, 3, 23, 59, 59, Time.now.utc_offset.to_r/86400) + month = i % 2 == 0 ? 7 : 1 + tm = Time.local(2000 + i, month, 3, 23, 59, 59) + dt = Date.civil(2000 + i, month, 3) + dttm = DateTime.civil(2000 + i, month, 3, 23, 59, 59, tm.utc_offset.to_r/86400) assert_equal(tm, row['D1']) assert_equal(tm, row['D2']) assert_equal(dt, row['D3']) From nobody at rubyforge.org Sat Dec 10 01:50:38 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 10 Dec 2011 01:50:38 -0500 (EST) Subject: [ruby-oci8-commit] [482] trunk/ruby-oci8: ENV['ORA_SDTZ'] instead of ' alter session set time_zone = ...' Message-ID: <20111210065038.5EDAC1678367@rubyforge.org> Revision: 482 Author: kubo Date: 2011-12-10 01:50:37 -0500 (Sat, 10 Dec 2011) Log Message: ----------- ENV['ORA_SDTZ'] instead of 'alter session set time_zone = ...' Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/lib/oci8/oci8.rb trunk/ruby-oci8/lib/oci8/properties.rb trunk/ruby-oci8/lib/oci8.rb.in trunk/ruby-oci8/test/test_datetime.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-10 05:50:41 UTC (rev 481) +++ trunk/ruby-oci8/ChangeLog 2011-12-10 06:50:37 UTC (rev 482) @@ -1,4 +1,11 @@ 2011-12-10 KUBO Takehiro + * lib/oci8/oci8.rb, lib/oci8/properties.rb, test/test_datetime.rb: + revert OCI8.properties[:time_zone] which was added 5 days ago. + * lib/oci8.rb.in: use ENV['ORA_SDTZ'] instead of 'alter session set time_zone = ...' + to set Oracle session time zone. On cygwin, explicitly set + environments variables which start with 'ORA_' to WIN32 environments. + +2011-12-10 KUBO Takehiro * test/test_oci8.rb: fix test_select when TZ set to daylight saving time. (reported by Yasuo Honda) Modified: trunk/ruby-oci8/lib/oci8/oci8.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/oci8.rb 2011-12-10 05:50:41 UTC (rev 481) +++ trunk/ruby-oci8/lib/oci8/oci8.rb 2011-12-10 06:50:37 UTC (rev 482) @@ -140,9 +140,6 @@ @prefetch_rows = nil @username = nil - - time_zone = OCI8.properties[:time_zone] || ENV['TZ'] - exec("alter session set time_zone = '#{time_zone}'") if time_zone and time_zone.length > 0 end # call-seq: Modified: trunk/ruby-oci8/lib/oci8/properties.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/properties.rb 2011-12-10 05:50:41 UTC (rev 481) +++ trunk/ruby-oci8/lib/oci8/properties.rb 2011-12-10 06:50:37 UTC (rev 482) @@ -5,7 +5,6 @@ class OCI8 @@properties = { - :time_zone => nil, :length_semantics => :byte, :bind_string_as_nchar => false, :float_conversion_type => :ruby, @@ -19,8 +18,6 @@ def @@properties.[]=(name, val) raise IndexError, "No such property name: #{name}" unless @@properties.has_key?(name) case name - when :time_zone - raise TypeError, "invalid property type #{val.class}" unless val.nil? or val.is_a? String when :length_semantic if val != :byte and val != :char raise ArgumentError, "Invalid property value #{val} for :length_semantics." @@ -53,14 +50,6 @@ # # Supported properties are listed below: # - # [:time_zone] - # (new in 2.1.0) - # - # If your application runs in a time zone which adopt daylight saving time, - # you should set the environment variable TZ or this +time_zone+ property. - # Otherwise, Oracle session time zone is set with current constant - # offset from GMT. - # # [:length_semantics] # (new in 2.1.0) # Modified: trunk/ruby-oci8/lib/oci8.rb.in =================================================================== --- trunk/ruby-oci8/lib/oci8.rb.in 2011-12-10 05:50:41 UTC (rev 481) +++ trunk/ruby-oci8/lib/oci8.rb.in 2011-12-10 06:50:37 UTC (rev 482) @@ -6,16 +6,21 @@ # ruby -r oci8 -e 'OCI8.new("scott", "tiger", nil).exec("select * from emp") do |r| puts r.join(","); end' # # select all data from emp and print them as CVS format. +ENV['ORA_SDTZ'] = ENV['TZ'] unless ENV['ORA_SDTZ'] + if RUBY_PLATFORM =~ /cygwin/ # Cygwin manages environment variables by itself. # They don't synchroize with Win32's ones. # This set some Oracle's environment variables to win32's enviroment. require 'Win32API' win32setenv = Win32API.new('Kernel32.dll', 'SetEnvironmentVariableA', 'PP', 'I') - ['NLS_LANG', 'ORA_NLS10', 'ORA_NLS32', 'ORA_NLS33', 'ORACLE_BASE', 'ORACLE_HOME', 'ORACLE_SID', 'TNS_ADMIN', 'LOCAL'].each do |name| + ['NLS_LANG', 'TNS_ADMIN', 'LOCAL'].each do |name| val = ENV[name] win32setenv.call(name, val && val.dup) end + ENV.each do |name, val| + win32setenv.call(name, val && val.dup) if name =~ /^ORA/ + end end so_basename = 'oci8lib_' Modified: trunk/ruby-oci8/test/test_datetime.rb =================================================================== --- trunk/ruby-oci8/test/test_datetime.rb 2011-12-10 05:50:41 UTC (rev 481) +++ trunk/ruby-oci8/test/test_datetime.rb 2011-12-10 06:50:37 UTC (rev 482) @@ -579,34 +579,4 @@ end end end - - def test_time_zone_property - orig_prop = OCI8.properties[:time_zone] - orig_env = ENV['TZ'] - conn = nil - begin - assert_raise(TypeError) do - OCI8.properties[:time_zone] = 1 - end - - OCI8.properties[:time_zone] = 'America/New_York' - ENV['TZ'] = nil - conn = get_oci8_connection - assert_equal('America/New_York', conn.select_one('select sessiontimezone from dual')[0]) - conn.logoff - conn = nil - - OCI8.properties[:time_zone] = nil - ENV['TZ'] = 'Europe/Riga' - conn = get_oci8_connection - assert_equal('Europe/Riga', conn.select_one('select sessiontimezone from dual')[0]) - conn.logoff - conn = nil - - ensure - conn.logoff if conn - OCI8.properties[:time_zone] = orig_prop - ENV['TZ'] = orig_env - end - end end # TestOCI8 From nobody at rubyforge.org Sat Dec 10 02:07:13 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 10 Dec 2011 02:07:13 -0500 (EST) Subject: [ruby-oci8-commit] [483] trunk/ruby-oci8: suppress "No tests were specified" when the client character set is not UTF-8. Message-ID: <20111210070713.4C1B8185837B@rubyforge.org> Revision: 483 Author: kubo Date: 2011-12-10 02:07:13 -0500 (Sat, 10 Dec 2011) Log Message: ----------- suppress "No tests were specified" when the client character set is not UTF-8. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/test/test_bind_string.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-10 06:50:37 UTC (rev 482) +++ trunk/ruby-oci8/ChangeLog 2011-12-10 07:07:13 UTC (rev 483) @@ -1,4 +1,8 @@ 2011-12-10 KUBO Takehiro + * test/test_bind_string.rb: suppress "No tests were specified" when + the client character set is not UTF-8. + +2011-12-10 KUBO Takehiro * lib/oci8/oci8.rb, lib/oci8/properties.rb, test/test_datetime.rb: revert OCI8.properties[:time_zone] which was added 5 days ago. * lib/oci8.rb.in: use ENV['ORA_SDTZ'] instead of 'alter session set time_zone = ...' Modified: trunk/ruby-oci8/test/test_bind_string.rb =================================================================== --- trunk/ruby-oci8/test/test_bind_string.rb 2011-12-10 06:50:37 UTC (rev 482) +++ trunk/ruby-oci8/test/test_bind_string.rb 2011-12-10 07:07:13 UTC (rev 483) @@ -96,5 +96,11 @@ OCI8.properties[:length_semantics] = orig_prop end end + + else + + def test_dummy + # to suppress "No tests were specified." + end end end From nobody at rubyforge.org Sun Dec 11 07:34:21 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sun, 11 Dec 2011 07:34:21 -0500 (EST) Subject: [ruby-oci8-commit] [484] trunk/ruby-oci8: update documents. Message-ID: <20111211123422.05700185834E@rubyforge.org> Revision: 484 Author: kubo Date: 2011-12-11 07:34:21 -0500 (Sun, 11 Dec 2011) Log Message: ----------- update documents. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/NEWS trunk/ruby-oci8/README trunk/ruby-oci8/ext/oci8/connection_pool.c trunk/ruby-oci8/test/README Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-10 07:07:13 UTC (rev 483) +++ trunk/ruby-oci8/ChangeLog 2011-12-11 12:34:21 UTC (rev 484) @@ -1,3 +1,8 @@ +2011-12-11 KUBO Takehiro + * NEWS: add changes between 2.0.6 and 2.1.0. + * README, test/README: rewritten. + * ext/oci8/connection_pool.c: add a note. + 2011-12-10 KUBO Takehiro * test/test_bind_string.rb: suppress "No tests were specified" when the client character set is not UTF-8. Modified: trunk/ruby-oci8/NEWS =================================================================== --- trunk/ruby-oci8/NEWS 2011-12-10 07:07:13 UTC (rev 483) +++ trunk/ruby-oci8/NEWS 2011-12-11 12:34:21 UTC (rev 484) @@ -1,3 +1,114 @@ +2.1.0: + +*** Ruby-oci8 2.1.0 doesn't support Oracle 8 (8.0) and Oracle 8i (8.1) anymore. *** + +* New Features + + - OCI connection pooling + + See: http://docs.oracle.com/cd/E11882_01/appdev.112/e10646/oci09adv.htm#sthref1479 + and http://docs.oracle.com/cd/E11882_01/java.112/e16548/ociconpl.htm#JJDBC28789 + + Example: + + # Create a connection pool. + # username and password are required to establish an implicit primary session. + cpool = OCI8::ConnectionPool.new(1, 5, 2, username, password, database) + + # Get a session from the pool. + # Pass the connection pool to the third argument. + conn1 = OCI8.new(username, password, cpool) + + # Get another session. + conn2 = OCI8.new(username, password, cpool) + + - Daylight saving time aware if TZ is set. + + You should set the environment variable TZ if your applications run + in a time zone with daylight saving time transitions. + Otherwise, Oracle session time zone is set with current constant + offset from GMT. + (reported by Yasuo Honda) + + - connect as sysasm (Oracle 11g only) + + OCI8.new('username/password as sysasm') + or + OCI8.new('username', 'password', nil, :SYSASM) + + - Oracle number is converted to ruby float exactly same as ruby does. + + From ruby 1.9.2, a float value converted from Oracle number 15.7 by + the Oracle function OCINumberToReal() makes a string representation + 15.700000000000001 by Float#to_s. (See: http://redmine.ruby-lang.org/issues/4656) + To avoid this issue, any Oracle number is converted to a float as + ruby's String#to_f does. + + The behavior is customizable by OCI8.properties[:float_conversion_type]. + + OCI8.properties[:float_conversion_type] = :oracle # => Use OCINumberToReal() + OCI8.properties[:float_conversion_type] = :ruby # => Use String#to_f + + The default value is :ruby. + + - OCI_SUCCESS_WITH_INFO handling is changed. + + Ruby-oci8 2.0 treats OCI_SUCCESS_WITH_INFO in OCI layer as an error + and raise an exception OCISuccessWithInfo such as "ORA-24347: Warning of + a NULL column in an aggregate function" and "ORA-28002: the password will + expire within xx days." + + From 2.1.0, it is treated as a warning and the exception is set + to OCI8#last_error. + + - OCI8#last_error + + The last error or warning associated with the session is set to + OCI8#last_error. The usecase is to detect OCI_SUCCESS_WITH_INFO. + It is reset by OCI8#exec and OCI8#parse. + + - Experimental support of character length semantics + + This is enabled when :char is set to OCI8.properties[:length_semantics]. + + - OCI8.client_charset_name and OCI8#database_charset_name is added. + + They return Oracle charset name such as WE8ISO8859P15. + +* Specification changes + + - The parent class OCINoData was changed from OCIException to OCIError. + +* Fixed Issues + + - Fix a bug that an array is always bound as null. + This bug was introduced in ruby-oci8 2.0.5. + (reported by Leo? Bitto) + + - Avoid a gcc internal compiler error when using ruby1.9.2-p290 on + ubuntu 11.10 (64bit). (reported by Bob Saveland.) + + - Fix compilation problems on Solaris. + (Reported by Sanjiv Patel.) + + - Fix compilation problems on Linux. + (Reported by Edgars Beigarts.) + + - Connections are released by GC without explicit logoff. + + - Set ruby encoding CP950 for oracle characterset ZHT16MSWIN950 and + CP951 for ZHT16HKSCS and ZHT16HKSCS31 when the ruby is 1.9.3. + + - Clear an executuing thread information in a connection when a SQL + executions is canceled by Thread#kill or Timeout::timeout. + (reported by Aaron Qian) + + - Fix some test cases for object type and TZ issues. + (reported by Yasuo Honda) + + - Use Gem::Command.build_args to get arguments after '--'. + (reported by jbirdjavi) + 2.0.6: * Fixed issues Modified: trunk/ruby-oci8/README =================================================================== --- trunk/ruby-oci8/README 2011-12-10 07:07:13 UTC (rev 483) +++ trunk/ruby-oci8/README 2011-12-11 12:34:21 UTC (rev 484) @@ -1,76 +1,5 @@ -= How to make +Ruby-oci8 is a ruby interface for Oracle using OCI8 API. +The latest version (2.1.x) works with Oracle9i or later. +Use ruby-oci8 2.0.6 or earlier for Oracle 8. -* ruby and make (or nmake on MSVC) commands in the environment variable PATH? -* ruby is 1.8.0 or later? (Use ruby-oci8 0.1.x for ruby 1.6.x.) - -== For OCI installed by Oracle Universal Installer -make sure the environment variable ORACLE_HOME (or registry on Windows) -is set correctly. run the the following commands. - - make (or nmake on MSVC) - -== For OCI installed by Oracle Instant Installer - -linux: - ruby setup.rb config -- --with-instant-client - make - -others: - ruby setup.rb config -- --with-instant-client=/path/to/instantclient10_1 - make (or nmake on MSVC) - -= On compilation failure - -Please report the following information to kubo at jiubao.org. - -* last 100 lines of 'ext/oci8/mkmf.log'. -* the results of the following commands: - ruby -r rbconfig -e "p Config::CONFIG['host']" - ruby -r rbconfig -e "p Config::CONFIG['CC']" - ruby -r rbconfig -e "p Config::CONFIG['CFLAGS']" - ruby -r rbconfig -e "p Config::CONFIG['LDSHARED']" - ruby -r rbconfig -e "p Config::CONFIG['LDFLAGS']" - ruby -r rbconfig -e "p Config::CONFIG['LIBS']" - ruby -r rbconfig -e "p Config::CONFIG['GNU_LD']" -* if you use gcc: - gcc --print-prog-name=ld - gcc --print-prog-name=as -* on platforms which can use both 32bit/64bit binaries: - file $ORACLE_HOME/bin/oracle - file `which ruby` - echo $LD_LIBRARY_PATH - -= How to run unit test - -before runing unit test, -1. connect to Oracle as system: - - $ sqlplus system/ - -2. create user ruby: - - SQL> CREATE USER ruby IDENTIFIED BY oci8; - - or - - SQL> CREATE USER ruby IDENTIFIED BY oci8 - 2 DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp; - -3. grant the privilege to connect and execute. - - SQL> GRANT connect, resource, create view TO ruby; - -4. connect to Oracle as sys - - $ sqlplus 'sys/ as sysdba' - -5. grant the privilege for the unittest of blocking-mode. - - SQL> GRANT EXECUTE ON dbms_lock TO ruby; - -6. change test/config.rb as you like - -Then you can run: - $ make check -or - $ nmake check (If your compiler is MS Visual C++.) +See: http://ruby-oci8.rubyforge.org Modified: trunk/ruby-oci8/ext/oci8/connection_pool.c =================================================================== --- trunk/ruby-oci8/ext/oci8/connection_pool.c 2011-12-10 07:07:13 UTC (rev 483) +++ trunk/ruby-oci8/ext/oci8/connection_pool.c 2011-12-11 12:34:21 UTC (rev 484) @@ -62,6 +62,8 @@ * conn_max specifies the maximum number of connections that * can be opened to the database. Once this value is reached, no more * connections are opened. Valid values are 1 and higher. + * Note that this limits the number of concurent SQL executions, not + * the number of concurrent sessions. * * conn_incr allows the application to set the next increment * for connections to be opened to the database if the current number Modified: trunk/ruby-oci8/test/README =================================================================== --- trunk/ruby-oci8/test/README 2011-12-10 07:07:13 UTC (rev 483) +++ trunk/ruby-oci8/test/README 2011-12-11 12:34:21 UTC (rev 484) @@ -1,4 +1,42 @@ -This directory includes test cases using RubyUnit. +Before runing unit test: -If RubyUnit is installed in your site, it is used to run test cases. -If not installed, support files in this package are used. +1. connect to Oracle as system: + + $ sqlplus system/ + +2. create user ruby: + + SQL> CREATE USER ruby IDENTIFIED BY oci8; + + or + + SQL> CREATE USER ruby IDENTIFIED BY oci8 + 2 DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp; + +3. grant the privilege to connect and execute. + + SQL> GRANT connect, resource, create view TO ruby; + +4. connect to Oracle as sys + + $ sqlplus 'sys/ as sysdba' + +5. grant privileges + + SQL> GRANT EXECUTE ON dbms_lock TO ruby; + SQL> GRANT CREATE VIEW TO ruby; + +6. connect as ruby user. + + $ sqlplus ruby/oci8 + +7. Create object types + + SQL> @test/setup_test_object.sql + +8. change $dbname if the database + +Then you can run: + $ make check +or + $ nmake check (If your compiler is MS Visual C++.) From nobody at rubyforge.org Sun Dec 11 08:53:04 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sun, 11 Dec 2011 08:53:04 -0500 (EST) Subject: [ruby-oci8-commit] [485] trunk/ruby-oci8: fix a buffer overrun in oci8_cpool_initialize(). Message-ID: <20111211135304.A17A2185834E@rubyforge.org> Revision: 485 Author: kubo Date: 2011-12-11 08:53:03 -0500 (Sun, 11 Dec 2011) Log Message: ----------- fix a buffer overrun in oci8_cpool_initialize(). Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/connection_pool.c Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-11 12:34:21 UTC (rev 484) +++ trunk/ruby-oci8/ChangeLog 2011-12-11 13:53:03 UTC (rev 485) @@ -1,4 +1,7 @@ 2011-12-11 KUBO Takehiro + * ext/oci8/connection_pool.c: fix a buffer overrun in oci8_cpool_initialize(). + +2011-12-11 KUBO Takehiro * NEWS: add changes between 2.0.6 and 2.1.0. * README, test/README: rewritten. * ext/oci8/connection_pool.c: add a note. Modified: trunk/ruby-oci8/ext/oci8/connection_pool.c =================================================================== --- trunk/ruby-oci8/ext/oci8/connection_pool.c 2011-12-11 12:34:21 UTC (rev 484) +++ trunk/ruby-oci8/ext/oci8/connection_pool.c 2011-12-11 13:53:03 UTC (rev 485) @@ -45,7 +45,7 @@ static oci8_base_vtable_t oci8_cpool_vtable = { oci8_cpool_mark, oci8_cpool_free, - sizeof(oci8_base_t), + sizeof(oci8_cpool_t), oci8_cpool_init, }; From nobody at rubyforge.org Tue Dec 13 05:32:11 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Tue, 13 Dec 2011 05:32:11 -0500 (EST) Subject: [ruby-oci8-commit] [486] trunk/ruby-oci8: suppress gcc-4. 6 warnings and update the version to 2.1.0. Message-ID: <20111213103211.3932F1D78108@rubyforge.org> Revision: 486 Author: kubo Date: 2011-12-13 05:32:09 -0500 (Tue, 13 Dec 2011) Log Message: ----------- suppress gcc-4.6 warnings and update the version to 2.1.0. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/VERSION trunk/ruby-oci8/ext/oci8/error.c trunk/ruby-oci8/ext/oci8/oci8.c trunk/ruby-oci8/ext/oci8/oci8.h trunk/ruby-oci8/ext/oci8/ocidatetime.c trunk/ruby-oci8/ext/oci8/ocinumber.c trunk/ruby-oci8/ext/oci8/stmt.c Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-11 13:53:03 UTC (rev 485) +++ trunk/ruby-oci8/ChangeLog 2011-12-13 10:32:09 UTC (rev 486) @@ -1,3 +1,8 @@ +2011-12-13 KUBO Takehiro + * VERSION: update to 2.1.0. + * ext/oci8/error.c, ext/oci8/oci8.c, ext/oci8/oci8.h, ext/oci8/ocidatetime.c, + ext/oci8/ocinumber.c, ext/oci8/stmt.c: suppress gcc-4.6 warnings. + 2011-12-11 KUBO Takehiro * ext/oci8/connection_pool.c: fix a buffer overrun in oci8_cpool_initialize(). Modified: trunk/ruby-oci8/VERSION =================================================================== --- trunk/ruby-oci8/VERSION 2011-12-11 13:53:03 UTC (rev 485) +++ trunk/ruby-oci8/VERSION 2011-12-13 10:32:09 UTC (rev 486) @@ -1 +1 @@ -2.1.x +2.1.0 Modified: trunk/ruby-oci8/ext/oci8/error.c =================================================================== --- trunk/ruby-oci8/ext/oci8/error.c 2011-12-11 13:53:03 UTC (rev 485) +++ trunk/ruby-oci8/ext/oci8/error.c 2011-12-13 10:32:09 UTC (rev 486) @@ -244,7 +244,7 @@ if (have_OCIMessageGet) { if (msghp == NULL) { - chkerr(OCIMessageOpen(oci8_envhp, oci8_errhp, &msghp, TO_ORATEXT("rdbms"), TO_ORATEXT("ora"), OCI_DURATION_PROCESS)); + chkerr(OCIMessageOpen(oci8_envhp, oci8_errhp, &msghp, TO_CONST_ORATEXT("rdbms"), TO_CONST_ORATEXT("ora"), OCI_DURATION_PROCESS)); } errmsg = TO_CHARPTR(OCIMessageGet(msghp, msgno, NULL, 0)); } Modified: trunk/ruby-oci8/ext/oci8/oci8.c =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8.c 2011-12-11 13:53:03 UTC (rev 485) +++ trunk/ruby-oci8/ext/oci8/oci8.c 2011-12-13 10:32:09 UTC (rev 486) @@ -830,7 +830,7 @@ */ static VALUE oci8_set_client_identifier(VALUE self, VALUE val) { - char *ptr; + const char *ptr; ub4 size; if (!NIL_P(val)) { @@ -846,7 +846,7 @@ if (size > 0 && ptr[0] == ':') { rb_raise(rb_eArgError, "client identifier should not start with ':'."); } - chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr, + chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, (dvoid*)ptr, size, OCI_ATTR_CLIENT_IDENTIFIER, oci8_errhp), DATA_PTR(self)); } else { @@ -854,7 +854,7 @@ oci8_exec_sql_var_t bind_vars[1]; /* :client_id */ - bind_vars[0].valuep = ptr; + bind_vars[0].valuep = (dvoid*)ptr; bind_vars[0].value_sz = size; bind_vars[0].dty = SQLT_CHR; bind_vars[0].indp = NULL; @@ -904,7 +904,7 @@ */ static VALUE oci8_set_module(VALUE self, VALUE val) { - char *ptr; + const char *ptr; ub4 size; if (!NIL_P(val)) { @@ -917,7 +917,7 @@ } if (oracle_client_version >= ORAVER_10_1) { /* Oracle 10g or upper */ - chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr, + chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, (dvoid*)ptr, size, OCI_ATTR_MODULE, oci8_errhp), DATA_PTR(self)); } else { @@ -925,7 +925,7 @@ oci8_exec_sql_var_t bind_vars[1]; /* :module */ - bind_vars[0].valuep = ptr; + bind_vars[0].valuep = (dvoid*)ptr; bind_vars[0].value_sz = size; bind_vars[0].dty = SQLT_CHR; bind_vars[0].indp = NULL; @@ -974,7 +974,7 @@ */ static VALUE oci8_set_action(VALUE self, VALUE val) { - char *ptr; + const char *ptr; ub4 size; if (!NIL_P(val)) { @@ -987,7 +987,7 @@ } if (oracle_client_version >= ORAVER_10_1) { /* Oracle 10g or upper */ - chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr, + chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, (dvoid*)ptr, size, OCI_ATTR_ACTION, oci8_errhp), DATA_PTR(self)); } else { @@ -995,7 +995,7 @@ oci8_exec_sql_var_t bind_vars[1]; /* :action */ - bind_vars[0].valuep = ptr; + bind_vars[0].valuep = (dvoid*)ptr; bind_vars[0].value_sz = size; bind_vars[0].dty = SQLT_CHR; bind_vars[0].indp = NULL; @@ -1037,7 +1037,7 @@ */ static VALUE oci8_set_client_info(VALUE self, VALUE val) { - char *ptr; + const char *ptr; ub4 size; if (!NIL_P(val)) { @@ -1050,7 +1050,7 @@ } if (oracle_client_version >= ORAVER_10_1) { /* Oracle 10g or upper */ - chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr, + chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, (dvoid*)ptr, size, OCI_ATTR_CLIENT_INFO, oci8_errhp), DATA_PTR(self)); } else { @@ -1058,7 +1058,7 @@ oci8_exec_sql_var_t bind_vars[1]; /* :client_info */ - bind_vars[0].valuep = ptr; + bind_vars[0].valuep = (dvoid*)ptr; bind_vars[0].value_sz = size; bind_vars[0].dty = SQLT_CHR; bind_vars[0].indp = NULL; Modified: trunk/ruby-oci8/ext/oci8/oci8.h =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8.h 2011-12-11 13:53:03 UTC (rev 485) +++ trunk/ruby-oci8/ext/oci8/oci8.h 2011-12-13 10:32:09 UTC (rev 486) @@ -220,17 +220,23 @@ #define IS_OCI_ERROR(v) (((v) != OCI_SUCCESS) && ((v) != OCI_SUCCESS_WITH_INFO)) #ifdef ALWAYS_INLINE #define TO_ORATEXT to_oratext +#define TO_CONST_ORATEXT to_const_oratext #define TO_CHARPTR to_charptr static ALWAYS_INLINE OraText *to_oratext(char *c) { return (OraText*)c; } +static ALWAYS_INLINE const OraText *to_const_oratext(const char *c) +{ + return (const OraText*)c; +} static ALWAYS_INLINE char *to_charptr(OraText *c) { return (char*)c; } #else #define TO_ORATEXT(c) ((OraText*)(c)) +#define TO_CONST_ORATEXT(c) ((const OraText*)(c)) #define TO_CHARPTR(c) ((char*)(c)) #endif #define RSTRING_ORATEXT(obj) TO_ORATEXT(RSTRING_PTR(obj)) Modified: trunk/ruby-oci8/ext/oci8/ocidatetime.c =================================================================== --- trunk/ruby-oci8/ext/oci8/ocidatetime.c 2011-12-11 13:53:03 UTC (rev 485) +++ trunk/ruby-oci8/ext/oci8/ocidatetime.c 2011-12-13 10:32:09 UTC (rev 486) @@ -265,8 +265,8 @@ if (svcctx == NULL || svcctx->type != OCI_HTYPE_SVCCTX) { rb_raise(rb_eRuntimeError, "oci8lib.so internal error [%s:%d, %p, %d, %p, %d]", __FILE__, __LINE__, - parent, parent ? parent->type : -1, - svcctx, svcctx ? svcctx->type : -1); + parent, parent ? (int)parent->type : -1, + svcctx, svcctx ? (int)svcctx->type : -1); } oci8_set_ocitimestamp_tz(*(OCIDateTime **)data, val, svcctx->self); } @@ -328,7 +328,7 @@ } else { /* Workaround for Bug 2227982 */ char buf[64]; - char *sign = ""; + const char *sign = ""; if (year < 0 && month != 0) { year += 1; @@ -383,7 +383,7 @@ } else { /* Workaround for Bug 2227982 */ char buf[64]; - char *sign = ""; + const char *sign = ""; if (day == 0) { if (hour < 0) { Modified: trunk/ruby-oci8/ext/oci8/ocinumber.c =================================================================== --- trunk/ruby-oci8/ext/oci8/ocinumber.c 2011-12-11 13:53:03 UTC (rev 485) +++ trunk/ruby-oci8/ext/oci8/ocinumber.c 2011-12-13 10:32:09 UTC (rev 486) @@ -1380,13 +1380,13 @@ onum_s_load(VALUE klass, VALUE str) { unsigned char *c; - int size; + size_t size; OCINumber num; Check_Type(str, T_STRING); c = RSTRING_ORATEXT(str); size = RSTRING_LEN(str); - if (size == 0 || size != c[0] + 1 || size > sizeof(num)) { + if (size == 0 || size != c[0] + 1u || size > sizeof(num)) { rb_raise(rb_eTypeError, "marshaled OCI::Number format differ"); } memset(&num, 0, sizeof(num)); Modified: trunk/ruby-oci8/ext/oci8/stmt.c =================================================================== --- trunk/ruby-oci8/ext/oci8/stmt.c 2011-12-11 13:53:03 UTC (rev 485) +++ trunk/ruby-oci8/ext/oci8/stmt.c 2011-12-13 10:32:09 UTC (rev 486) @@ -144,7 +144,6 @@ sword status; VALUE old_value; void *indp; - ub4 *curelep; if (NIL_P(vplaceholder)) { /* 1 */ placeholder_ptr = NULL; @@ -170,11 +169,6 @@ vptr = (const oci8_bind_vtable_t *)obind->base.vptr; indp = NIL_P(obind->tdo) ? obind->u.inds : NULL; - if (obind->maxar_sz == 0) { - curelep = NULL; - } else { - curelep = &obind->curar_sz; - } if (placeholder_ptr == (char*)-1) { status = OCIBindByPos(stmt->base.hp.stmt, &obind->base.hp.bnd, oci8_errhp, position, obind->valuep, obind->value_sz, vptr->dty, indp, NULL, 0, 0, 0, OCI_DEFAULT); } else { From nobody at rubyforge.org Tue Dec 13 05:46:16 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Tue, 13 Dec 2011 05:46:16 -0500 (EST) Subject: [ruby-oci8-commit] [487] tags/ruby-oci8-2.1.0/: tag 2.1.0 Message-ID: <20111213104620.3B6C11D783DF@rubyforge.org> Revision: 487 Author: kubo Date: 2011-12-13 05:46:02 -0500 (Tue, 13 Dec 2011) Log Message: ----------- tag 2.1.0 Added Paths: ----------- tags/ruby-oci8-2.1.0/ From nobody at rubyforge.org Thu Dec 15 09:40:28 2011 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Thu, 15 Dec 2011 09:40:28 -0500 (EST) Subject: [ruby-oci8-commit] [488] trunk/ruby-oci8: fix "wrong number of arguments (1 for 2)" when date datatype in a object type is gotten. Message-ID: <20111215144028.4BB471218278@rubyforge.org> Revision: 488 Author: kubo Date: 2011-12-15 09:40:27 -0500 (Thu, 15 Dec 2011) Log Message: ----------- fix "wrong number of arguments (1 for 2)" when date datatype in a object type is gotten. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/lib/oci8/object.rb trunk/ruby-oci8/test/setup_test_object.sql trunk/ruby-oci8/test/test_object.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2011-12-13 10:46:02 UTC (rev 487) +++ trunk/ruby-oci8/ChangeLog 2011-12-15 14:40:27 UTC (rev 488) @@ -1,3 +1,9 @@ +2011-12-15 KUBO Takehiro + * lib/oci8/object.rb, test/setup_test_object.sql, test/test_object.rb: + fix "wrong number of arguments (1 for 2)" when date datatype in a object + type is gotten. + (repored by Leo? Bitto) + 2011-12-13 KUBO Takehiro * VERSION: update to 2.1.0. * ext/oci8/error.c, ext/oci8/oci8.c, ext/oci8/oci8.h, ext/oci8/ocidatetime.c, Modified: trunk/ruby-oci8/lib/oci8/object.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/object.rb 2011-12-13 10:46:02 UTC (rev 487) +++ trunk/ruby-oci8/lib/oci8/object.rb 2011-12-15 14:40:27 UTC (rev 488) @@ -443,7 +443,7 @@ when :date [ATTR_OCIDATE, nil, SIZE_OF_OCIDATE, 2, ALIGNMENT_OF_OCIDATE, Proc.new do |val| datetime_to_array(val, :date) end, # set_proc - Proc.new do |val| array_to_datetime(val) end, # get_proc + Proc.new do |val| array_to_datetime(val, :local) end, # get_proc ] when :binary_double [ATTR_BINARY_DOUBLE, nil, SIZE_OF_DOUBLE, 2, ALIGNMENT_OF_DOUBLE] Modified: trunk/ruby-oci8/test/setup_test_object.sql =================================================================== --- trunk/ruby-oci8/test/setup_test_object.sql 2011-12-13 10:46:02 UTC (rev 487) +++ trunk/ruby-oci8/test/setup_test_object.sql 2011-12-15 14:40:27 UTC (rev 488) @@ -33,6 +33,8 @@ / create or replace type rb_test_obj_elem_ary_of_ary as array(50) of rb_test_obj_elem_array / +--create or replace type rb_test_date_array as array(50) of date +--/ create type rb_test_obj as object ( int_val integer, flt_val float, @@ -51,6 +53,8 @@ raw_array_val rb_test_raw_array, obj_array_val rb_test_obj_elem_array, obj_ary_of_ary_val rb_test_obj_elem_ary_of_ary, + date_val date, +-- date_array_val rb_test_date_array, constructor function rb_test_obj(n number) return self as result, static function class_func(n number) return rb_test_obj, @@ -63,6 +67,15 @@ create or replace type body rb_test_obj is constructor function rb_test_obj(n number) return self as result is + function to_test_date(n number) return date is + begin + return to_date(to_char(1000 + n * 10, 'FM0000') || + to_char(mod(round(n) * 5, 12) + 1, 'FM00') || + to_char(mod(round(n) * 7, 27) + 1, 'FM00') || + to_char(mod(round(n) * 9, 24), 'FM00') || + to_char(mod(round(n) * 11, 60), 'FM00') || + to_char(mod(round(n) * 13, 60), 'FM00'), 'yyyymmddhh24miss'); + end; begin self.int_val := n; self.flt_val := n; @@ -72,6 +85,7 @@ self.str_val := to_char(n); self.raw_val := utl_raw.cast_to_raw(to_char(n)); self.obj_val := rb_test_obj_elem(n, n + 1); + self.date_val := to_test_date(n); if self.int_val != 1 then self.int_array_val := rb_test_int_array(n, n + 1, n + 2); self.flt_array_val := rb_test_flt_array(n, n + 1, n + 2); @@ -86,6 +100,9 @@ rb_test_obj_elem(n + 1, n + 2), rb_test_obj_elem(n + 2, n + 3)); self.obj_ary_of_ary_val := rb_test_obj_elem_ary_of_ary(self.obj_array_val); +-- self.date_array_val := rb_test_date_array(to_test_date(n), +-- to_test_date(n + 1), +-- to_test_date(n + 2)); end if; return; end; Modified: trunk/ruby-oci8/test/test_object.rb =================================================================== --- trunk/ruby-oci8/test/test_object.rb 2011-12-13 10:46:02 UTC (rev 487) +++ trunk/ruby-oci8/test/test_object.rb 2011-12-15 14:40:27 UTC (rev 488) @@ -50,11 +50,25 @@ attr_reader :raw_array_val attr_reader :obj_array_val attr_reader :obj_ary_of_ary_val + attr_reader :date_val +# attr_reader :date_array_val def initialize @n = 0.0 end + @@offset = ::Time.local(2007).utc_offset.to_r / 86400 + def to_test_date(n) + year = (1000 + n * 10).round + month = (n.round * 5) % 12 + 1 + mday = (n.round * 7) % 27 + 1 + hour = (n.round * 9) % 24 + minute = (n.round * 11) % 60 + sec = (n.round * 13) % 60 + ::DateTime.civil(year, month, mday, hour, minute, sec, @@offset) + end + private :to_test_date + def next @n += 1.2 @n = (@n * 10).round / 10.0 @@ -67,6 +81,7 @@ @str_val = $` if /.0$/ =~ @str_val @raw_val = @str_val @obj_val = ExpectedValObjElem.new(@int_val, @int_val + 1) + @date_val = to_test_date(@n) if @int_val == 1 @int_array_val = nil @flt_array_val = nil @@ -77,6 +92,7 @@ @raw_array_val = nil @obj_array_val = nil @obj_ary_of_ary_val = nil +# @date_array_val = nil else @int_array_val = [] @flt_array_val = [] @@ -87,6 +103,7 @@ @raw_array_val = [] @obj_array_val = [] @obj_ary_of_ary_val = [] +# @date_array_val = [] 0.upto(2) do |i| ival = @n.round val = (@n + i).to_s @@ -99,6 +116,7 @@ @str_array_val[i] = val @raw_array_val[i] = val @obj_array_val[i] = ExpectedValObjElem.new(@int_val + i, @int_val + i + 1) +# @date_array_val[i] = to_test_date(@n + i) end @obj_ary_of_ary_val[0] = @obj_array_val end @@ -124,6 +142,8 @@ raw_array_val = val[14] obj_array_val = val[15] obj_ary_of_ary_val = val[16] + date_val = val[17] +# date_array_val = val[18] else assert_instance_of(RbTestObj, val) int_val = val.int_val @@ -143,6 +163,8 @@ raw_array_val = val.raw_array_val obj_array_val = val.obj_array_val obj_ary_of_ary_val = val.obj_ary_of_ary_val + date_val = val.date_val +# date_array_val = val.date_array_val end assert_equal(@int_val, int_val) @@ -162,6 +184,8 @@ assert_equal(@raw_array_val, raw_array_val && raw_array_val.to_ary) assert_equal(@obj_array_val, obj_array_val && obj_array_val.to_ary) assert_equal(@obj_ary_of_ary_val, obj_ary_of_ary_val && obj_ary_of_ary_val.to_ary.collect { |elem| elem.to_ary }) + assert_equal(@date_val, date_val) +# assert_equal(@date_array_val, date_array_val && date_array_val.to_ary) end def assert_array_in_delta(exp, val) @@ -189,11 +213,17 @@ def test_select2 expected_val = ExpectedVal.new - @conn.exec("select * from rb_test_obj_tab2 order by int_val") do |row| - assert(expected_val.next) - expected_val.should_be_equal(row) + orig_val = OCI8::BindType::Mapping[:date] + OCI8::BindType::Mapping[:date] = OCI8::BindType::DateTime # TODO: Delete this line later. + begin + @conn.exec("select * from rb_test_obj_tab2 order by int_val") do |row| + assert(expected_val.next) + expected_val.should_be_equal(row) + end + assert(!expected_val.next) + ensure + OCI8::BindType::Mapping[:date] = orig_val end - assert(!expected_val.next) end def test_select3