Skip to content

Commit 74cb8d4

Browse files
committed
Removed various version and inspection methods. They include:
* database_version * database_year * product_level * product_version * edition
1 parent 8a8e770 commit 74cb8d4

File tree

3 files changed

+24
-98
lines changed

3 files changed

+24
-98
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,23 @@
2222

2323
* SQL Server versions < 2012 which do not support OFFSET and FETCH. http://bit.ly/1B5Bwsd
2424
* The `enable_default_unicode_types` option. Default to national types all the time. Use SQL type name in migrations if needed.
25-
* Native type configs for older DB support. Includes the following with new default value.
25+
* Native type configs for older DB support. Includes the following with new default value:
2626
* native_string_database_type => `nvarchar`
2727
* native_text_database_type => `nvarchar(max)`
2828
* native_binary_database_type => `varbinary(max)`
29-
29+
* Various version and inspection methods removed. These include:
30+
* database_version
31+
* database_year
32+
* product_level
33+
* product_version
34+
* edition
3035

3136
#### Fixed
3237

3338
* n/a
3439

3540
#### Security
3641

37-
* n/a
42+
* The connection's `inspect` method no longer returns sensitive connection info. Very basic now.
3843

3944

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SQLServerAdapter < AbstractAdapter
3535

3636
ADAPTER_NAME = 'SQLServer'.freeze
3737

38-
attr_reader :database_version, :database_year, :spid, :product_level, :product_version, :edition
38+
attr_reader :spid
3939

4040
cattr_accessor :auto_connect, :cs_equality_operator,
4141
:lowercase_schema_reflection, :auto_connect_duration, :showplan_option
@@ -50,27 +50,9 @@ def initialize(connection, logger, pool, config)
5050
@config = config
5151
@connection_options = config
5252
connect
53-
@database_version = select_value 'SELECT @@version', 'SCHEMA'
54-
@database_year = begin
55-
if @database_version =~ /Azure/i
56-
@sqlserver_azure = true
57-
@database_version.match(/\s-\s([0-9.]+)/)[1]
58-
year = 2012
59-
else
60-
year = DATABASE_VERSION_REGEXP.match(@database_version)[1]
61-
year == 'Denali' ? 2011 : year.to_i
62-
end
63-
rescue
64-
0
65-
end
66-
@product_level = select_value "SELECT CAST(SERVERPROPERTY('productlevel') AS VARCHAR(128))", 'SCHEMA'
67-
@product_version = select_value "SELECT CAST(SERVERPROPERTY('productversion') AS VARCHAR(128))", 'SCHEMA'
68-
@edition = select_value "SELECT CAST(SERVERPROPERTY('edition') AS VARCHAR(128))", 'SCHEMA'
53+
@sqlserver_azure = !!(select_value('SELECT @@version', 'SCHEMA') =~ /Azure/i)
6954
initialize_dateformatter
7055
use_database
71-
unless @sqlserver_azure == true || SUPPORTED_VERSIONS.include?(@database_year)
72-
raise NotImplementedError, "Currently, only #{SUPPORTED_VERSIONS.to_sentence} are supported. We got back #{@database_version}."
73-
end
7456
end
7557

7658
# === Abstract Adapter ========================================== #
@@ -108,7 +90,7 @@ def supports_index_sort_order?
10890
end
10991

11092
def supports_partial_index?
111-
@database_year >= 2008
93+
true
11294
end
11395

11496
def supports_explain?
@@ -178,26 +160,6 @@ def sqlserver?
178160
true
179161
end
180162

181-
def sqlserver_2005?
182-
@database_year == 2005
183-
end
184-
185-
def sqlserver_2008?
186-
@database_year == 2008
187-
end
188-
189-
def sqlserver_2011?
190-
@database_year == 2011
191-
end
192-
193-
def sqlserver_2012?
194-
@database_year == 2012
195-
end
196-
197-
def sqlserver_2014?
198-
@database_year == 2014
199-
end
200-
201163
def sqlserver_azure?
202164
@sqlserver_azure
203165
end
@@ -207,7 +169,7 @@ def version
207169
end
208170

209171
def inspect
210-
"#<#{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}>"
172+
"#<#{self.class} version: #{version}, mode: #{@connection_options[:mode]}, azure: #{sqlserver_azure?.inspect}>"
211173
end
212174

213175
def auto_connect

test/cases/adapter_test_sqlserver.rb

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
2828
@basic_select_sql = "SELECT * FROM [customers] WHERE ([customers].[id] = 1)"
2929
end
3030

31+
it 'has basic and non-senstive information in the adpaters inspect method' do
32+
string = connection.inspect
33+
string.must_match %r{ActiveRecord::ConnectionAdapters::SQLServerAdapter}
34+
string.must_match %r{version\: \d.\d}
35+
string.must_match %r{mode: (dblib|odbc)}
36+
string.must_match %r{azure: (true|false)}
37+
string.wont_match %r{host}
38+
string.wont_match %r{password}
39+
string.wont_match %r{username}
40+
string.wont_match %r{port}
41+
end
42+
3143
it 'has a 128 max #table_alias_length' do
3244
assert connection.table_alias_length <= 128
3345
end
@@ -40,34 +52,6 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
4052
assert_equal 'SQLServer', connection.adapter_name
4153
end
4254

43-
it 'include version in inspect' do
44-
assert_match(/version\: \d.\d/, )
45-
end
46-
47-
it 'include database product level in inspect' do
48-
assert_match(/product_level\: "\w+/, connection.inspect)
49-
end
50-
51-
it 'include database product version in inspect' do
52-
assert_match(/product_version\: "\d+/, connection.inspect)
53-
end
54-
55-
it 'include database edition in inspect' do
56-
assert_match(/edition\: "\w+/, connection.inspect)
57-
end
58-
59-
it 'set database product level' do
60-
assert_match(/\w+/, connection.product_level)
61-
end
62-
63-
it 'set database product version' do
64-
assert_match(/\d+/, connection.product_version)
65-
end
66-
67-
it 'set database edition' do
68-
assert_match(/\w+/, connection.edition)
69-
end
70-
7155
it 'support migrations' do
7256
assert connection.supports_migrations?
7357
end
@@ -87,31 +71,6 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
8771
end
8872
end
8973

90-
describe 'for database version' do
91-
92-
before do
93-
@version_regexp = ActiveRecord::ConnectionAdapters::SQLServerAdapter::DATABASE_VERSION_REGEXP
94-
@supported_versions = ActiveRecord::ConnectionAdapters::SQLServerAdapter::SUPPORTED_VERSIONS
95-
@sqlserver_2005_string = "Microsoft SQL Server 2005 - 9.00.3215.00 (Intel X86)"
96-
@sqlserver_2008_string = "Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)"
97-
@sqlserver_2011_string1 = %|Microsoft SQL Server "Denali" (CTP1) - 11.0.1103.9 (Intel X86) Sep 24 2010 22:02:43 Copyright (c) Microsoft Corporation Enterprise Evaluation Edition on Windows NT 6.0 (Build 6002: Service Pack 2)|
98-
end
99-
100-
it 'return a string from #database_version that matches class regexp' do
101-
assert_match @version_regexp, connection.database_version
102-
end unless sqlserver_azure?
103-
104-
it 'return a 4 digit year fixnum for #database_year' do
105-
assert_instance_of Fixnum, connection.database_year
106-
@supported_versions.must_include connection.database_year
107-
end
108-
109-
it 'return a code name if year not available' do
110-
assert_equal "Denali", @version_regexp.match(@sqlserver_2011_string1)[1]
111-
end
112-
113-
end
114-
11574
it 'return true to #insert_sql? for inserts only' do
11675
assert connection.send(:insert_sql?,'INSERT...')
11776
assert connection.send(:insert_sql?, "EXEC sp_executesql N'INSERT INTO [fk_test_has_fks] ([fk_id]) VALUES (@0); SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident', N'@0 int', @0 = 0")

0 commit comments

Comments
 (0)