[ruby-oci8-commit] [562] trunk/ruby-oci8: refactoring.

nobody at rubyforge.org nobody at rubyforge.org
Tue Mar 5 14:16:07 UTC 2013


Revision: 562
Author:   kubo
Date:     2013-03-05 14:16:06 +0000 (Tue, 05 Mar 2013)
Log Message:
-----------
refactoring.

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

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2013-03-03 11:48:59 UTC (rev 561)
+++ trunk/ruby-oci8/ChangeLog	2013-03-05 14:16:06 UTC (rev 562)
@@ -1,3 +1,7 @@
+2013-03-05  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/oci8.c, lib/oci8/oci8.rb, lib/oci8/oracle_version.rb:
+	    refactoring.
+
 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

Modified: trunk/ruby-oci8/ext/oci8/oci8.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.c	2013-03-03 11:48:59 UTC (rev 561)
+++ trunk/ruby-oci8/ext/oci8/oci8.c	2013-03-05 14:16:06 UTC (rev 562)
@@ -160,8 +160,6 @@
 };
 
 static VALUE oracle_client_vernum; /* Oracle client version number */
-static ID id_at_prefetch_rows;
-static ID id_set_prefetch_rows;
 
 static VALUE oci8_s_oracle_client_vernum(VALUE klass)
 {
@@ -775,23 +773,6 @@
 
 /*
  * call-seq:
- *   prefetch_rows = number
- *
- * Sets the prefetch rows size. The default value is one.
- * When a select statement is executed, the OCI library allocate
- * prefetch buffer to reduce the number of network round trips by
- * retrieving specified number of rows in one round trip.
- *
- * Note: Active record adaptors set 100 by default.
- */
-static VALUE oci8_set_prefetch_rows(VALUE self, VALUE val)
-{
-    rb_ivar_set(self, id_at_prefetch_rows, val);
-    return val;
-}
-
-/*
- * call-seq:
  *   oracle_server_vernum -> an integer
  *
  * Returns a numerical format of the Oracle server version.
@@ -1147,9 +1128,6 @@
         oracle_client_vernum = INT2FIX(ORAVERNUM(major, minor, update, patch, port_update));
     }
 
-    id_at_prefetch_rows = rb_intern("@prefetch_rows");
-    id_set_prefetch_rows = rb_intern("prefetch_rows=");
-
     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(cOCI8, "__get_prop", oci8_s_get_prop, 1);
@@ -1170,7 +1148,6 @@
     rb_define_method(cOCI8, "long_read_len", oci8_long_read_len, 0);
     rb_define_method(cOCI8, "long_read_len=", oci8_set_long_read_len, 1);
     rb_define_method(cOCI8, "break", oci8_break, 0);
-    rb_define_method(cOCI8, "prefetch_rows=", oci8_set_prefetch_rows, 1);
     rb_define_private_method(cOCI8, "oracle_server_vernum", oci8_oracle_server_vernum, 0);
     rb_define_method(cOCI8, "ping", oci8_ping, 0);
     rb_define_method(cOCI8, "client_identifier=", oci8_set_client_identifier, 1);

Modified: trunk/ruby-oci8/lib/oci8/oci8.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/oci8.rb	2013-03-03 11:48:59 UTC (rev 561)
+++ trunk/ruby-oci8/lib/oci8/oci8.rb	2013-03-05 14:16:06 UTC (rev 562)
@@ -329,6 +329,16 @@
     end
   end
 
+  # Sets the prefetch rows size. The default value is one.
+  # When a select statement is executed, the OCI library allocate
+  # prefetch buffer to reduce the number of network round trips by
+  # retrieving specified number of rows in one round trip.
+  #
+  # Note: Active record adaptors set 100 by default.
+  def prefetch_rows=(num)
+    @prefetch_rows = num
+  end
+
   # @private
   def inspect
     "#<OCI8:#{username}>"

Modified: trunk/ruby-oci8/lib/oci8/oracle_version.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/oracle_version.rb	2013-03-03 11:48:59 UTC (rev 561)
+++ trunk/ruby-oci8/lib/oci8/oracle_version.rb	2013-03-05 14:16:06 UTC (rev 562)
@@ -80,6 +80,7 @@
       @update = update || 0
       @patch = patch || 0
       @port_update = port_update || 0
+      @vernum = (@major << 24) | (@minor << 20) | (@update << 12) | (@patch << 8) | @port_update
     end
 
     # Compares +self+ and +other+.
@@ -89,15 +90,7 @@
     #
     # @return [-1, 0, +1]
     def <=>(other)
-      cmp = @major <=> other.major
-      return cmp if cmp != 0
-      cmp = @minor <=> other.minor
-      return cmp if cmp != 0
-      cmp = @update <=> other.update
-      return cmp if cmp != 0
-      cmp = @patch <=> other.patch
-      return cmp if cmp != 0
-      @port_update <=> other.port_update
+      @vernum <=> other.to_i
     end
 
     # Returns an integer number contains 5-digit Oracle version.
@@ -113,7 +106,7 @@
     #
     # @return [Integer]
     def to_i
-      (@major << 24) | (@minor << 20) | (@update << 12) | (@patch << 8) | @port_update
+      @vernum
     end
 
     # Returns a dotted version string of the Oracle version.
@@ -139,7 +132,7 @@
     #
     # @return [Integer]
     def hash
-      to_i
+      @vernum
     end
 
     # @private



More information about the ruby-oci8-commit mailing list