Skip to content

Commit 32968ae

Browse files
committed
Ensure that execute_procedure returns proper time zones. Fixes #449
1 parent bcf12d7 commit 32968ae

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Conform to new data_sources interfaces. See: https://git.io/va4Fp
66
* The `primary_key` method falls back to Identity columns. Not the other way around. Fixes #454. Thanks @marceloeloelo
7+
* Ensure that `execute_procedure` returns proper time zones. Fixes #449
78

89
#### Changed
910

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def execute_procedure(proc_name, *variables)
117117
case @connection_options[:mode]
118118
when :dblib
119119
result = @connection.execute(sql)
120-
result.each(as: :hash, cache_rows: true) do |row|
120+
options = { as: :hash, cache_rows: true, timezone: ActiveRecord::Base.default_timezone || :utc }
121+
result.each(options) do |row|
121122
r = row.with_indifferent_access
122123
yield(r) if block_given?
123124
end

test/cases/execute_procedure_test_sqlserver.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,10 @@ class ExecuteProcedureTestSQLServer < ActiveRecord::TestCase
3535
assert_equal 'VIEW', table_info['TABLE_TYPE'], "Table Info: #{table_info.inspect}"
3636
end
3737

38+
it 'uses the proper timezone' do
39+
date_proc = connection.execute_procedure('my_getutcdate').first['utcdate']
40+
date_base = connection.select_value('select GETUTCDATE()')
41+
assert_equal date_base, date_proc
42+
end
43+
3844
end

test/schema/sqlserver_specific_schema.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@
119119
end
120120
execute "sp_bindefault 'sst_getdateobject', 'sst_defaultobjects.date'"
121121

122+
execute "DROP PROCEDURE my_getutcdate" rescue nil
123+
execute <<-SQL
124+
CREATE PROCEDURE my_getutcdate AS
125+
SELECT GETUTCDATE() utcdate
126+
SQL
127+
122128
# Constraints
123129

124130
create_table(:sst_has_fks, force: true) { |t| t.column(:fk_id, :integer, null: false) }

0 commit comments

Comments
 (0)