[ruby-oci8-commit] [550] trunk/ruby-oci8: Add OCI8.properties[:events_mode] to support Fast Application Notification (FAN).

nobody at rubyforge.org nobody at rubyforge.org
Thu Jan 3 08:08:23 UTC 2013


Revision: 550
Author:   kubo
Date:     2013-01-03 08:08:21 +0000 (Thu, 03 Jan 2013)
Log Message:
-----------
Add OCI8.properties[:events_mode] to support Fast Application Notification (FAN).

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/ext/oci8/oci8.c
    trunk/ruby-oci8/lib/oci8/properties.rb

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2013-01-03 02:13:25 UTC (rev 549)
+++ trunk/ruby-oci8/ChangeLog	2013-01-03 08:08:21 UTC (rev 550)
@@ -1,4 +1,8 @@
 2013-01-03  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/oci8.c, lib/oci8/properties.rb: add OCI8.properties[:events_mode]
+	    to support Fast Application Notification (FAN).
+
+2013-01-03  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/extconf.rb, lib/oci8.rb.in: add languange mode to the extension
 	    library name when ths ruby engine is rubinius and explicitly claim that
 	    jruby is not supported when it is jruby.

Modified: trunk/ruby-oci8/ext/oci8/oci8.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.c	2013-01-03 02:13:25 UTC (rev 549)
+++ trunk/ruby-oci8/ext/oci8/oci8.c	2013-01-03 08:08:21 UTC (rev 550)
@@ -2,7 +2,7 @@
 /*
  * oci8.c - part of ruby-oci8
  *
- * Copyright (C) 2002-2011 KUBO Takehiro <kubo at jiubao.org>
+ * Copyright (C) 2002-2013 KUBO Takehiro <kubo at jiubao.org>
  *
  */
 #include "oci8.h"
@@ -171,25 +171,56 @@
     return oracle_client_vernum;
 }
 
-static VALUE oci8_s_set_property(VALUE klass, VALUE name, VALUE val)
+/*
+ * call-seq:
+ *   OCI8.__get_prop(key)
+ *
+ * @param [Fixnum] key    1 or 2
+ *
+ * @private
+ */
+static VALUE oci8_s_get_prop(VALUE klass, VALUE key)
 {
-    const char *name_str;
+    switch (NUM2INT(key)) {
+    case 1:
+        return oci8_float_conversion_type_is_ruby ? Qtrue : Qfalse;
+    case 2:
+        return UINT2NUM(oci8_env_mode);
+    default:
+        rb_raise(rb_eArgError, "Unknown prop %d", NUM2INT(key));
+    }
+}
 
-    Check_Type(name, T_SYMBOL);
-    name_str = rb_id2name(SYM2ID(name));
-    if (strcmp(name_str, "float_conversion_type") == 0) {
-        const char *val_str;
-        Check_Type(val, T_SYMBOL);
-        val_str = rb_id2name(SYM2ID(val));
-        if (strcmp(val_str, "ruby") == 0) {
-            oci8_float_conversion_type_is_ruby = 1;
-        } else if (strcmp(val_str, "oracle") == 0) {
-            oci8_float_conversion_type_is_ruby = 0;
-        } else {
-            rb_raise(rb_eArgError, "float_conversion_type's value should be either :ruby or :oracle.");
+
+/*
+ * call-seq:
+ *   OCI8.__set_prop(key, value)
+ *
+ * @param [Fixnum] key    1 or 2
+ * @param [Object] value  depends on +key+.
+ *
+ * @private
+ */
+static VALUE oci8_s_set_prop(VALUE klass, VALUE key, VALUE val)
+{
+    switch (NUM2INT(key)) {
+    case 1:
+        oci8_float_conversion_type_is_ruby = RTEST(val) ? 1 : 0;
+        break;
+    case 2:
+        /*
+         * Changes the OCI environment mode which will be passed to the second
+         * argument of the OCI function OCIEnvCreate.
+         */
+        if (oci8_global_envhp != NULL) {
+            rb_raise(rb_eRuntimeError, "The OCI Environment has been alreadly initialized. It cannot be changed after even one OCI function is called.");
         }
+        oci8_env_mode = NUM2UINT(val);
+        break;
+    default:
+        rb_raise(rb_eArgError, "Unknown prop %d", NUM2INT(key));
     }
-    return Qnil;
+    return klass;
 }
 
 /*
@@ -1121,7 +1152,8 @@
 
     rb_define_const(cOCI8, "VERSION", rb_obj_freeze(rb_usascii_str_new_cstr(OCI8LIB_VERSION)));
     rb_define_singleton_method_nodoc(cOCI8, "oracle_client_vernum", oci8_s_oracle_client_vernum, 0);
-    rb_define_singleton_method_nodoc(cOCI8, "__set_property", oci8_s_set_property, 2);
+    rb_define_singleton_method(cOCI8, "__get_prop", oci8_s_get_prop, 1);
+    rb_define_singleton_method(cOCI8, "__set_prop", oci8_s_set_prop, 2);
     rb_define_singleton_method(cOCI8, "error_message", oci8_s_error_message, 1);
     rb_define_private_method(cOCI8, "parse_connect_string", oci8_parse_connect_string, 1);
     rb_define_private_method(cOCI8, "logon2", oci8_logon2, 4);

Modified: trunk/ruby-oci8/lib/oci8/properties.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/properties.rb	2013-01-03 02:13:25 UTC (rev 549)
+++ trunk/ruby-oci8/lib/oci8/properties.rb	2013-01-03 08:08:21 UTC (rev 550)
@@ -1,6 +1,6 @@
 # properties.rb -- implements OCI8.properties
 #
-# Copyright (C) 2010-2012 KUBO Takehiro <kubo at jiubao.org>
+# Copyright (C) 2010-2013 KUBO Takehiro <kubo at jiubao.org>
 
 #
 class OCI8
@@ -8,8 +8,9 @@
   @@properties = {
     :length_semantics => :byte,
     :bind_string_as_nchar => false,
-    :float_conversion_type => :ruby,
+    :float_conversion_type => OCI8.__get_prop(1) ? :ruby : :oracle,
     :statement_cache_size => 0,
+    :events_mode => ((OCI8.__get_prop(2) & 4) != 0) # 4 <- OCI_EVENTS in oci.h
   }
 
   if OCI8.oracle_client_version < OCI8::ORAVER_9_2
@@ -31,23 +32,31 @@
     when :bind_string_as_nchar
       val = val ? true : false
     when :float_conversion_type
-      # handled by native code in oci8lib_xx.so.
-      OCI8.__set_property(name, val)
+      case val
+      when :ruby
+        OCI8.__set_prop(1, true)
+      when :oracle
+        OCI8.__set_prop(1, false)
+      else
+        raise ArgumentError, "float_conversion_type's value should be either :ruby or :oracle."
+      end
     when :statement_cache_size
       if OCI8.oracle_client_version < OCI8::ORAVER_9_2
         raise RuntimeError, ":statement_cache_size is disabled on Oracle 9iR1 client."
       end
       val = val.to_i
       raise ArgumentError, "The property value for :statement_cache_size must not be negative." if val < 0
+    when :events_mode
+      val = val ? true : false
+      if val
+        OCI8.__set_prop(2, OCI8.__get_prop(2) | 4) # set OCI_EVENTS
+      else
+        OCI8.__set_prop(2, OCI8.__get_prop(2) & ~4) # unset OCI_EVENTS
+      end
     end
     super(name, val)
   end
 
-  # call-seq:
-  #   OCI8.properties -> a customized Hash
-  #
-  # (new in 2.0.5)
-  #
   # Returns a Hash which ruby-oci8 global settings.
   # The hash's setter and getter methods are customized to check
   # property names and values.
@@ -63,19 +72,20 @@
   # 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
   #     Oracle 9i.
+  #     
+  #     *Since:* 2.1.0
   #
   # [:bind_string_as_nchar]
+  #     
   #     +true+ when string bind variables are bound as NCHAR,
   #     otherwise +false+. The default value is +false+.
   #
   # [:float_conversion_type]
-  #     (new in 2.1.0)
   #     
   #     +:ruby+ when Oracle decimal numbers are converted to ruby Float values
   #     same as Float#to_s does. (default)
@@ -85,15 +95,36 @@
   #     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
+  #     
+  #     *Since:* 2.1.0
   #
   # [:statement_cache_size]
-  #     (new in 2.1.1)
   #     
   #     The statement cache size per each session. The default size is 0, which
   #     means no statement cache, since 2.1.2. It was 20 in 2.1.1.
   #     This feature is available on Oracle 9iR2 or later.
   #     See: http://docs.oracle.com/cd/E11882_01/appdev.112/e10646/oci09adv.htm#i471377
+  #     
+  #     *Since:* 2.1.1
   #
+  # [:events_mode]
+  #     
+  #     +true+ when Fast Application Notification (FAN) Support is enabled.
+  #     +false+ when it is disabled. The default value is +false+.
+  #     This corresponds to {http://php.net/manual/en/oci8.configuration.php#ini.oci8.events +oci8.events+ in PHP}.
+  #     
+  #     This parameter can be changed only when no OCI methods are called.
+  #     
+  #       require 'oci8'
+  #       OCI8.properties[:events_mode] = true # works fine.
+  #       ... call some OCI methods ...
+  #       OCI8.properties[:events_mode] = true # raises a runtime error.
+  #     
+  #     *Since:* 2.1.4
+  #
+  # @return [a customized Hash]
+  # @since 2.0.5
+  #
   def self.properties
     @@properties
   end



More information about the ruby-oci8-commit mailing list