From nobody at rubyforge.org Tue Sep 9 04:05:29 2008 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Tue, 9 Sep 2008 04:05:29 -0400 (EDT) Subject: [ruby-oci8-commit] [288] trunk/ruby-oci8: * ext/oci8/apiwrap.rb, ext/oci8/apiwrap.yml, ext/ oci8/oci8.h, Message-ID: <20080909080529.AA85618585D6@rubyforge.org> Revision: 288 Author: kubo Date: 2008-09-09 04:05:28 -0400 (Tue, 09 Sep 2008) Log Message: ----------- * ext/oci8/apiwrap.rb, ext/oci8/apiwrap.yml, ext/oci8/oci8.h, ext/oci8/ocidatetime.c, lib/oci8.rb.in, lib/oci8/datetime.rb, lib/oci8/metadata.rb, lib/oci8/oci8.rb, test/test_break.rb, test/test_datetime.rb, test/test_dbi.rb, test/test_metadata.rb: fix Oracle version number mistakes. rename ORAVER_9_1 to ORAVER_9_0. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/apiwrap.rb trunk/ruby-oci8/ext/oci8/apiwrap.yml trunk/ruby-oci8/ext/oci8/oci8.h trunk/ruby-oci8/ext/oci8/ocidatetime.c trunk/ruby-oci8/lib/oci8/datetime.rb trunk/ruby-oci8/lib/oci8/metadata.rb trunk/ruby-oci8/lib/oci8/oci8.rb trunk/ruby-oci8/lib/oci8.rb.in trunk/ruby-oci8/test/test_break.rb trunk/ruby-oci8/test/test_datetime.rb trunk/ruby-oci8/test/test_dbi.rb trunk/ruby-oci8/test/test_metadata.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2008-08-31 14:11:39 UTC (rev 287) +++ trunk/ruby-oci8/ChangeLog 2008-09-09 08:05:28 UTC (rev 288) @@ -1,3 +1,11 @@ +2008-09-09 KUBO Takehiro + * ext/oci8/apiwrap.rb, ext/oci8/apiwrap.yml, ext/oci8/oci8.h, + ext/oci8/ocidatetime.c, lib/oci8.rb.in, lib/oci8/datetime.rb, + lib/oci8/metadata.rb, lib/oci8/oci8.rb, test/test_break.rb, + test/test_datetime.rb, test/test_dbi.rb, test/test_metadata.rb: + fix Oracle version number mistakes. rename ORAVER_9_1 to + ORAVER_9_0. + 2008-08-31 KUBO Takehiro * ext/oci8/bind.c, ext/oci8/stmt.c: disable DYNAMIC_FETCH to fetch LONG or LONG RAW columns. It doesn't work well. Modified: trunk/ruby-oci8/ext/oci8/apiwrap.rb =================================================================== --- trunk/ruby-oci8/ext/oci8/apiwrap.rb 2008-08-31 14:11:39 UTC (rev 287) +++ trunk/ruby-oci8/ext/oci8/apiwrap.rb 2008-09-09 08:05:28 UTC (rev 288) @@ -39,7 +39,7 @@ case @version when 0x08000000; @version_num = 'ORAVER_8_0' when 0x08100000; @version_num = 'ORAVER_8_1' - when 0x09100000; @version_num = 'ORAVER_9_1' + when 0x09000000; @version_num = 'ORAVER_9_0' when 0x09200000; @version_num = 'ORAVER_9_2' when 0x0a100000; @version_num = 'ORAVER_10_1' when 0x0a200000; @version_num = 'ORAVER_10_2' Modified: trunk/ruby-oci8/ext/oci8/apiwrap.yml =================================================================== --- trunk/ruby-oci8/ext/oci8/apiwrap.yml 2008-08-31 14:11:39 UTC (rev 287) +++ trunk/ruby-oci8/ext/oci8/apiwrap.yml 2008-09-09 08:05:28 UTC (rev 288) @@ -1015,12 +1015,12 @@ - OCIError *errhp # -# Oracle 9.1 +# Oracle 9.0 # # round trip: 0 (not docmented. I guess.) OCIDateTimeConstruct: - :version: 910 + :version: 900 :args: - dvoid *hndl - OCIError *err - OCIDateTime *datetime @@ -1036,7 +1036,7 @@ # round trip: 0 (not docmented. I guess.) OCIDateTimeGetDate: - :version: 910 + :version: 900 :args: - dvoid *hndl - OCIError *err - const OCIDateTime *date @@ -1046,7 +1046,7 @@ # round trip: 0 (not docmented. I guess.) OCIDateTimeGetTime: - :version: 910 + :version: 900 :args: - dvoid *hndl - OCIError *err - OCIDateTime *datetime @@ -1057,7 +1057,7 @@ # round trip: 0 (not docmented. I guess.) OCIDateTimeGetTimeZoneOffset: - :version: 910 + :version: 900 :args: - dvoid *hndl - OCIError *err - const OCIDateTime *datetime @@ -1066,7 +1066,7 @@ # round trip: 0 (not docmented. I guess.) OCIIntervalGetDaySecond: - :version: 910 + :version: 900 :args: - dvoid *hndl - OCIError *err - sb4 *dy @@ -1078,7 +1078,7 @@ # round trip: 0 (not docmented. I guess.) OCIIntervalGetYearMonth: - :version: 910 + :version: 900 :args: - dvoid *hndl - OCIError *err - sb4 *yr @@ -1087,7 +1087,7 @@ # round trip: 0 (not docmented. I guess.) OCIIntervalSetDaySecond: - :version: 910 + :version: 900 :args: - dvoid *hndl - OCIError *err - sb4 dy @@ -1099,7 +1099,7 @@ # round trip: 0 (not docmented. I guess.) OCIIntervalSetYearMonth: - :version: 910 + :version: 900 :args: - dvoid *hndl - OCIError *err - sb4 yr @@ -1108,7 +1108,7 @@ # round trip: 0 (not docmented. I guess.) OCIRowidToChar: - :version: 910 + :version: 900 :args: - OCIRowid *rowidDesc - OraText *outbfp - ub2 *outbflp Modified: trunk/ruby-oci8/ext/oci8/oci8.h =================================================================== --- trunk/ruby-oci8/ext/oci8/oci8.h 2008-08-31 14:11:39 UTC (rev 287) +++ trunk/ruby-oci8/ext/oci8/oci8.h 2008-09-09 08:05:28 UTC (rev 288) @@ -33,8 +33,8 @@ #define ORAVER_8_0 ORAVERNUM(8, 0, 0, 0, 0) #define ORAVER_8_1 ORAVERNUM(8, 1, 0, 0, 0) -#define ORAVER_9_1 ORAVERNUM(9, 1, 0, 0, 0) -#define ORAVER_9_2 ORAVERNUM(9, 1, 0, 0, 0) +#define ORAVER_9_0 ORAVERNUM(9, 0, 0, 0, 0) +#define ORAVER_9_2 ORAVERNUM(9, 2, 0, 0, 0) #define ORAVER_10_1 ORAVERNUM(10, 1, 0, 0, 0) #define ORAVER_10_2 ORAVERNUM(10, 2, 0, 0, 0) #define ORAVER_11_1 ORAVERNUM(11, 1, 0, 0, 0) Modified: trunk/ruby-oci8/ext/oci8/ocidatetime.c =================================================================== --- trunk/ruby-oci8/ext/oci8/ocidatetime.c 2008-08-31 14:11:39 UTC (rev 287) +++ trunk/ruby-oci8/ext/oci8/ocidatetime.c 2008-09-09 08:05:28 UTC (rev 288) @@ -100,7 +100,7 @@ SQLT_ODT, }; -#if defined RUNTIME_API_CHECK || ORACLE_CLIENT_VERSION >= ORAVER_9_1 +#if defined RUNTIME_API_CHECK || ORACLE_CLIENT_VERSION >= ORAVER_9_0 VALUE oci8_make_ocitimestamp(OCIDateTime *dttm) { @@ -432,14 +432,14 @@ SQLT_INTERVAL_DS }; -#endif /* defined RUNTIME_API_CHECK || ORACLE_CLIENT_VERSION >= ORAVER_9_1 */ +#endif /* defined RUNTIME_API_CHECK || ORACLE_CLIENT_VERSION >= ORAVER_9_0 */ void Init_oci_datetime(void) { oci8_define_bind_class("OCIDate", &bind_ocidate_class); -#if defined RUNTIME_API_CHECK || ORACLE_CLIENT_VERSION >= ORAVER_9_1 - if (oracle_client_version >= ORAVER_9_1) { +#if defined RUNTIME_API_CHECK || ORACLE_CLIENT_VERSION >= ORAVER_9_0 + if (oracle_client_version >= ORAVER_9_0) { oci8_define_bind_class("OCITimestamp", &bind_ocitimestamp_class); oci8_define_bind_class("OCIIntervalYM", &bind_ociinterval_ym_class); oci8_define_bind_class("OCIIntervalDS", &bind_ociinterval_ds_class); Modified: trunk/ruby-oci8/lib/oci8/datetime.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/datetime.rb 2008-08-31 14:11:39 UTC (rev 287) +++ trunk/ruby-oci8/lib/oci8/datetime.rb 2008-09-09 08:05:28 UTC (rev 288) @@ -95,7 +95,7 @@ end end - if OCI8.oracle_client_version >= ORAVER_9_1 + if OCI8.oracle_client_version >= ORAVER_9_0 def ocitimestamp_to_datetime(ary) year, month, day, hour, minute, sec, fsec, tz_hour, tz_min = ary @@ -165,7 +165,7 @@ end end - if OCI8.oracle_client_version >= ORAVER_9_1 + if OCI8.oracle_client_version >= ORAVER_9_0 class DateTimeViaOCITimestamp < OCI8::BindType::OCITimestamp include OCI8::BindType::Util @@ -275,7 +275,7 @@ # cursor.close # class DateTime - if OCI8.oracle_client_version >= ORAVER_9_1 + if OCI8.oracle_client_version >= ORAVER_9_0 def self.create(con, val, param, max_array_size) DateTimeViaOCITimestamp.new(con, val, param, max_array_size) end @@ -287,7 +287,7 @@ end class Time - if OCI8.oracle_client_version >= ORAVER_9_1 + if OCI8.oracle_client_version >= ORAVER_9_0 def self.create(con, val, param, max_array_size) TimeViaOCITimestamp.new(con, val, param, max_array_size) end @@ -298,7 +298,7 @@ end end - if OCI8.oracle_client_version >= ORAVER_9_1 + if OCI8.oracle_client_version >= ORAVER_9_0 #-- # OCI8::BindType::IntervalYM #++ Modified: trunk/ruby-oci8/lib/oci8/metadata.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/metadata.rb 2008-08-31 14:11:39 UTC (rev 287) +++ trunk/ruby-oci8/lib/oci8/metadata.rb 2008-09-09 08:05:28 UTC (rev 288) @@ -998,7 +998,7 @@ __charset_form end - if OCI8.oracle_client_version >= ORAVER_9_1 + if OCI8.oracle_client_version >= ORAVER_9_0 # The fractional seconds precision of a datetime or interval. # # (unavailable on Oracle 8.1 or lower) @@ -1332,7 +1332,7 @@ ## Table 6-13 Attributes Belonging to Columns of Tables or Views - if OCI8.oracle_client_version >= ORAVER_9_1 + if OCI8.oracle_client_version >= ORAVER_9_0 # returns the type of length semantics of the column. # [:byte] byte-length semantics # [:char] character-length semantics. @@ -1438,7 +1438,7 @@ ## Table 6-8 Attributes Belonging to Type Attributes ## But Column also have these. - if OCI8.oracle_client_version >= ORAVER_9_1 + if OCI8.oracle_client_version >= ORAVER_9_0 # The fractional seconds precision of a datetime or interval. # # (unavailable on Oracle 8.1 or lower) Modified: trunk/ruby-oci8/lib/oci8/oci8.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/oci8.rb 2008-08-31 14:11:39 UTC (rev 287) +++ trunk/ruby-oci8/lib/oci8/oci8.rb 2008-09-09 08:05:28 UTC (rev 288) @@ -701,7 +701,7 @@ # DATE SQLT_DAT 7 0 0 OCI8::BindType::Mapping[:date] = OCI8::BindType::Time -if OCI8.oracle_client_version >= OCI8::ORAVER_9_1 +if OCI8.oracle_client_version >= OCI8::ORAVER_9_0 OCI8::BindType::Mapping[:timestamp] = OCI8::BindType::Time OCI8::BindType::Mapping[:timestamp_tz] = OCI8::BindType::DateTime OCI8::BindType::Mapping[:timestamp_ltz] = OCI8::BindType::Time Modified: trunk/ruby-oci8/lib/oci8.rb.in =================================================================== --- trunk/ruby-oci8/lib/oci8.rb.in 2008-08-31 14:11:39 UTC (rev 287) +++ trunk/ruby-oci8/lib/oci8.rb.in 2008-09-09 08:05:28 UTC (rev 288) @@ -23,7 +23,7 @@ class OCI8 ORAVER_8_0 = 0x08000000 # 8.0 ORAVER_8_1 = 0x08100000 # 8.1 - ORAVER_9_1 = 0x09100000 # 9.1 + ORAVER_9_0 = 0x09000000 # 9.0 ORAVER_9_2 = 0x09200000 # 9.2 ORAVER_10_1 = 0x0a100000 # 10.1 ORAVER_10_2 = 0x0a200000 # 10.2 Modified: trunk/ruby-oci8/test/test_break.rb =================================================================== --- trunk/ruby-oci8/test/test_break.rb 2008-08-31 14:11:39 UTC (rev 287) +++ trunk/ruby-oci8/test/test_break.rb 2008-09-09 08:05:28 UTC (rev 288) @@ -64,7 +64,7 @@ assert_equal(true, @conn.non_blocking?) expect = [] if is_windows_server - if $oracle_server_version >= OCI8::ORAVER_9_1 + if $oracle_server_version >= OCI8::ORAVER_9_0 # raise after sleeping #{TIME_IN_PLSQL} seconds. expect[PLSQL_DONE] = "Invalid status" expect[OCIBREAK] = TIME_IN_PLSQL Modified: trunk/ruby-oci8/test/test_datetime.rb =================================================================== --- trunk/ruby-oci8/test/test_datetime.rb 2008-08-31 14:11:39 UTC (rev 287) +++ trunk/ruby-oci8/test/test_datetime.rb 2008-09-09 08:05:28 UTC (rev 288) @@ -71,7 +71,7 @@ end def test_timestamp_select - return if $oracle_version < OCI8::ORAVER_9_1 + return if $oracle_version < OCI8::ORAVER_9_0 ['2005-12-31 23:59:59.999999000', '2006-01-01 00:00:00.000000000'].each do |date| @@ -84,7 +84,7 @@ end def test_timestamp_out_bind - return if $oracle_version < OCI8::ORAVER_9_1 + return if $oracle_version < OCI8::ORAVER_9_0 cursor = @conn.parse(<<-EOS) BEGIN @@ -103,7 +103,7 @@ end def test_timestamp_in_bind - return if $oracle_version < OCI8::ORAVER_9_1 + return if $oracle_version < OCI8::ORAVER_9_0 cursor = @conn.parse(<<-EOS) BEGIN @@ -122,7 +122,7 @@ end def test_timestamp_tz_select - return if $oracle_version < OCI8::ORAVER_9_1 + return if $oracle_version < OCI8::ORAVER_9_0 ['2005-12-31 23:59:59.999999000 +08:30', '2006-01-01 00:00:00.000000000 -08:30'].each do |date| @@ -135,7 +135,7 @@ end def test_timestamp_tz_out_bind - return if $oracle_version < OCI8::ORAVER_9_1 + return if $oracle_version < OCI8::ORAVER_9_0 cursor = @conn.parse(<<-EOS) BEGIN @@ -154,7 +154,7 @@ end def test_timestamp_tz_in_bind - return if $oracle_version < OCI8::ORAVER_9_1 + return if $oracle_version < OCI8::ORAVER_9_0 cursor = @conn.parse(<<-EOS) BEGIN @@ -227,7 +227,7 @@ end def test_interval_ym_select - return if $oracle_version < OCI8::ORAVER_9_1 + return if $oracle_version < OCI8::ORAVER_9_0 [['2006-01-01', '2004-03-01'], ['2006-01-01', '2005-03-01'], @@ -245,7 +245,7 @@ end def test_interval_ym_out_bind - return if $oracle_version < OCI8::ORAVER_9_1 + return if $oracle_version < OCI8::ORAVER_9_0 cursor = @conn.parse(<<-EOS) DECLARE @@ -274,7 +274,7 @@ end def test_interval_ym_in_bind - return if $oracle_version < OCI8::ORAVER_9_1 + return if $oracle_version < OCI8::ORAVER_9_0 cursor = @conn.parse(<<-EOS) DECLARE @@ -301,7 +301,7 @@ end def test_interval_ds_select - return if $oracle_version < OCI8::ORAVER_9_1 + return if $oracle_version < OCI8::ORAVER_9_0 [['2006-01-01', '2004-03-01'], ['2006-01-01', '2005-03-01'], @@ -329,7 +329,7 @@ end def test_interval_ds_out_bind - return if $oracle_version < OCI8::ORAVER_9_1 + return if $oracle_version < OCI8::ORAVER_9_0 cursor = @conn.parse(<<-EOS) DECLARE @@ -368,7 +368,7 @@ end def test_interval_ds_in_bind - return if $oracle_version < OCI8::ORAVER_9_1 + return if $oracle_version < OCI8::ORAVER_9_0 cursor = @conn.parse(<<-EOS) DECLARE Modified: trunk/ruby-oci8/test/test_dbi.rb =================================================================== --- trunk/ruby-oci8/test/test_dbi.rb 2008-08-31 14:11:39 UTC (rev 287) +++ trunk/ruby-oci8/test/test_dbi.rb 2008-09-09 08:05:28 UTC (rev 288) @@ -102,7 +102,7 @@ sth = @dbh.prepare("INSERT INTO test_table VALUES (:C, :V, :N, :D1, :D2, :D3, :D4, :INT, :BIGNUM)") 1.upto(10) do |i| if i == 1 - if OCI8::oracle_client_version >= OCI8::ORAVER_9_1 + if OCI8::oracle_client_version >= OCI8::ORAVER_9_0 dt = nil v = '' sth.execute(format("%10d", i * 10), v, i, dt, dt, dt, dt, i, i) @@ -192,7 +192,7 @@ # data_size factor for nchar charset_form. sth = @dbh.execute("select N'1' from dual") cfrm = sth.column_info[0]['precision'] - if $oracle_version >= OCI8::ORAVER_9_1 + if $oracle_version >= OCI8::ORAVER_9_0 # data_size factor for char semantics. sth = @dbh.execute("select CAST('1' AS CHAR(1 char)) from dual") csem = sth.column_info[0]['precision'] @@ -202,16 +202,16 @@ ora80 = OCI8::ORAVER_8_0 ora81 = OCI8::ORAVER_8_1 - ora91 = OCI8::ORAVER_9_1 + ora90 = OCI8::ORAVER_9_0 ora101 = OCI8::ORAVER_10_1 coldef = [ # oracle_version, definition, sql_type, type_name, nullable, precision,scale,indexed,primary,unique,default [ora80, "CHAR(10) NOT NULL", DBI::SQL_CHAR, 'CHAR', false, 10, nil, true, true, true, nil], - [ora91, "CHAR(10 CHAR)", DBI::SQL_CHAR, 'CHAR', true, 10 * csem, nil, false,false,false,nil], + [ora90, "CHAR(10 CHAR)", DBI::SQL_CHAR, 'CHAR', true, 10 * csem, nil, false,false,false,nil], [ora80, "NCHAR(10)", DBI::SQL_CHAR, 'NCHAR', true, 10 * cfrm, nil, true, false,true, nil], [ora80, "VARCHAR2(10) DEFAULT 'a''b'", DBI::SQL_VARCHAR, 'VARCHAR2', true, 10, nil, true, false,false, "a'b"], - [ora91, "VARCHAR2(10 CHAR)", DBI::SQL_VARCHAR, 'VARCHAR2', true, 10 * csem, nil, false,false,false,nil], + [ora90, "VARCHAR2(10 CHAR)", DBI::SQL_VARCHAR, 'VARCHAR2', true, 10 * csem, nil, false,false,false,nil], [ora80, "NVARCHAR2(10)", DBI::SQL_VARCHAR, 'NVARCHAR2',true, 10 * cfrm, nil, false,false,false,nil], [ora80, "RAW(10)", DBI::SQL_VARBINARY, 'RAW', true, 10, nil, false,false,false,nil], [ora81, "CLOB", DBI::SQL_CLOB, 'CLOB', true, 4000, nil, false,false,false,nil], @@ -226,16 +226,16 @@ [ora101,"BINARY_FLOAT", DBI::SQL_FLOAT, 'BINARY_FLOAT', true, 7, nil, false,false,false,nil], [ora101,"BINARY_DOUBLE", DBI::SQL_DOUBLE, 'BINARY_DOUBLE', true, 16, nil, false,false,false,nil], [ora80, "DATE", DBI::SQL_DATE, 'DATE', true, 19, nil, false,false,false,nil], - [ora91, "TIMESTAMP", DBI::SQL_TIMESTAMP, 'TIMESTAMP', true, 20 + 6, nil, false,false,false,nil], - [ora91, "TIMESTAMP(9)", DBI::SQL_TIMESTAMP, 'TIMESTAMP', true, 20 + 9, nil, false,false,false,nil], - [ora91, "TIMESTAMP WITH TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH TIME ZONE', true, 27 + 6, nil, false,false,false,nil], - [ora91, "TIMESTAMP(9) WITH TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH TIME ZONE', true, 27 + 9, nil, false,false,false,nil], - [ora91, "TIMESTAMP WITH LOCAL TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH LOCAL TIME ZONE', true, 20 + 6, nil, false,false,false,nil], - [ora91, "TIMESTAMP(9) WITH LOCAL TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH LOCAL TIME ZONE', true, 20 + 9, nil, false,false,false,nil], - [ora91, "INTERVAL YEAR TO MONTH", DBI::SQL_OTHER, 'INTERVAL YEAR TO MONTH', true, 2 + 3, nil, false,false,false,nil], - [ora91, "INTERVAL YEAR(4) TO MONTH", DBI::SQL_OTHER, 'INTERVAL YEAR TO MONTH', true, 4 + 3, nil, false,false,false,nil], - [ora91, "INTERVAL DAY TO SECOND", DBI::SQL_OTHER, 'INTERVAL DAY TO SECOND', true, 2 + 10 + 6, nil, false,false,false,nil], - [ora91, "INTERVAL DAY(4) TO SECOND(9)",DBI::SQL_OTHER, 'INTERVAL DAY TO SECOND', true, 4 + 10 + 9, nil, false,false,false,nil], + [ora90, "TIMESTAMP", DBI::SQL_TIMESTAMP, 'TIMESTAMP', true, 20 + 6, nil, false,false,false,nil], + [ora90, "TIMESTAMP(9)", DBI::SQL_TIMESTAMP, 'TIMESTAMP', true, 20 + 9, nil, false,false,false,nil], + [ora90, "TIMESTAMP WITH TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH TIME ZONE', true, 27 + 6, nil, false,false,false,nil], + [ora90, "TIMESTAMP(9) WITH TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH TIME ZONE', true, 27 + 9, nil, false,false,false,nil], + [ora90, "TIMESTAMP WITH LOCAL TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH LOCAL TIME ZONE', true, 20 + 6, nil, false,false,false,nil], + [ora90, "TIMESTAMP(9) WITH LOCAL TIME ZONE", DBI::SQL_TIMESTAMP, 'TIMESTAMP WITH LOCAL TIME ZONE', true, 20 + 9, nil, false,false,false,nil], + [ora90, "INTERVAL YEAR TO MONTH", DBI::SQL_OTHER, 'INTERVAL YEAR TO MONTH', true, 2 + 3, nil, false,false,false,nil], + [ora90, "INTERVAL YEAR(4) TO MONTH", DBI::SQL_OTHER, 'INTERVAL YEAR TO MONTH', true, 4 + 3, nil, false,false,false,nil], + [ora90, "INTERVAL DAY TO SECOND", DBI::SQL_OTHER, 'INTERVAL DAY TO SECOND', true, 2 + 10 + 6, nil, false,false,false,nil], + [ora90, "INTERVAL DAY(4) TO SECOND(9)",DBI::SQL_OTHER, 'INTERVAL DAY TO SECOND', true, 4 + 10 + 9, nil, false,false,false,nil], ] coldef.reject! do |c| c[0] > $oracle_version end Modified: trunk/ruby-oci8/test/test_metadata.rb =================================================================== --- trunk/ruby-oci8/test/test_metadata.rb 2008-08-31 14:11:39 UTC (rev 287) +++ trunk/ruby-oci8/test/test_metadata.rb 2008-09-09 08:05:28 UTC (rev 288) @@ -25,7 +25,7 @@ # data_size factor for nchar charset_form. cursor = @conn.exec("select N'1' from dual") cfrm = cursor.column_metadata[0].data_size - if $oracle_version >= OCI8::ORAVER_9_1 + if $oracle_version >= OCI8::ORAVER_9_0 # data_size factor for char semantics. cursor = @conn.exec("select CAST('1' AS CHAR(1 char)) from dual") csem = cursor.column_metadata[0].data_size @@ -35,16 +35,16 @@ ora80 = OCI8::ORAVER_8_0 ora81 = OCI8::ORAVER_8_1 - ora91 = OCI8::ORAVER_9_1 + ora90 = OCI8::ORAVER_9_0 ora101 = OCI8::ORAVER_10_1 coldef = [ # oracle_version, definition, data_type, csfrm, null?,csem?,csize, data_size,prec,scale,fsprec,lfprec [ora80, "CHAR(10) NOT NULL", :char, :implicit, false, false, 10, 10, 0, 0, 0, 0], - [ora91, "CHAR(10 CHAR)", :char, :implicit, true, true, 10, 10 * csem, 0, 0, 0, 0], + [ora90, "CHAR(10 CHAR)", :char, :implicit, true, true, 10, 10 * csem, 0, 0, 0, 0], [ora80, "NCHAR(10)", :char, :nchar, true, true, 10, 10 * cfrm, 0, 0, 0, 0], [ora80, "VARCHAR2(10)", :varchar2, :implicit, true, false, 10, 10, 0, 0, 0, 0], - [ora91, "VARCHAR2(10 CHAR)", :varchar2, :implicit, true, true, 10, 10 * csem, 0, 0, 0, 0], + [ora90, "VARCHAR2(10 CHAR)", :varchar2, :implicit, true, true, 10, 10 * csem, 0, 0, 0, 0], [ora80, "NVARCHAR2(10)", :varchar2, :nchar, true, true, 10, 10 * cfrm, 0, 0, 0, 0], [ora80, "RAW(10)", :raw, nil, true, false, 0, 10, 0, 0, 0, 0], @@ -84,7 +84,7 @@ # | FLOAT(10) | implicit | 129 | 10 | # | | explicit | 10 | 129 | # +----------------+----------+-------------+-------------+ - [ora80, "NUMBER", :number, nil, true, false, 0, 22, 0, $oracle_version >= ora91 ? -127 : 0, :nc, :nc], + [ora80, "NUMBER", :number, nil, true, false, 0, 22, 0, $oracle_version >= ora90 ? -127 : 0, :nc, :nc], [ora80, "NUMBER(10)", :number, nil, true, false, 0, 22, 10, 0, :nc, :nc], [ora80, "NUMBER(10,2)", :number, nil, true, false, 0, 22, 10, 2, :nc, :nc], [ora80, "FLOAT", :number, nil, true, false, 0, 22, 126, -127, :nc, :nc], @@ -118,12 +118,12 @@ # | TIMESTAMP(9) WITH LOCAL TIME ZONE | implicit | 0 | 0 | # | | explicit | 9 | 9 | # +-----------------------------------+----------+-----------+-------------+ - [ora91, "TIMESTAMP", :timestamp, nil, true, false, 0, 11, :nc, 6, 6, :nc], - [ora91, "TIMESTAMP(9)", :timestamp, nil, true, false, 0, 11, :nc, 9, 9, :nc], - [ora91, "TIMESTAMP WITH TIME ZONE", :timestamp_tz, nil, true, false, 0, 13, :nc, 6, 6, :nc], - [ora91, "TIMESTAMP(9) WITH TIME ZONE", :timestamp_tz, nil, true, false, 0, 13, :nc, 9, 9, :nc], - [ora91, "TIMESTAMP WITH LOCAL TIME ZONE", :timestamp_ltz, nil, true, false, 0, 11, :nc, 6, 6, :nc], - [ora91, "TIMESTAMP(9) WITH LOCAL TIME ZONE", :timestamp_ltz, nil, true, false, 0, 11, :nc, 9, 9, :nc], + [ora90, "TIMESTAMP", :timestamp, nil, true, false, 0, 11, :nc, 6, 6, :nc], + [ora90, "TIMESTAMP(9)", :timestamp, nil, true, false, 0, 11, :nc, 9, 9, :nc], + [ora90, "TIMESTAMP WITH TIME ZONE", :timestamp_tz, nil, true, false, 0, 13, :nc, 6, 6, :nc], + [ora90, "TIMESTAMP(9) WITH TIME ZONE", :timestamp_tz, nil, true, false, 0, 13, :nc, 9, 9, :nc], + [ora90, "TIMESTAMP WITH LOCAL TIME ZONE", :timestamp_ltz, nil, true, false, 0, 11, :nc, 6, 6, :nc], + [ora90, "TIMESTAMP(9) WITH LOCAL TIME ZONE", :timestamp_ltz, nil, true, false, 0, 11, :nc, 9, 9, :nc], # Don't check scale and fsprecision for INTERVAL YEAR TO MONTH # @@ -137,8 +137,8 @@ # | INTERVAL YEAR(4) TO MONTH | implicit | 0 | 0 | # | | explicit | 4 | 4 | # +------------------------------+----------+-----------+-------------+ - [ora91, "INTERVAL YEAR TO MONTH", :interval_ym, nil, true, false, 0, 5, 2, :nc, :nc, 2], - [ora91, "INTERVAL YEAR(4) TO MONTH", :interval_ym, nil, true, false, 0, 5, 4, :nc, :nc, 4], + [ora90, "INTERVAL YEAR TO MONTH", :interval_ym, nil, true, false, 0, 5, 2, :nc, :nc, 2], + [ora90, "INTERVAL YEAR(4) TO MONTH", :interval_ym, nil, true, false, 0, 5, 4, :nc, :nc, 4], # Don't check precision and scale for INTERVAL DAY TO SECOND # @@ -152,8 +152,8 @@ # | INTERVAL DAY(4) TO SECOND(9) | implicit | 4 | 9 | # | | explicit | 9 | 4 | # +------------------------------+----------+-----------+-----------+ - [ora91, "INTERVAL DAY TO SECOND", :interval_ds, nil, true, false, 0, 11, :nc, :nc, 6, 2], - [ora91, "INTERVAL DAY(4) TO SECOND(9)",:interval_ds, nil, true, false, 0, 11, :nc, :nc, 9, 4], + [ora90, "INTERVAL DAY TO SECOND", :interval_ds, nil, true, false, 0, 11, :nc, :nc, 6, 2], + [ora90, "INTERVAL DAY(4) TO SECOND(9)",:interval_ds, nil, true, false, 0, 11, :nc, :nc, 9, 4], ] coldef.reject! do |c| c[0] > $oracle_version end @@ -178,7 +178,7 @@ assert_equal(coldef[i][3], md.charset_form, "'#{coldef[i][1]}': charset_form") assert_equal(coldef[i][4], md.nullable?, "'#{coldef[i][1]}': nullable? ") # string type - if $oracle_version >= OCI8::ORAVER_9_1 + if $oracle_version >= OCI8::ORAVER_9_0 assert_equal(coldef[i][5], md.char_used?, "'#{coldef[i][1]}': char_used? ") assert_equal(coldef[i][6], md.char_size, "'#{coldef[i][1]}': char_size") end @@ -186,7 +186,7 @@ # number, timestamp and interval type assert_equal(coldef[i][8], md.precision, "'#{coldef[i][1]}': precision") if coldef[i][8] != :nc assert_equal(coldef[i][9], md.scale, "'#{coldef[i][1]}': scale") if coldef[i][9] != :nc - if $oracle_version >= OCI8::ORAVER_9_1 + if $oracle_version >= OCI8::ORAVER_9_0 assert_equal(coldef[i][10], md.fsprecision, "'#{coldef[i][1]}': fsprecision") if coldef[i][10] != :nc assert_equal(coldef[i][11], md.lfprecision, "'#{coldef[i][1]}': lfprecision") if coldef[i][11] != :nc end @@ -216,7 +216,7 @@ assert_equal(coldef[i][3], md.charset_form, "'#{coldef[i][1]}': charset_form") assert_equal(coldef[i][4], md.nullable?, "'#{coldef[i][1]}': nullable? ") # string type - if $oracle_version >= OCI8::ORAVER_9_1 + if $oracle_version >= OCI8::ORAVER_9_0 assert_equal(coldef[i][5], md.char_used?, "'#{coldef[i][1]}': char_used? ") assert_equal(coldef[i][6], md.char_size, "'#{coldef[i][1]}': char_size") end @@ -224,7 +224,7 @@ # number, timestamp and interval type assert_equal(coldef[i][8], md.precision, "'#{coldef[i][1]}': precision") if coldef[i][8] != :nc assert_equal(coldef[i][9], md.scale, "'#{coldef[i][1]}': scale") if coldef[i][9] != :nc - if $oracle_version >= OCI8::ORAVER_9_1 + if $oracle_version >= OCI8::ORAVER_9_0 assert_equal(coldef[i][10], md.fsprecision, "'#{coldef[i][1]}': fsprecision") if coldef[i][10] != :nc assert_equal(coldef[i][11], md.lfprecision, "'#{coldef[i][1]}': lfprecision") if coldef[i][11] != :nc end From nobody at rubyforge.org Wed Sep 10 10:07:07 2008 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Wed, 10 Sep 2008 10:07:07 -0400 (EDT) Subject: [ruby-oci8-commit] [289] trunk/ruby-oci8: * ext/oci8/ocidatetime.c: use session time zone when time zone Message-ID: <20080910140707.E6CE61858289@rubyforge.org> Revision: 289 Author: kubo Date: 2008-09-10 10:07:07 -0400 (Wed, 10 Sep 2008) Log Message: ----------- * ext/oci8/ocidatetime.c: use session time zone when time zone is not specified to set bind objects of timestamp with time zone datatype. * lib/oci8/datetime.rb: add OCI8::BindType::Util.default_timezone to get Time or DateTime objects from bind objects of date datatype. * test/test_datetime.rb: fix test_datetype_duck_typing and add test_timezone for the above changes. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/ext/oci8/ocidatetime.c trunk/ruby-oci8/lib/oci8/datetime.rb trunk/ruby-oci8/test/test_datetime.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2008-09-09 08:05:28 UTC (rev 288) +++ trunk/ruby-oci8/ChangeLog 2008-09-10 14:07:07 UTC (rev 289) @@ -1,3 +1,13 @@ +2008-09-10 KUBO Takehiro + * ext/oci8/ocidatetime.c: use session time zone when time zone + is not specified to set bind objects of timestamp with time + zone datatype. + * lib/oci8/datetime.rb: add OCI8::BindType::Util.default_timezone + to get Time or DateTime objects from bind objects of date + datatype. + * test/test_datetime.rb: fix test_datetype_duck_typing and add + test_timezone for the above changes. + 2008-09-09 KUBO Takehiro * ext/oci8/apiwrap.rb, ext/oci8/apiwrap.yml, ext/oci8/oci8.h, ext/oci8/ocidatetime.c, lib/oci8.rb.in, lib/oci8/datetime.rb, Modified: trunk/ruby-oci8/ext/oci8/ocidatetime.c =================================================================== --- trunk/ruby-oci8/ext/oci8/ocidatetime.c 2008-09-09 08:05:28 UTC (rev 288) +++ trunk/ruby-oci8/ext/oci8/ocidatetime.c 2008-09-10 14:07:07 UTC (rev 289) @@ -132,7 +132,7 @@ have_tz ? INT2FIX(tz_minute) : Qnil); } -OCIDateTime *oci8_set_ocitimestamp(OCIDateTime *dttm, VALUE val) +OCIDateTime *oci8_set_ocitimestamp(OCIDateTime *dttm, VALUE val, VALUE svc) { long year; long month; @@ -141,7 +141,10 @@ long minute; long sec; long fsec; + OraText *tz; + size_t tzlen; char tz_str[32]; + OCISession *seshp = NULL; Check_Type(val, T_ARRAY); if (RARRAY_LEN(val) != 9) { @@ -184,15 +187,22 @@ } /* time zone */ if (NIL_P(RARRAY_PTR(val)[7]) && NIL_P(RARRAY_PTR(val)[8])) { - /* use session timezone. */ - tz_str[0] = '\0'; + if (!NIL_P(svc)) { + /* use session timezone. */ + seshp = oci8_get_oci_session(svc); + } + tz = NULL; + tzlen = 0; } else { - sprintf(tz_str, "%+02ld:%02ld", - NUM2LONG(RARRAY_PTR(val)[7]), - NUM2LONG(RARRAY_PTR(val)[8])); + snprintf(tz_str, sizeof(tz_str), "%+02ld:%02ld", + NUM2LONG(RARRAY_PTR(val)[7]), + NUM2LONG(RARRAY_PTR(val)[8])); + tz_str[sizeof(tz_str) - 1] = '\0'; + tz = (OraText*)tz_str; + tzlen = strlen(tz_str); } /* construct */ - oci_lc(OCIDateTimeConstruct(oci8_envhp, oci8_errhp, dttm, + oci_lc(OCIDateTimeConstruct(seshp ? (void*)seshp : (void*)oci8_envhp, oci8_errhp, dttm, (sb2)year, (ub1)month, (ub1)day, @@ -200,8 +210,7 @@ (ub1)minute, (ub1)sec, (ub4)fsec, - (OraText *)tz_str, - strlen(tz_str))); + tz, tzlen)); return dttm; } @@ -235,7 +244,22 @@ static void bind_ocitimestamp_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val) { - oci8_set_ocitimestamp(*(OCIDateTime **)data, val); + oci8_base_t *stmt; + oci8_base_t *svcctx; + + stmt = obind->base.parent; + if (stmt == NULL || stmt->type != OCI_HTYPE_STMT) { + rb_raise(rb_eRuntimeError, "oci8lib.so internal error [%s:%d, %p, %d]", + __FILE__, __LINE__, + stmt, stmt ? stmt->type : -1); + } + svcctx = stmt->parent; + if (svcctx == NULL || svcctx->type != OCI_HTYPE_SVCCTX) { + rb_raise(rb_eRuntimeError, "oci8lib.so internal error [%s:%d, %p, %d]", + __FILE__, __LINE__, + svcctx, svcctx ? svcctx->type : -1); + } + oci8_set_ocitimestamp(*(OCIDateTime **)data, val, svcctx->self); } static void bind_ocitimestamp_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length) Modified: trunk/ruby-oci8/lib/oci8/datetime.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/datetime.rb 2008-09-09 08:05:28 UTC (rev 288) +++ trunk/ruby-oci8/lib/oci8/datetime.rb 2008-09-10 14:07:07 UTC (rev 289) @@ -10,6 +10,24 @@ @@time_offset = ::Time.now.utc_offset @@datetime_offset = ::DateTime.now.offset + @@default_timezone = :local + def self.default_timezone + @@default_timezone + end + + # Determines default timezone of Time and DateTime retrived from Oracle. + # This accepts :local or :utc. The default is :local. + # + # This parameter is used when both or either of Oracle server and client + # version is Oracle 8i or lower. If both versions are Oracle 9i or upper, + # the default timezone is determined by session timezone. + def self.default_timezone=(tz) + if tz != :local and tz != :utc + raise ArgumentError, "expected :local or :utc but #{tz}" + end + @@default_timezone = tz + end + private def datetime_to_array(val, full) @@ -83,13 +101,18 @@ def ocidate_to_datetime(ary) year, month, day, hour, minute, sec = ary - ::DateTime.civil(year, month, day, hour, minute, sec, @@datetime_offset) + if @@default_timezone == :local + offset = @@datetime_offset + else + offset = 0 + end + ::DateTime.civil(year, month, day, hour, minute, sec, offset) end def ocidate_to_time(ary) year, month, day, hour, minute, sec = ary begin - ::Time.local(year, month, day, hour, minute, sec) + ::Time.send(@@default_timezone, year, month, day, hour, minute, sec) rescue StandardError ocidate_to_datetime(ary) end @@ -277,7 +300,11 @@ class DateTime if OCI8.oracle_client_version >= ORAVER_9_0 def self.create(con, val, param, max_array_size) - DateTimeViaOCITimestamp.new(con, val, param, max_array_size) + if true # TODO: check Oracle server version + DateTimeViaOCITimestamp.new(con, val, param, max_array_size) + else + DateTimeViaOCIDate.new(con, val, param, max_array_size) + end end else def self.create(con, val, param, max_array_size) @@ -289,7 +316,11 @@ class Time if OCI8.oracle_client_version >= ORAVER_9_0 def self.create(con, val, param, max_array_size) - TimeViaOCITimestamp.new(con, val, param, max_array_size) + if true # TODO: check Oracle server version + TimeViaOCITimestamp.new(con, val, param, max_array_size) + else + TimeViaOCIDate.new(con, val, param, max_array_size) + end end else def self.create(con, val, param, max_array_size) Modified: trunk/ruby-oci8/test/test_datetime.rb =================================================================== --- trunk/ruby-oci8/test/test_datetime.rb 2008-09-09 08:05:28 UTC (rev 288) +++ trunk/ruby-oci8/test/test_datetime.rb 2008-09-10 14:07:07 UTC (rev 289) @@ -183,27 +183,31 @@ def obj.day; 31; end cursor[:in] = obj cursor.exec - assert_equal(DateTime.parse('2006-12-31'), cursor[:out]) + assert_equal(DateTime.parse('2006-12-31 00:00:00' + @local_timezone), cursor[:out]) # test hour def obj.hour; 23; end cursor[:in] = obj cursor.exec - assert_equal(DateTime.parse('2006-12-31 23:00:00'), cursor[:out]) + assert_equal(DateTime.parse('2006-12-31 23:00:00' + @local_timezone), cursor[:out]) # test min def obj.min; 59; end cursor[:in] = obj cursor.exec - assert_equal(DateTime.parse('2006-12-31 23:59:00'), cursor[:out]) + assert_equal(DateTime.parse('2006-12-31 23:59:00' + @local_timezone), cursor[:out]) # test sec def obj.sec; 59; end cursor[:in] = obj cursor.exec - assert_equal(DateTime.parse('2006-12-31 23:59:59'), cursor[:out]) + assert_equal(DateTime.parse('2006-12-31 23:59:59' + @local_timezone), cursor[:out]) + + # sec_fraction and timezone are available on Oracle 9i or later + return if $oracle_version < OCI8::ORAVER_9_0 + # test sec_fraction def obj.sec_fraction; DateTime.parse('0001-01-01 00:00:00.000001').sec_fraction * 999999 ; end cursor[:in] = obj cursor.exec - assert_equal(DateTime.parse('2006-12-31 23:59:59.999999'), cursor[:out]) + assert_equal(DateTime.parse('2006-12-31 23:59:59.999999' + @local_timezone), cursor[:out]) # test utc_offset (Time) def obj.utc_offset; @utc_offset; end obj.instance_variable_set(:@utc_offset, 9 * 60 * 60) @@ -226,6 +230,67 @@ assert_equal(DateTime.parse('2006-12-31 23:59:59.999999 -05:00'), cursor[:out]) end + def test_timezone + if $oracle_version >= OCI8::ORAVER_9_0 + # temporarily change the mapping to test OCI8::BindType::Util.default_timezone. + OCI8::BindType::Mapping[:date] = OCI8::BindType::TimeViaOCIDate + end + begin + assert_raise(ArgumentError) do + OCI8::BindType::Util.default_timezone = :invalid_value + end + + [:local, :utc].each do |tz| + OCI8::BindType::Util.default_timezone = tz + @conn.exec("select sysdate, to_date('2008-01-02', 'yyyy-mm-dd') from dual") do |row| + row.each do |dt| + assert_kind_of(Time, dt) + assert_equal(tz, dt.utc? ? :utc : :local) + end + assert_equal(2008, row[1].year) + assert_equal(1, row[1].month) + assert_equal(2, row[1].day) + end + end + ensure + OCI8::BindType::Util.default_timezone = :local + if $oracle_version >= OCI8::ORAVER_9_0 + OCI8::BindType::Mapping[:date] = OCI8::BindType::Time + end + end + + if $oracle_version >= OCI8::ORAVER_9_0 + ses_tz = nil + @conn.exec('select sessiontimezone from dual') do |row| + ses_tz = row[0] + end + + begin + ['+09:00', '+00:00', '-05:00'].each do |tz| + @conn.exec("alter session set time_zone = '#{tz}'") + @conn.exec("select current_timestamp, sysdate, to_timestamp('2008-01-02', 'yyyy-mm-dd') from dual") do |row| + row.each do |dt| + case dt + when Time + assert_equal(tz, timezone_string(*((dt.utc_offset / 60).divmod 60))) + when DateTime + assert_equal(tz, dt.zone) + else + flunk "unexpedted type #{dt.class}" + end + end + assert_equal(2008, row[2].year) + assert_equal(1, row[2].month) + assert_equal(2, row[2].day) + end + end + ensure + @conn.exec("alter session set time_zone = '#{ses_tz}'") + end + else + end + end + def test_interval_ym_select return if $oracle_version < OCI8::ORAVER_9_0