[ruby-oci8-commit] [527] trunk/ruby-oci8: add OCI8::Cursor#statement.

nobody at rubyforge.org nobody at rubyforge.org
Sat Jul 28 11:50:49 UTC 2012


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  <kubo at jiubao.org>
+	* lib/oci8/oci8.rb, test/test_oci8.rb: add OCI8::Cursor#statement.
+	   See github issue #12 requested by timon.
+
 2012-05-25  KUBO Takehiro  <kubo at jiubao.org>
 	* 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'



More information about the ruby-oci8-commit mailing list