From eaff1c6586d88daaec224c41b21ea1deb658dc5f Mon Sep 17 00:00:00 2001 From: Gaspard Bucher Date: Fri, 13 Feb 2009 23:20:06 +0100 Subject: [PATCH] Added a configuration option to set the timezone of the mysql connection. --- .../connection_adapters/mysql_adapter.rb | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 9300df2..37f9cbe 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -152,6 +152,7 @@ module ActiveRecord # * :password - Defaults to nothing. # * :database - The name of the database. No default, must be provided. # * :encoding - (Optional) Sets the client encoding by executing "SET NAMES " after connection. + # * :timezone - (Optional) Sets the client timezone by executing "SET TIME_ZONE " after connection. # * :reconnect - Defaults to false (See MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html). # * :sslca - Necessary to use MySQL with an SSL connection. # * :sslkey - Necessary to use MySQL with an SSL connection. @@ -584,6 +585,9 @@ module ActiveRecord def configure_connection encoding = @config[:encoding] execute("SET NAMES '#{encoding}'") if encoding + + timezone = @config[:timezone] + execute("SET TIME_ZONE = '#{timezone}'") if timezone # By default, MySQL 'where id is null' selects the last inserted id. # Turn this off. http://dev.rubyonrails.org/ticket/6778 -- 1.6.0