@@ -167,7 +167,7 @@ class SQLServerAdapter < AbstractAdapter
167167 ADAPTER_NAME = 'SQLServer' . freeze
168168 VERSION = '3.0.10' . freeze
169169 DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s +"?(\d {4}|\w +)"?/
170- SUPPORTED_VERSIONS = [ 2005 , 2008 , 2011 ] . freeze
170+ SUPPORTED_VERSIONS = [ 2005 , 2008 , 2010 , 2011 ] . freeze
171171
172172 attr_reader :database_version , :database_year ,
173173 :connection_supports_native_types
@@ -182,8 +182,13 @@ def initialize(logger,config)
182182 super ( @connection , logger )
183183 @database_version = info_schema_query { select_value ( 'SELECT @@version' ) }
184184 @database_year = begin
185- year = DATABASE_VERSION_REGEXP . match ( @database_version ) [ 1 ]
186- year == "Denali" ? 2011 : year . to_i
185+ if @database_version =~ /Microsoft SQL Azure/i
186+ @sqlserver_azure = true
187+ @database_version . match ( /\s (\d {4})\s / ) [ 1 ] . to_i
188+ else
189+ year = DATABASE_VERSION_REGEXP . match ( @database_version ) [ 1 ]
190+ year == "Denali" ? 2011 : year . to_i
191+ end
187192 rescue
188193 0
189194 end
@@ -290,6 +295,10 @@ def sqlserver_2011?
290295 @database_year == 2011
291296 end
292297
298+ def sqlserver_azure?
299+ @sqlserver_azure && @database_year == 2010
300+ end
301+
293302 def version
294303 self . class ::VERSION
295304 end
@@ -311,11 +320,11 @@ def native_text_database_type
311320 end
312321
313322 def native_time_database_type
314- sqlserver_2008 ? ? 'time ' : 'datetime '
323+ sqlserver_2005 ? ? 'datetime ' : 'time '
315324 end
316325
317326 def native_date_database_type
318- sqlserver_2008 ? ? 'date ' : 'datetime '
327+ sqlserver_2005 ? ? 'datetime ' : 'date '
319328 end
320329
321330 def native_binary_database_type
@@ -362,11 +371,22 @@ def connect
362371 :appname => appname ,
363372 :login_timeout => login_timeout ,
364373 :timeout => timeout ,
365- :encoding => encoding
374+ :encoding => encoding ,
375+ :azure => config [ :azure ]
366376 } ) . tap do |client |
367- client . execute ( "SET ANSI_DEFAULTS ON" ) . do
368- client . execute ( "SET IMPLICIT_TRANSACTIONS OFF" ) . do
369- client . execute ( "SET CURSOR_CLOSE_ON_COMMIT OFF" ) . do
377+ if config [ :azure ]
378+ client . execute ( "SET ANSI_NULLS ON" ) . do
379+ client . execute ( "SET CURSOR_CLOSE_ON_COMMIT OFF" ) . do
380+ client . execute ( "SET ANSI_NULL_DFLT_ON ON" ) . do
381+ client . execute ( "SET IMPLICIT_TRANSACTIONS OFF" ) . do
382+ client . execute ( "SET ANSI_PADDING ON" ) . do
383+ client . execute ( "SET QUOTED_IDENTIFIER ON" )
384+ client . execute ( "SET ANSI_WARNINGS ON" ) . do
385+ else
386+ client . execute ( "SET ANSI_DEFAULTS ON" ) . do
387+ client . execute ( "SET CURSOR_CLOSE_ON_COMMIT OFF" ) . do
388+ client . execute ( "SET IMPLICIT_TRANSACTIONS OFF" ) . do
389+ end
370390 end
371391 when :odbc
372392 odbc = [ '::ODBC' , '::ODBC_UTF8' , '::ODBC_NONE' ] . detect { |odbc_ns | odbc_ns . constantize rescue nil } . constantize
0 commit comments