Skip to content

Commit fbaf023

Browse files
committed
Default behavor for sqlserver 2000 is text type is text. Add class attribute accessor for setting this which tests do to varchar(8000) when tests are running on a 2000 DB version.
1 parent a6936d8 commit fbaf023

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ class SQLServerAdapter < AbstractAdapter
274274
SUPPORTED_VERSIONS = [2000,2005].freeze
275275
LIMITABLE_TYPES = [:string,:integer,:float].freeze
276276

277+
cattr_accessor :native_text_database_type
278+
277279
class << self
278280

279281
def type_limitable?(type)
@@ -321,6 +323,10 @@ def sqlserver_2005?
321323
database_year == 2005
322324
end
323325

326+
def native_text_database_type
327+
self.class.native_text_database_type || (sqlserver_2005? ? 'varchar(max)' : 'text')
328+
end
329+
324330
# QUOTING ==================================================#
325331

326332
def quote(value, column = nil)
@@ -468,12 +474,11 @@ def empty_insert_statement(table_name)
468474
# SCHEMA STATEMENTS ========================================#
469475

470476
def native_database_types
471-
text = sqlserver_2005? ? "varchar(max)" : "varchar(8000)"
472477
binary = sqlserver_2005? ? "varbinary(max)" : "image"
473478
{
474479
:primary_key => "int NOT NULL IDENTITY(1, 1) PRIMARY KEY",
475480
:string => { :name => "varchar", :limit => 255 },
476-
:text => { :name => text },
481+
:text => { :name => native_text_database_type },
477482
:integer => { :name => "int", :limit => 4 },
478483
:float => { :name => "float", :limit => 8 },
479484
:decimal => { :name => "decimal" },

test/cases/sqlserver_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414

1515
class TableWithRealColumn < ActiveRecord::Base; end
1616

17+
# Change the text database type to support ActiveRecord's tests for = on text columns which
18+
# is not supported in SQL Server text columns, so use varchar(8000) instead.
19+
20+
if ActiveRecord::Base.connection.sqlserver_2000?
21+
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = 'varchar(8000)'
22+
end
23+
24+
# Our changes/additions to ActiveRecord test helpers specific for SQL Server.
1725

1826
ActiveRecord::Base.connection.class.class_eval do
1927
IGNORED_SQL << /SELECT SCOPE_IDENTITY/ << /INFORMATION_SCHEMA.TABLES/ << /INFORMATION_SCHEMA.COLUMNS/

0 commit comments

Comments
 (0)