From nobody at rubyforge.org Sat Jul 28 11:50:49 2012 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 28 Jul 2012 11:50:49 +0000 (UTC) Subject: [ruby-oci8-commit] [527] trunk/ruby-oci8: add OCI8::Cursor#statement. Message-ID: <20120728115049.3627D2E060@rubyforge.org> Revision: 527 Author: kubo Date: 2012-07-28 11:50:48 +0000 (Sat, 28 Jul 2012) Log Message: ----------- add OCI8::Cursor#statement. See github issue #12 requested by timon. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/lib/oci8/oci8.rb trunk/ruby-oci8/test/test_oci8.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2012-05-25 12:13:15 UTC (rev 526) +++ trunk/ruby-oci8/ChangeLog 2012-07-28 11:50:48 UTC (rev 527) @@ -1,3 +1,7 @@ +2012-07-28 KUBO Takehiro + * lib/oci8/oci8.rb, test/test_oci8.rb: add OCI8::Cursor#statement. + See github issue #12 requested by timon. + 2012-05-25 KUBO Takehiro * test/test_clob.rb: speed up clob tests 29 times. Modified: trunk/ruby-oci8/lib/oci8/oci8.rb =================================================================== --- trunk/ruby-oci8/lib/oci8/oci8.rb 2012-05-25 12:13:15 UTC (rev 526) +++ trunk/ruby-oci8/lib/oci8/oci8.rb 2012-07-28 11:50:48 UTC (rev 527) @@ -606,6 +606,24 @@ @column_metadata = nil end # close + # Returns the text of the SQL statement prepared in the cursor. + # + # @note + # When {http://docs.oracle.com/cd/E11882_01/server.112/e10729/ch7progrunicode.htm#CACHHIFE + # NCHAR String Literal Replacement} is turned on, it returns the modified SQL text, + # instead of the original SQL text. + # + # @example + # cursor = conn.parse("select * from country where country_code = 'ja'") + # cursor.statement # => "select * from country where country_code = 'ja'" + # + # @return [String] + def statement + # The magic number 144 is OCI_ATTR_STATEMENT. + # See http://docs.oracle.com/cd/E11882_01/appdev.112/e10646/ociaahan.htm#sthref5503 + attr_get_string(144) + end + private def make_bind_object(param) Modified: trunk/ruby-oci8/test/test_oci8.rb =================================================================== --- trunk/ruby-oci8/test/test_oci8.rb 2012-05-25 12:13:15 UTC (rev 526) +++ trunk/ruby-oci8/test/test_oci8.rb 2012-07-28 11:50:48 UTC (rev 527) @@ -439,6 +439,12 @@ end end + def test_parse_sets_query_on_cursor + statement = "select * from country where country_code = 'ja'" + cursor = @conn.parse(statement) + assert_equal(statement, cursor.statement) + end + def test_last_error # OCI8#parse and OCI8#exec reset OCI8#last_error @conn.last_error = 'dummy' From nobody at rubyforge.org Sat Jul 28 12:12:26 2012 From: nobody at rubyforge.org (nobody at rubyforge.org) Date: Sat, 28 Jul 2012 12:12:26 +0000 (UTC) Subject: [ruby-oci8-commit] [528] trunk/ruby-oci8: fix a sequence test failure on Oracle 11gR2. Message-ID: <20120728121226.8DA622E060@rubyforge.org> Revision: 528 Author: kubo Date: 2012-07-28 12:12:26 +0000 (Sat, 28 Jul 2012) Log Message: ----------- fix a sequence test failure on Oracle 11gR2. Fix github issue #18 reported by Yasuo Honda. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/test/test_metadata.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2012-07-28 11:50:48 UTC (rev 527) +++ trunk/ruby-oci8/ChangeLog 2012-07-28 12:12:26 UTC (rev 528) @@ -1,4 +1,8 @@ 2012-07-28 KUBO Takehiro + * test/test_metadata.rb: fix a sequence test failure on Oracle 11gR2. + Fix github issue #18 reported by Yasuo Honda. + +2012-07-28 KUBO Takehiro * lib/oci8/oci8.rb, test/test_oci8.rb: add OCI8::Cursor#statement. See github issue #12 requested by timon. Modified: trunk/ruby-oci8/test/test_metadata.rb =================================================================== --- trunk/ruby-oci8/test/test_metadata.rb 2012-07-28 11:50:48 UTC (rev 527) +++ trunk/ruby-oci8/test/test_metadata.rb 2012-07-28 12:12:26 UTC (rev 528) @@ -1406,6 +1406,33 @@ drop_table('test_table') end # test_column_metadata + def assert_sequence(sequence_name, desc) + # defined in OCI8::Metadata::Base + assert_object_id(sequence_name, desc.obj_id) + assert_equal(sequence_name, desc.obj_name, 'obj_name') + assert_equal(@conn.username, desc.obj_schema, 'obj_schema') + # defined in OCI8::Metadata::Sequence + assert_object_id(sequence_name, desc.objid) + min, max, incr, cache, order = @conn.select_one(< Revision: 529 Author: kubo Date: 2012-07-31 11:21:28 +0000 (Tue, 31 Jul 2012) Log Message: ----------- refactor test code by adding global functions convert_to_time() and convert_to_datetime(), which will be used by test_object.rb later. Modified Paths: -------------- trunk/ruby-oci8/ChangeLog trunk/ruby-oci8/test/config.rb trunk/ruby-oci8/test/test_datetime.rb Modified: trunk/ruby-oci8/ChangeLog =================================================================== --- trunk/ruby-oci8/ChangeLog 2012-07-28 12:12:26 UTC (rev 528) +++ trunk/ruby-oci8/ChangeLog 2012-07-31 11:21:28 UTC (rev 529) @@ -1,3 +1,8 @@ +2012-07-31 KUBO Takehiro + * test/config.rb, test/test_datetime.rb: refactor test code by adding + global functions convert_to_time() and convert_to_datetime(), + which will be used by test_object.rb later. + 2012-07-28 KUBO Takehiro * test/test_metadata.rb: fix a sequence test failure on Oracle 11gR2. Fix github issue #18 reported by Yasuo Honda. Modified: trunk/ruby-oci8/test/config.rb =================================================================== --- trunk/ruby-oci8/test/config.rb 2012-07-28 12:12:26 UTC (rev 528) +++ trunk/ruby-oci8/test/config.rb 2012-07-31 11:21:28 UTC (rev 529) @@ -44,6 +44,53 @@ $test_clob = true end +begin + Time.new(2001, 1, 1, 0, 0, 0, '+00:00') + # ruby 1.9.2 or later + def convert_to_time(year, month, day, hour, minute, sec, subsec, timezone) + subsec ||= 0 + if timezone + # with time zone + Time.new(year, month, day, hour, minute, sec + subsec, timezone) + else + # without time zone + Time.local(year, month, day, hour, minute, sec, subsec * 1000000) + end + end +rescue + # ruby 1.9.1 or former + def convert_to_time(year, month, day, hour, minute, sec, subsec, timezone) + subsec ||= 0 + if timezone + # with time zone + /([+-])(\d+):(\d+)/ =~ timezone + offset = ($1 + '1').to_i * ($2.to_i * 60 + $3.to_i) + if offset == 0 + Time.utc(year, month, day, hour, minute, sec, subsec * 1000000) + else + tm = Time.local(year, month, day, hour, minute, sec, subsec * 1000000) + raise "Failed to convert #{str} to Time" if tm.utc_offset != offset * 60 + tm + end + else + # without time zone + Time.local(year, month, day, hour, minute, sec, subsec * 1000000) + end + end +end + +def convert_to_datetime(year, month, day, hour, minute, sec, subsec, timezone) + subsec ||= 0 + utc_offset = if timezone + # with time zone + /([+-])(\d+):(\d+)/ =~ timezone + ($1 + '1').to_i * ($2.to_i * 60 + $3.to_i) * 60 + else + Time.local(year, month, day, hour, minute, sec).utc_offset + end + DateTime.civil(year, month, day, hour, minute, sec + subsec, utc_offset.to_r / 86400) +end + module Test module Unit class TestCase Modified: trunk/ruby-oci8/test/test_datetime.rb =================================================================== --- trunk/ruby-oci8/test/test_datetime.rb 2012-07-28 12:12:26 UTC (rev 528) +++ trunk/ruby-oci8/test/test_datetime.rb 2012-07-31 11:21:28 UTC (rev 529) @@ -13,59 +13,20 @@ end end - @@time_new_accepts_timezone = begin - Time.new(2001, 1, 1, 0, 0, 0, '+00:00') - true - rescue - false - end - def string_to_time(str) - /(\d+)-(\d+)-(\d+) ?(?:(\d+):(\d+):(\d+))?(?:\.(\d+))? ?(([+-])(\d+):(\d+))?/ =~ str - args = [] - args << $1.to_i # year - args << $2.to_i # month - args << $3.to_i # day - args << $4.to_i if $4 # hour - args << $5.to_i if $5 # minute - if $8 and @@time_new_accepts_timezone - args << $6.to_i + $7.to_i.to_r / ('1' + '0' * ($7.length)).to_i - args << $8 - Time.new(*args) - else - if $6 - args << $6.to_i - end - if $7 - args << $7.to_i.to_r * 1000000 / ('1' + '0' * ($7.length)).to_i - end - if $8 - # with time zone - offset = ($9 + '1').to_i * ($10.to_i * 60 + $11.to_i) - if offset == 0 - Time.utc(*args) - else - tm = Time.local(*args) - raise "Failed to convert #{str} to Time" if tm.utc_offset != offset * 60 - tm - end - else - # without time zone - Time.local(*args) - end + /(\d+)-(\d+)-(\d+) ?(?:(\d+):(\d+):(\d+))?(?:\.(\d+))? ?([+-]\d+:\d+)?/ =~ str + if $7 + subsec = $7.to_i.to_r / ('1' + '0' * ($7.length)).to_i end - #Time.local(*str.split(/[- :\.]/).collect do |n| n.to_i; end) + convert_to_time($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, subsec, $8) end def string_to_datetime(str) - /(\d+-\d+-\d+ ?(?:\d+:\d+:\d+)?(?:\.\d+)?) ?([+-]\d+:\d+)?/ =~ str - if $2 - # with time zone - DateTime.parse(str) - else - tm = string_to_time(str) - DateTime.parse(str + timezone_string(*((tm.utc_offset / 60).divmod 60))) + /(\d+)-(\d+)-(\d+) ?(?:(\d+):(\d+):(\d+))?(?:\.(\d+))? ?([+-]\d+:\d+)?/ =~ str + if $7 + subsec = $7.to_i.to_r / ('1' + '0' * ($7.length)).to_i end + convert_to_datetime($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, subsec, $8) end def setup