Skip to content

Commit 5529234

Browse files
committed
Merge pull request #149 from ManageIQ/dont_hit_db_on_inspect
Don't hit the database on inspect and run the selects without retry and log blocks.
2 parents bebde18 + 3fd6d7b commit 5529234

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class SQLServerAdapter < AbstractAdapter
176176
DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+"?(\d{4}|\w+)"?/
177177
SUPPORTED_VERSIONS = [2005,2008,2010,2011].freeze
178178

179-
attr_reader :database_version, :database_year, :spid
179+
attr_reader :database_version, :database_year, :spid, :product_level, :product_version, :edition
180180

181181
cattr_accessor :native_text_database_type, :native_binary_database_type, :native_string_database_type,
182182
:log_info_schema_queries, :enable_default_unicode_types, :auto_connect,
@@ -208,6 +208,9 @@ def initialize(logger,config)
208208
rescue
209209
0
210210
end
211+
@product_level = info_schema_query { select_value("SELECT CAST(SERVERPROPERTY('productlevel') AS VARCHAR(128))") }
212+
@product_version = info_schema_query { select_value("SELECT CAST(SERVERPROPERTY('productversion') AS VARCHAR(128))") }
213+
@edition = info_schema_query { select_value("SELECT CAST(SERVERPROPERTY('edition') AS VARCHAR(128))") }
211214
initialize_dateformatter
212215
initialize_sqlserver_caches
213216
use_database
@@ -323,20 +326,8 @@ def version
323326
self.class::VERSION
324327
end
325328

326-
def product_level
327-
@product_level ||= info_schema_query { select_value("SELECT CAST(SERVERPROPERTY('productlevel') AS VARCHAR(128))")}
328-
end
329-
330-
def product_version
331-
@product_version ||= info_schema_query { select_value("SELECT CAST(SERVERPROPERTY('productversion') AS VARCHAR(128))")}
332-
end
333-
334-
def edition
335-
@edition ||= info_schema_query { select_value("SELECT CAST(SERVERPROPERTY('edition') AS VARCHAR(128))")}
336-
end
337-
338329
def inspect
339-
"#<#{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}>"
330+
"#<#{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}>"
340331
end
341332

342333
def auto_connect
@@ -443,7 +434,7 @@ def connect
443434
end
444435
end
445436
end
446-
@spid = _raw_select("SELECT @@SPID", :fetch => :rows).first.first
437+
@spid = _raw_select("SELECT @@SPID", :fetch => :rows).first.first
447438
configure_connection
448439
rescue
449440
raise unless @auto_connecting

0 commit comments

Comments
 (0)