[ruby-oci8-commit] [360] trunk/ruby-oci8: * ext/oci8/oci8.c: Add constants missing in Oracle client prior to 10g.

nobody at rubyforge.org nobody at rubyforge.org
Sun Oct 4 09:55:02 EDT 2009


Revision: 360
Author:   kubo
Date:     2009-10-04 09:55:01 -0400 (Sun, 04 Oct 2009)

Log Message:
-----------
* ext/oci8/oci8.c: Add constants missing in Oracle client prior to 10g.
* ext/oci8/oraconf.rb:
    1. Fix for ruby 1.8.5 with Oracle 8.x which needs some object
       files to link with.
    2. Revise the error message under the sudo environemnt.
    3. Print not only error message but also the error backtrace when
       oraconf.rb fails.
* lib/oci8/object.rb: Fix to accept nil attribute in object type's
    constructors. This works only for simple data types such as number,
    string. But it doesn't for complex types such as object types.
    (requested by Remi Gagnon)
* spec/object_type_spec.rb: Add a test for object type's constructors.

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

Added Paths:
-----------
    trunk/ruby-oci8/spec/object_type_spec.rb

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2009-09-22 10:46:31 UTC (rev 359)
+++ trunk/ruby-oci8/ChangeLog	2009-10-04 13:55:01 UTC (rev 360)
@@ -1,3 +1,17 @@
+2009-10-04  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/oci8.c: Add constants missing in Oracle client prior to 10g.
+	* ext/oci8/oraconf.rb:
+	    1. Fix for ruby 1.8.5 with Oracle 8.x which needs some object
+	       files to link with.
+	    2. Revise the error message under the sudo environemnt.
+	    3. Print not only error message but also the error backtrace when
+	       oraconf.rb fails.
+	* lib/oci8/object.rb: Fix to accept nil attribute in object type's
+	    constructors. This works only for simple data types such as number,
+	    string. But it doesn't for complex types such as object types.
+	    (requested by Remi Gagnon)
+	* spec/object_type_spec.rb: Add a test for object type's constructors.
+
 2009-09-22  KUBO Takehiro  <kubo at jiubao.org>
 	* lib/oci8/.document, lib/oci8/datetime.rb: 1. Add
 	    OCI8::BindType.default_timezone and OCI8::BindType.default_timezone=.

Modified: trunk/ruby-oci8/ext/oci8/oci8.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.c	2009-09-22 10:46:31 UTC (rev 359)
+++ trunk/ruby-oci8/ext/oci8/oci8.c	2009-10-04 13:55:01 UTC (rev 360)
@@ -20,6 +20,15 @@
 #ifndef OCI_ATTR_CLIENT_IDENTIFIER
 #define OCI_ATTR_CLIENT_IDENTIFIER 278
 #endif
+#ifndef OCI_ATTR_MODULE
+#define OCI_ATTR_MODULE 366
+#endif
+#ifndef OCI_ATTR_ACTION
+#define OCI_ATTR_ACTION 367
+#endif
+#ifndef OCI_ATTR_CLIENT_INFO
+#define OCI_ATTR_CLIENT_INFO 368
+#endif
 
 static VALUE cOCI8;
 

Modified: trunk/ruby-oci8/ext/oci8/oraconf.rb
===================================================================
--- trunk/ruby-oci8/ext/oci8/oraconf.rb	2009-09-22 10:46:31 UTC (rev 359)
+++ trunk/ruby-oci8/ext/oci8/oraconf.rb	2009-10-04 13:55:01 UTC (rev 360)
@@ -353,8 +353,10 @@
       end
       print <<EOS
 ---------------------------------------------------
-error messages:
-#{$!.to_s}
+Error Message:
+  #{$!.to_s.gsub(/\n/, "\n  ")}
+Backtrace:
+  #{$!.backtrace.join("\n  ")}
 ---------------------------------------------------
 See:
  * http://ruby-oci8.rubyforge.org/#{lang}/HowToInstall.html
@@ -616,6 +618,7 @@
 EOS
     end
     puts "ok"
+    $stdout.flush
   end # check_ruby_header
 
   def try_link_oci
@@ -873,7 +876,7 @@
         if /\w*make\b/ =~ sudo_command
           msg += <<EOS
 
-'sudo' may unset environment variables for security reasons.
+The 'sudo' command unset some environment variables for security reasons.
 Use it only when running 'make install' as follows
      make
      sudo make install
@@ -882,9 +885,11 @@
         if /\w+\/gem\b/ =~ sudo_command
           msg += <<EOS
 
-'sudo' may unset environment variables for security reasons.
+The 'sudo' command unset some environment variables for security reasons.
 Pass required varialbes as follows
-     sudo VAR1=val1 VAR2=val2 #{sudo_command}
+     sudo env #{OraConf.ld_envs[0]}=$#{OraConf.ld_envs[0]} #{sudo_command}
+  or 
+     sudo env ORACLE_HOME=$ORACLE_HOME #{sudo_command}
 EOS
         end
         raise msg
@@ -977,10 +982,10 @@
 
         # monkey patching!
         Object.module_eval do
-          alias :orig_link_command :link_command
-          def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH)
-            opt = "" if opt == $libs
-            orig_link_command(ldflags, opt, libpath)
+          alias :link_command_pre_oci8 :link_command
+          def link_command(*args)
+            args[1] = "" if args[1] == $libs
+            link_command_pre_oci8(*args)
           end
         end
 

Modified: trunk/ruby-oci8/lib/oci8/object.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/object.rb	2009-09-22 10:46:31 UTC (rev 359)
+++ trunk/ruby-oci8/lib/oci8/object.rb	2009-10-04 13:55:01 UTC (rev 360)
@@ -84,7 +84,7 @@
           csr.bind_param(key, nil, :named_type_internal, tdo)
           csr[key].attributes = val
         else
-          csr.bind_param(key, val)
+          csr.bind_param(key, val ? val : '')
         end
       end
       csr.exec

Added: trunk/ruby-oci8/spec/object_type_spec.rb
===================================================================
--- trunk/ruby-oci8/spec/object_type_spec.rb	                        (rev 0)
+++ trunk/ruby-oci8/spec/object_type_spec.rb	2009-10-04 13:55:01 UTC (rev 360)
@@ -0,0 +1,56 @@
+require File.join(File.dirname(__FILE__), 'spec_helper.rb')
+
+describe OCI8::Object::Base, "when creating an instance" do
+  before :all do
+    @conn = get_oracle_connection()
+    @conn.exec <<EOS
+CREATE OR REPLACE TYPE rboci8_test_object AS OBJECT (
+   char_attr char(5),
+   varchar2_attr varchar2(5),
+   raw_attr raw(5),
+   number_attr number,
+   integer_attr integer,
+   float_attr double precision,
+   date_attr date
+);
+EOS
+  end
+
+  after :all do
+    @conn.exec "DROP TYPE rboci8_test_object"
+    @conn.logoff
+  end
+
+  class Rboci8TestObject < OCI8::Object::Base
+  end
+
+  def make_attr(seed)
+    [format("%5d", seed * 10),       # char_attr
+     format("%d", seed * 11),     # varchar2_attr
+     format("%010x", seed * 12),       # raw_attr
+     OraNumber.new(seed * 13+ 0.5), # number_attr
+     (seed * 999).to_i,             # integer_attr
+     (seed * 1023).to_f + 0.25,     # float_attr
+     Time.at(946702800 + seed * 10000).to_datetime, # date_attr
+    ]
+  end
+
+  def check_attr(obj, attr)
+    obj.char_attr    .should eql attr[0]
+    obj.varchar2_attr.should eql attr[1]
+    obj.raw_attr     .should eql attr[2] ? [attr[2]].pack('H*') : nil
+    obj.number_attr  .should eql attr[3]
+    obj.integer_attr .should eql attr[4]
+    obj.float_attr   .should eql attr[5]
+    obj.date_attr    .should eql attr[6]
+  end
+
+  it "should accept nil attributes" do
+    0.upto 6 do |idx|
+      attr = make_attr(idx)
+      attr[idx] = nil
+      obj = Rboci8TestObject.new(@conn, *attr)
+      check_attr(obj, attr)
+    end
+  end
+end




More information about the ruby-oci8-commit mailing list