From b1c48364cdd6d4acf66f25da53ff78b36732f9e9 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Fri, 18 Nov 2011 16:22:34 -0500 Subject: [PATCH 1/2] Don't hit the database on inspect and run the selects without retry and log blocks. --- .../connection_adapters/sqlserver_adapter.rb | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/active_record/connection_adapters/sqlserver_adapter.rb b/lib/active_record/connection_adapters/sqlserver_adapter.rb index b4a3521ef..9828066a1 100644 --- a/lib/active_record/connection_adapters/sqlserver_adapter.rb +++ b/lib/active_record/connection_adapters/sqlserver_adapter.rb @@ -176,7 +176,7 @@ class SQLServerAdapter < AbstractAdapter DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+"?(\d{4}|\w+)"?/ SUPPORTED_VERSIONS = [2005,2008,2010,2011].freeze - attr_reader :database_version, :database_year, :spid + attr_reader :database_version, :database_year, :spid, :product_level, :product_version, :edition cattr_accessor :native_text_database_type, :native_binary_database_type, :native_string_database_type, :log_info_schema_queries, :enable_default_unicode_types, :auto_connect, @@ -323,20 +323,8 @@ def version self.class::VERSION end - def product_level - @product_level ||= info_schema_query { select_value("SELECT CAST(SERVERPROPERTY('productlevel') AS VARCHAR(128))")} - end - - def product_version - @product_version ||= info_schema_query { select_value("SELECT CAST(SERVERPROPERTY('productversion') AS VARCHAR(128))")} - end - - def edition - @edition ||= info_schema_query { select_value("SELECT CAST(SERVERPROPERTY('edition') AS VARCHAR(128))")} - end - def inspect - "#<#{self.class} version: #{version}, year: #{@database_year}, product_level: #{product_level.inspect}, product_version: #{product_version.inspect}, edition: #{edition.inspect}, connection_options: #{@connection_options.inspect}>" + "#<#{self.class} version: #{version}, year: #{@database_year}, product_level: #{@product_level.inspect}, product_version: #{@product_version.inspect}, edition: #{@edition.inspect}, connection_options: #{@connection_options.inspect}>" end def auto_connect @@ -443,7 +431,10 @@ def connect end end end - @spid = _raw_select("SELECT @@SPID", :fetch => :rows).first.first + @spid = _raw_select("SELECT @@SPID", :fetch => :rows).first.first + @product_level = _raw_select("SELECT CAST(SERVERPROPERTY('productlevel') AS VARCHAR(128))", :fetch => :rows).first.first + @product_version = _raw_select("SELECT CAST(SERVERPROPERTY('productversion') AS VARCHAR(128))", :fetch => :rows).first.first + @edition = _raw_select("SELECT CAST(SERVERPROPERTY('edition') AS VARCHAR(128))", :fetch => :rows).first.first configure_connection rescue raise unless @auto_connecting From 3fd6d7b0937c8817391fedbd573de18f47d53575 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Mon, 21 Nov 2011 10:15:54 -0500 Subject: [PATCH 2/2] Set product_level, product_version, and edition where we get information about the database as opposed to the connection itself. --- lib/active_record/connection_adapters/sqlserver_adapter.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_record/connection_adapters/sqlserver_adapter.rb b/lib/active_record/connection_adapters/sqlserver_adapter.rb index 9828066a1..fd38c32b3 100644 --- a/lib/active_record/connection_adapters/sqlserver_adapter.rb +++ b/lib/active_record/connection_adapters/sqlserver_adapter.rb @@ -208,6 +208,9 @@ def initialize(logger,config) rescue 0 end + @product_level = info_schema_query { select_value("SELECT CAST(SERVERPROPERTY('productlevel') AS VARCHAR(128))") } + @product_version = info_schema_query { select_value("SELECT CAST(SERVERPROPERTY('productversion') AS VARCHAR(128))") } + @edition = info_schema_query { select_value("SELECT CAST(SERVERPROPERTY('edition') AS VARCHAR(128))") } initialize_dateformatter initialize_sqlserver_caches use_database @@ -432,9 +435,6 @@ def connect end end @spid = _raw_select("SELECT @@SPID", :fetch => :rows).first.first - @product_level = _raw_select("SELECT CAST(SERVERPROPERTY('productlevel') AS VARCHAR(128))", :fetch => :rows).first.first - @product_version = _raw_select("SELECT CAST(SERVERPROPERTY('productversion') AS VARCHAR(128))", :fetch => :rows).first.first - @edition = _raw_select("SELECT CAST(SERVERPROPERTY('edition') AS VARCHAR(128))", :fetch => :rows).first.first configure_connection rescue raise unless @auto_connecting