Skip to content

Commit

Permalink
Merge pull request #16 from localytics/in-time-zone
Browse files Browse the repository at this point in the history
Cast Time/Timestamp to Rails application timezone.
  • Loading branch information
kddnewton authored Mar 7, 2017
2 parents ef91d09 + a6aa2d3 commit cc31c29
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 51 deletions.
8 changes: 7 additions & 1 deletion lib/active_record/connection_adapters/odbc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
require 'odbc_adapter/column_metadata'
require 'odbc_adapter/database_metadata'
require 'odbc_adapter/registry'
require 'odbc_adapter/type_caster'
require 'odbc_adapter/version'

module ActiveRecord
Expand Down Expand Up @@ -79,6 +78,7 @@ class ODBCAdapter < AbstractAdapter
attr_reader :database_metadata

def initialize(connection, logger, config, database_metadata)
configure_time_options(connection)
super(connection, logger, config)
@database_metadata = database_metadata
end
Expand Down Expand Up @@ -113,6 +113,7 @@ def reconnect!
else
ODBC::Database.new.drvconnect(@config[:driver])
end
configure_time_options(@connection)
super
end
alias reset! reconnect!
Expand Down Expand Up @@ -189,6 +190,11 @@ def alias_type(map, new_type, old_type)
map.lookup(old_type, *args)
end
end

# Ensure ODBC is mapping time-based fields to native ruby objects
def configure_time_options(connection)
connection.use_time = true
end
end
end
end
7 changes: 0 additions & 7 deletions lib/odbc_adapter/database_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ def exec_query(sql, name = 'SQL', binds = [], prepare: false) # rubocop:disable
values = stmt.to_a
stmt.drop

casters = TypeCaster.build_from(columns.values)
if casters.any?
values.each do |row|
casters.each { |caster| row[caster.idx] = caster.cast(row[caster.idx]) }
end
end

values = dbms_type_cast(columns.values, values)
column_names = columns.keys.map { |key| format_case(key) }
ActiveRecord::Result.new(column_names, values)
Expand Down
42 changes: 0 additions & 42 deletions lib/odbc_adapter/type_caster.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/odbc_adapter/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ODBCAdapter
VERSION = '5.0.3'.freeze
VERSION = '5.0.4'.freeze
end

0 comments on commit cc31c29

Please sign in to comment.