[ruby-oci8-commit] [270] branches/ruby-oci8-1.0: * lib/oci8.rb.in: (1) add #to_json to OraDate too.

nobody at rubyforge.org nobody at rubyforge.org
Sat Jul 12 09:01:27 EDT 2008


Revision: 270
Author:   kubo
Date:     2008-07-12 09:01:27 -0400 (Sat, 12 Jul 2008)

Log Message:
-----------
* lib/oci8.rb.in: (1) add #to_json to OraDate too.
    (2) fix a bug when using Oracle 8i and dbd. OCI_ATTR_FSPRECISION
    is for TIMESTAMP data type which is new in Oracle 9i.

Modified Paths:
--------------
    branches/ruby-oci8-1.0/ChangeLog
    branches/ruby-oci8-1.0/lib/oci8.rb.in

Modified: branches/ruby-oci8-1.0/ChangeLog
===================================================================
--- branches/ruby-oci8-1.0/ChangeLog	2008-07-07 16:02:45 UTC (rev 269)
+++ branches/ruby-oci8-1.0/ChangeLog	2008-07-12 13:01:27 UTC (rev 270)
@@ -1,3 +1,8 @@
+2008-07-12  KUBO Takehiro  <kubo at jiubao.org>
+	* lib/oci8.rb.in: (1) add #to_json to OraDate too.
+	    (2) fix a bug when using Oracle 8i and dbd. OCI_ATTR_FSPRECISION
+	    is for TIMESTAMP data type which is new in Oracle 9i.
+
 2008-07-07  KUBO Takehiro  <kubo at jiubao.org>
 	* lib/oci8.rb.in: fix the problem that OraNumber#to_json returns
 	    "{}" when using Rails. (This issue is reported by Alex Moore)

Modified: branches/ruby-oci8-1.0/lib/oci8.rb.in
===================================================================
--- branches/ruby-oci8-1.0/lib/oci8.rb.in	2008-07-07 16:02:45 UTC (rev 269)
+++ branches/ruby-oci8-1.0/lib/oci8.rb.in	2008-07-12 13:01:27 UTC (rev 270)
@@ -1293,6 +1293,10 @@
       out.scalar(taguri, self.to_s, :plain)
     end
   end
+
+  def to_json(options=nil) # :nodoc:
+    to_datetime.to_json(options)
+  end
 end
 
 class OraNumber
@@ -1568,6 +1572,12 @@
       attr_reader :scale
 
       # interval
+      if defined? OCI_ATTR_FSPRECISION and defined? OCI_ATTR_LFPRECISION
+        # Oracle 8i or upper has OCI_ATTR_FSPRECISION and OCI_ATTR_LFPRECISION
+        @@is_fsprecision_available = true
+      else
+        @@is_fsprecision_available = false
+      end
       attr_reader :fsprecision
       attr_reader :lfprecision
 
@@ -1592,8 +1602,22 @@
                         when 5; :lit_null
                         else raise "unknown charset_form #{param.attrGet(OCI_ATTR_CHARSET_FORM)}"
                         end
-        @fsprecision = param.attrGet(OCI_ATTR_FSPRECISION)
-        @lfprecision = param.attrGet(OCI_ATTR_LFPRECISION)
+
+        @fsprecision = nil
+        @lfprecision = nil
+        if @@is_fsprecision_available
+          begin
+            @fsprecision = param.attrGet(OCI_ATTR_FSPRECISION)
+            @lfprecision = param.attrGet(OCI_ATTR_LFPRECISION)
+          rescue OCIError
+            raise if $!.code != 24316 # ORA-24316: illegal handle type
+            # Oracle 8i could not use OCI_ATTR_FSPRECISION and
+            # OCI_ATTR_LFPRECISION even though it defines these
+            # constants in oci.h.
+            @@is_fsprecision_available = false
+          end
+        end
+
         @type_string = __type_string(param)
       end
 




More information about the ruby-oci8-commit mailing list