From ee2397036fc8d4a9498617349fb391389d8bb933 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 25 Aug 2006 03:56:21 +0000 Subject: SQLServer: work around bug where some unambiguous date formats are not correctly identified if the session language is set to german. Closes #5894. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4816 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/CHANGELOG | 2 ++ .../connection_adapters/sqlserver_adapter.rb | 3 ++- activerecord/test/adapter_test_sqlserver.rb | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 622499a91a..d326057d33 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* SQLServer: work around bug where some unambiguous date formats are not correctly identified if the session language is set to german. #5894 [Tom Ward, kruth@bfpi] + * SQLServer: fix eager association test. #5901 [Tom Ward] * Clashing type columns due to a sloppy join shouldn't wreck single-table inheritance. #5838 [Kevin Clark] diff --git a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb index a19da5a545..ff77c382d2 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb @@ -356,7 +356,8 @@ module ActiveRecord case value when TrueClass then '1' when FalseClass then '0' - when Time, DateTime then "'#{value.strftime("%Y-%m-%d %H:%M:%S")}'" + when Time, DateTime then "'#{value.strftime("%Y%m%d %H:%M:%S")}'" + when Date then "'#{value.strftime("%Y%m%d")}'" else super end end diff --git a/activerecord/test/adapter_test_sqlserver.rb b/activerecord/test/adapter_test_sqlserver.rb index 11f244e9f7..bf74671209 100644 --- a/activerecord/test/adapter_test_sqlserver.rb +++ b/activerecord/test/adapter_test_sqlserver.rb @@ -5,11 +5,25 @@ require 'fixtures/task' class SqlServerAdapterTest < Test::Unit::TestCase fixtures :posts, :tasks - + def setup @connection = ActiveRecord::Base.connection end - + + def teardown + @connection.execute("SET LANGUAGE us_english") + end + + # SQL Server 2000 has a bug where some unambiguous date formats are not + # correctly identified if the session language is set to german + def test_date_insertion_when_language_is_german + @connection.execute("SET LANGUAGE deutsch") + + assert_nothing_raised do + Task.create(:starting => Time.utc(2000, 1, 31, 5, 42, 0), :ending => Date.new(2006, 12, 31)) + end + end + def test_execute_without_block_closes_statement assert_all_statements_used_are_closed do @connection.execute("SELECT 1") -- cgit v1.2.3