[ruby-oci8-commit] [561] trunk/ruby-oci8: set 'rubyoci8' as the driver name, which is displayed in V$SESSION_CONNECT_INFO.CLIENT_DRIVER.

nobody at rubyforge.org nobody at rubyforge.org
Sun Mar 3 11:48:59 UTC 2013


Revision: 561
Author:   kubo
Date:     2013-03-03 11:48:59 +0000 (Sun, 03 Mar 2013)
Log Message:
-----------
set 'rubyoci8' as the driver name, which is displayed in V$SESSION_CONNECT_INFO.CLIENT_DRIVER.
(require Oracle 11g or upper)

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	2013-03-03 06:09:22 UTC (rev 560)
+++ trunk/ruby-oci8/ChangeLog	2013-03-03 11:48:59 UTC (rev 561)
@@ -1,4 +1,10 @@
 2013-03-03  KUBO Takehiro  <kubo at jiubao.org>
+	* lib/oci8/oci8.rb, test/test_oci8.rb: set 'rubyoci8' as
+	    the driver name, which is displayed in
+	    V$SESSION_CONNECT_INFO.CLIENT_DRIVER.
+	    (require Oracle 11g or upper)
+
+2013-03-03  KUBO Takehiro  <kubo at jiubao.org>
 	* lib/oci8.rb.in: use RbConfig::CONFIG instead of obsolete
 	    constant Config::CONFIG.
 	* lib/oci8/object.rb, test/test_bind_time.rb, test/test_metadata.rb

Modified: trunk/ruby-oci8/lib/oci8/oci8.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/oci8.rb	2013-03-03 06:09:22 UTC (rev 560)
+++ trunk/ruby-oci8/lib/oci8/oci8.rb	2013-03-03 11:48:59 UTC (rev 561)
@@ -1,6 +1,6 @@
 # oci8.rb -- OCI8
 #
-# Copyright (C) 2002-2012 KUBO Takehiro <kubo at jiubao.org>
+# Copyright (C) 2002-2013 Kubo Takehiro <kubo at jiubao.org>
 #
 # Original Copyright is:
 #   Oracle module for Ruby
@@ -123,48 +123,38 @@
     stmt_cache_size = OCI8.properties[:statement_cache_size]
     stmt_cache_size = nil if stmt_cache_size == 0
 
-    if mode.nil? and cred.nil?
-      # logon by the OCI function OCILogon2().
-      logon2_mode = 0
-      if dbname.is_a? OCI8::ConnectionPool
-        @pool = dbname # to prevent GC from freeing the connection pool.
-        dbname = dbname.send(:pool_name)
-        logon2_mode |= 0x0200 # OCI_LOGON2_CPOOL
-      end
-      if stmt_cache_size
-        # enable statement caching
-        logon2_mode |= 0x0004 # OCI_LOGON2_STMTCACHE
-      end
+    attach_mode = 0
+    if dbname.is_a? OCI8::ConnectionPool
+      @pool = dbname # to prevent GC from freeing the connection pool.
+      dbname = dbname.send(:pool_name)
+      attach_mode |= 0x0200 # OCI_CPOOL and OCI_LOGON2_CPOOL
+    end
+    if stmt_cache_size
+      # enable statement caching
+      attach_mode |= 0x0004 # OCI_STMT_CACHE and OCI_LOGON2_STMTCACHE
+    end
 
-      logon2(username, password, dbname, logon2_mode)
-
-      if stmt_cache_size
-        # set statement cache size
-        attr_set_ub4(176, stmt_cache_size) # 176: OCI_ATTR_STMTCACHESIZE
-      end
-    else
+    if true
       # logon by the OCI function OCISessionBegin().
-      attach_mode = 0
-      if dbname.is_a? OCI8::ConnectionPool
-        @pool = dbname # to prevent GC from freeing the connection pool.
-        dbname = dbname.send(:pool_name)
-        attach_mode |= 0x0200 # OCI_CPOOL
-      end
-      if stmt_cache_size
-        # enable statement caching
-        attach_mode |= 0x0004 # OCI_STMT_CACHE
-      end
-
       allocate_handles()
       @session_handle.send(:attr_set_string, OCI_ATTR_USERNAME, username) if username
       @session_handle.send(:attr_set_string, OCI_ATTR_PASSWORD, password) if password
+      if @@oracle_client_version >= ORAVER_11_1
+        # 'rubyoci8' is displayed in V$SESSION_CONNECT_INFO.CLIENT_DRIVER
+        # if both the client and the server are Oracle 11g or upper.
+        # 424: OCI_ATTR_DRIVER_NAME
+        @session_handle.send(:attr_set_string, 424, 'rubyoci8')
+      end
       server_attach(dbname, attach_mode)
       session_begin(cred ? cred : OCI_CRED_RDBMS, mode ? mode : OCI_DEFAULT)
+    else
+      # logon by the OCI function OCILogon2().
+      logon2(username, password, dbname, attach_mode)
+    end
 
-      if stmt_cache_size
-        # set statement cache size
-        attr_set_ub4(176, stmt_cache_size) # 176: OCI_ATTR_STMTCACHESIZE
-      end
+    if stmt_cache_size
+      # set statement cache size
+      attr_set_ub4(176, stmt_cache_size) # 176: OCI_ATTR_STMTCACHESIZE
     end
 
     @prefetch_rows = nil

Modified: trunk/ruby-oci8/test/test_oci8.rb
===================================================================
--- trunk/ruby-oci8/test/test_oci8.rb	2013-03-03 06:09:22 UTC (rev 560)
+++ trunk/ruby-oci8/test/test_oci8.rb	2013-03-03 11:48:59 UTC (rev 561)
@@ -478,4 +478,12 @@
     # OCI_ATTR_MEMPOOL_SIZE
     assert_equal(0, OCI8.send(:class_variable_get, :@@process_handle).send(:attr_get_ub4, 88))
   end
+
+  def test_client_driver_name
+    if OCI8.oracle_client_version >= OCI8::ORAVER_11_1 and @conn.oracle_server_version >= OCI8::ORAVER_11_1
+      sid = @conn.select_one("select userenv('sid') from dual")[0].to_i
+      driver_name = @conn.select_one('select client_driver from v$session_connect_info where sid = :1', sid)[0]
+      assert_equal('rubyoci8', driver_name)
+    end
+  end
 end # TestOCI8



More information about the ruby-oci8-commit mailing list