Skip to content

Commit dff21ff

Browse files
committed
Converted database_version year and major revision to instance variables.
This was to remove some duplication and eliminate unneeded methods.
1 parent fc08426 commit dff21ff

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,19 @@ class SQLServerAdapter < AbstractAdapter
246246
def initialize(connection, logger, connection_options=nil)
247247
super(connection, logger)
248248
@connection_options = connection_options
249+
if database_version =~ /(2000|2005) - (\d+)\./
250+
@database_version_year = $1.to_i
251+
@database_version_major = $2.to_i
252+
else
253+
raise "Currently, only 2000 and 2005 are supported versions"
254+
end
255+
249256
end
250257

251258
def native_database_types
252259
# support for varchar(max) and varbinary(max) for text and binary cols if our version is 9 (2005)
253-
txt = database_version_major >= 9 ? "varchar(max)" : "text"
254-
bin = database_version_major >= 9 ? "varbinary(max)" : "image"
260+
txt = @database_version_major >= 9 ? "varchar(max)" : "text"
261+
bin = @database_version_major >= 9 ? "varbinary(max)" : "image"
255262
{
256263
:primary_key => "int NOT NULL IDENTITY(1, 1) PRIMARY KEY",
257264
:string => { :name => "varchar", :limit => 255 },
@@ -277,17 +284,7 @@ def database_version
277284
# "Microsoft SQL Server 2000 - 8.00.2039 (Intel X86) \n\tMay 3 2005 23:18:38 \n\tCopyright (c) 1988-2003 Microsoft Corporation\n\tEnterprise Edition on Windows NT 5.2 (Build 3790: )\n"
278285
# "Microsoft SQL Server 2005 - 9.00.3215.00 (Intel X86) \n\tDec 8 2007 18:51:32 \n\tCopyright (c) 1988-2005 Microsoft Corporation\n\tStandard Edition on Windows NT 5.2 (Build 3790: Service Pack 2)\n"
279286
return select_value("SELECT @@version")
280-
end
281-
282-
def database_version_year
283-
# returns 2000 or 2005
284-
return $1.to_i if database_version =~ /(2000|2005) - (\d+)\./
285-
end
286-
287-
def database_version_major
288-
# returns 8 or 9
289-
return $2.to_i if database_version =~ /(2000|2005) - (\d+)\./
290-
end
287+
end
291288

292289
def supports_migrations? #:nodoc:
293290
true

0 commit comments

Comments
 (0)