Skip to content

Commit f5315eb

Browse files
committed
Move initialize_type_map to class method
1 parent 71267c7 commit f5315eb

1 file changed

Lines changed: 38 additions & 34 deletions

File tree

lib/active_record/connection_adapters/odbc_adapter.rb

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -162,37 +162,39 @@ def new_column(name, default, sql_type_metadata, null, table_name, native_type =
162162

163163
# Build the type map for ActiveRecord
164164
# Here, ODBC and ODBC_UTF8 constants are interchangeable
165-
def initialize_type_map(map)
166-
map.register_type 'boolean', Type::Boolean.new
167-
map.register_type 'json', Type::Json.new
168-
map.register_type ODBC::SQL_CHAR, Type::String.new
169-
map.register_type ODBC::SQL_LONGVARCHAR, Type::Text.new
170-
map.register_type ODBC::SQL_TINYINT, Type::Integer.new(limit: 4)
171-
map.register_type ODBC::SQL_SMALLINT, Type::Integer.new(limit: 8)
172-
map.register_type ODBC::SQL_INTEGER, Type::Integer.new(limit: 16)
173-
map.register_type ODBC::SQL_BIGINT, Type::BigInteger.new(limit: 32)
174-
map.register_type ODBC::SQL_REAL, Type::Float.new(limit: 24)
175-
map.register_type ODBC::SQL_FLOAT, Type::Float.new
176-
map.register_type ODBC::SQL_DOUBLE, Type::Float.new(limit: 53)
177-
map.register_type ODBC::SQL_DECIMAL, Type::Float.new
178-
map.register_type ODBC::SQL_NUMERIC, Type::Integer.new
179-
map.register_type ODBC::SQL_BINARY, Type::Binary.new
180-
map.register_type ODBC::SQL_DATE, Type::Date.new
181-
map.register_type ODBC::SQL_DATETIME, Type::DateTime.new
182-
map.register_type ODBC::SQL_TIME, Type::Time.new
183-
map.register_type ODBC::SQL_TIMESTAMP, Type::DateTime.new
184-
map.register_type ODBC::SQL_GUID, Type::String.new
185-
186-
alias_type map, ODBC::SQL_BIT, 'boolean'
187-
alias_type map, ODBC::SQL_VARCHAR, ODBC::SQL_CHAR
188-
alias_type map, ODBC::SQL_WCHAR, ODBC::SQL_CHAR
189-
alias_type map, ODBC::SQL_WVARCHAR, ODBC::SQL_CHAR
190-
alias_type map, ODBC::SQL_WLONGVARCHAR, ODBC::SQL_LONGVARCHAR
191-
alias_type map, ODBC::SQL_VARBINARY, ODBC::SQL_BINARY
192-
alias_type map, ODBC::SQL_LONGVARBINARY, ODBC::SQL_BINARY
193-
alias_type map, ODBC::SQL_TYPE_DATE, ODBC::SQL_DATE
194-
alias_type map, ODBC::SQL_TYPE_TIME, ODBC::SQL_TIME
195-
alias_type map, ODBC::SQL_TYPE_TIMESTAMP, ODBC::SQL_TIMESTAMP
165+
class << self
166+
def initialize_type_map(map)
167+
map.register_type 'boolean', Type::Boolean.new
168+
map.register_type 'json', Type::Json.new
169+
map.register_type ODBC::SQL_CHAR, Type::String.new
170+
map.register_type ODBC::SQL_LONGVARCHAR, Type::Text.new
171+
map.register_type ODBC::SQL_TINYINT, Type::Integer.new(limit: 4)
172+
map.register_type ODBC::SQL_SMALLINT, Type::Integer.new(limit: 8)
173+
map.register_type ODBC::SQL_INTEGER, Type::Integer.new(limit: 16)
174+
map.register_type ODBC::SQL_BIGINT, Type::BigInteger.new(limit: 32)
175+
map.register_type ODBC::SQL_REAL, Type::Float.new(limit: 24)
176+
map.register_type ODBC::SQL_FLOAT, Type::Float.new
177+
map.register_type ODBC::SQL_DOUBLE, Type::Float.new(limit: 53)
178+
map.register_type ODBC::SQL_DECIMAL, Type::Float.new
179+
map.register_type ODBC::SQL_NUMERIC, Type::Integer.new
180+
map.register_type ODBC::SQL_BINARY, Type::Binary.new
181+
map.register_type ODBC::SQL_DATE, Type::Date.new
182+
map.register_type ODBC::SQL_DATETIME, Type::DateTime.new
183+
map.register_type ODBC::SQL_TIME, Type::Time.new
184+
map.register_type ODBC::SQL_TIMESTAMP, Type::DateTime.new
185+
map.register_type ODBC::SQL_GUID, Type::String.new
186+
187+
alias_type map, ODBC::SQL_BIT, 'boolean'
188+
alias_type map, ODBC::SQL_VARCHAR, ODBC::SQL_CHAR
189+
alias_type map, ODBC::SQL_WCHAR, ODBC::SQL_CHAR
190+
alias_type map, ODBC::SQL_WVARCHAR, ODBC::SQL_CHAR
191+
alias_type map, ODBC::SQL_WLONGVARCHAR, ODBC::SQL_LONGVARCHAR
192+
alias_type map, ODBC::SQL_VARBINARY, ODBC::SQL_BINARY
193+
alias_type map, ODBC::SQL_LONGVARBINARY, ODBC::SQL_BINARY
194+
alias_type map, ODBC::SQL_TYPE_DATE, ODBC::SQL_DATE
195+
alias_type map, ODBC::SQL_TYPE_TIME, ODBC::SQL_TIME
196+
alias_type map, ODBC::SQL_TYPE_TIMESTAMP, ODBC::SQL_TIMESTAMP
197+
end
196198
end
197199

198200
# Translate an exception from the native DBMS to something usable by
@@ -221,9 +223,11 @@ def translate_exception(exception, message)
221223
# Can't use the built-in ActiveRecord map#alias_type because it doesn't
222224
# work with non-string keys, and in our case the keys are (almost) all
223225
# numeric
224-
def alias_type(map, new_type, old_type)
225-
map.register_type(new_type) do |_, *args|
226-
map.lookup(old_type, *args)
226+
class << self
227+
def alias_type(map, new_type, old_type)
228+
map.register_type(new_type) do |_, *args|
229+
map.lookup(old_type, *args)
230+
end
227231
end
228232
end
229233

0 commit comments

Comments
 (0)