[ruby-oci8-commit] [476] trunk/ruby-oci8: add OCI8.properties[:time_zone] and use ENV['TZ'] or the time_zone propery to set Oracle session time zone.
nobody at rubyforge.org
nobody at rubyforge.org
Mon Dec 5 08:23:22 EST 2011
Revision: 476
Author: kubo
Date: 2011-12-05 08:23:21 -0500 (Mon, 05 Dec 2011)
Log Message:
-----------
add OCI8.properties[:time_zone] and use ENV['TZ'] or the time_zone propery to set Oracle session time zone.
Modified Paths:
--------------
trunk/ruby-oci8/ChangeLog
trunk/ruby-oci8/lib/oci8/oci8.rb
trunk/ruby-oci8/lib/oci8/properties.rb
trunk/ruby-oci8/test/test_datetime.rb
Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog 2011-12-05 12:08:51 UTC (rev 475)
+++ trunk/ruby-oci8/ChangeLog 2011-12-05 13:23:21 UTC (rev 476)
@@ -1,4 +1,9 @@
2011-12-05 KUBO Takehiro <kubo at jiubao.org>
+ * lib/oci8/oci8.rb, lib/oci8/properties.rb, test/test_datetime.rb.
+ add OCI8.properties[:time_zone] and use ENV['TZ'] or the time_zone
+ propery to set Oracle session time zone.
+
+2011-12-05 KUBO Takehiro <kubo at jiubao.org>
* lib/oci8/encoding-init.rb, lib/oci8/oci8.rb: add OCI8.client_charset_name.
* test/config.rb: use OCI8.client_charset_name instead of OCI8.encoding.
Ruby-oci8 compiled for ruby 1.8 doesn't has the latter.
Modified: trunk/ruby-oci8/lib/oci8/oci8.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/oci8.rb 2011-12-05 12:08:51 UTC (rev 475)
+++ trunk/ruby-oci8/lib/oci8/oci8.rb 2011-12-05 13:23:21 UTC (rev 476)
@@ -140,6 +140,9 @@
@prefetch_rows = nil
@username = nil
+
+ time_zone = OCI8.properties[:time_zone] || ENV['TZ']
+ exec("alter session set time_zone = '#{time_zone}'") if time_zone and time_zone.length > 0
end
# call-seq:
Modified: trunk/ruby-oci8/lib/oci8/properties.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/properties.rb 2011-12-05 12:08:51 UTC (rev 475)
+++ trunk/ruby-oci8/lib/oci8/properties.rb 2011-12-05 13:23:21 UTC (rev 476)
@@ -5,6 +5,7 @@
class OCI8
@@properties = {
+ :time_zone => nil,
:length_semantics => :byte,
:bind_string_as_nchar => false,
:float_conversion_type => :ruby,
@@ -18,6 +19,8 @@
def @@properties.[]=(name, val)
raise IndexError, "No such property name: #{name}" unless @@properties.has_key?(name)
case name
+ when :time_zone
+ raise TypeError, "invalid property type #{val.class}" unless val.nil? or val.is_a? String
when :length_semantic
if val != :byte and val != :char
raise ArgumentError, "Invalid property value #{val} for :length_semantics."
@@ -50,8 +53,17 @@
#
# Supported properties are listed below:
#
+ # [:time_zone]
+ # (new in 2.1.0)
+ #
+ # If your application runs in a time zone which adopt daylight saving time,
+ # you should set the environment variable TZ or this +time_zone+ property.
+ # Otherwise, Oracle session time zone is set with current constant
+ # offset from GMT.
+ #
# [: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
@@ -63,9 +75,14 @@
#
# [:float_conversion_type]
# (new in 2.1.0)
- # Specifies who converts decimal to float and vice versa.
- # It should be either +:ruby+ or +:oracle+. The default value
- # is +:ruby+.
+ #
+ # +:ruby+ when Oracle decimal numbers are converted to ruby Float values
+ # same as Float#to_s does. (default)
+ # +:oracle:+ when they are done by Oracle OCI functions.
+ #
+ # From ruby 1.9.2, a float value converted from Oracle number 15.7 by
+ # 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
#
def self.properties
Modified: trunk/ruby-oci8/test/test_datetime.rb
===================================================================
--- trunk/ruby-oci8/test/test_datetime.rb 2011-12-05 12:08:51 UTC (rev 475)
+++ trunk/ruby-oci8/test/test_datetime.rb 2011-12-05 13:23:21 UTC (rev 476)
@@ -579,4 +579,34 @@
end
end
end
+
+ def test_time_zone_property
+ orig_prop = OCI8.properties[:time_zone]
+ orig_env = ENV['TZ']
+ conn = nil
+ begin
+ assert_raise(TypeError) do
+ OCI8.properties[:time_zone] = 1
+ end
+
+ OCI8.properties[:time_zone] = 'America/New_York'
+ ENV['TZ'] = nil
+ conn = get_oci8_connection
+ assert_equal('America/New_York', conn.select_one('select sessiontimezone from dual')[0])
+ conn.logoff
+ conn = nil
+
+ OCI8.properties[:time_zone] = nil
+ ENV['TZ'] = 'Europe/Riga'
+ conn = get_oci8_connection
+ assert_equal('Europe/Riga', conn.select_one('select sessiontimezone from dual')[0])
+ conn.logoff
+ conn = nil
+
+ ensure
+ conn.logoff if conn
+ OCI8.properties[:time_zone] = orig_prop
+ ENV['TZ'] = orig_env
+ end
+ end
end # TestOCI8
More information about the ruby-oci8-commit
mailing list