File tree 3 files changed +38
-10
lines changed
lib/active_record/connection_adapters/sqlserver
3 files changed +38
-10
lines changed Original file line number Diff line number Diff line change @@ -415,15 +415,13 @@ def column_definitions(table_name)
415
415
ci [ :default_function ] = begin
416
416
default = ci [ :default_value ]
417
417
if default . nil? && view_exists
418
- default = uncached do
419
- select_value %{
420
- SELECT c.COLUMN_DEFAULT
421
- FROM #{ database } .INFORMATION_SCHEMA.COLUMNS c
422
- WHERE
423
- c.TABLE_NAME = '#{ view_tblnm } '
424
- AND c.COLUMN_NAME = '#{ views_real_column_name ( table_name , ci [ :name ] ) } '
425
- } . squish , 'SCHEMA'
426
- end
418
+ default = select_value %{
419
+ SELECT c.COLUMN_DEFAULT
420
+ FROM #{ database } .INFORMATION_SCHEMA.COLUMNS c
421
+ WHERE
422
+ c.TABLE_NAME = '#{ view_tblnm } '
423
+ AND c.COLUMN_NAME = '#{ views_real_column_name ( table_name , ci [ :name ] ) } '
424
+ } . squish , 'SCHEMA'
427
425
end
428
426
case default
429
427
when nil
@@ -442,7 +440,7 @@ def column_definitions(table_name)
442
440
else ci [ :type ]
443
441
end
444
442
value = default . match ( /\A \( (.*)\) \Z /m ) [ 1 ]
445
- value = uncached { select_value ( "SELECT CAST(#{ value } AS #{ type } ) AS value3 " , 'SCHEMA' ) }
443
+ value = select_value ( "SELECT CAST(#{ value } AS #{ type } ) AS value " , 'SCHEMA' )
446
444
[ value , nil ]
447
445
end
448
446
end
Original file line number Diff line number Diff line change 2
2
require 'bundler/setup'
3
3
Bundler . require :default , :development
4
4
require 'pry'
5
+ require 'support/core_ext/query_cache'
5
6
require 'support/minitest_sqlserver'
6
7
require 'support/test_in_memory_oltp'
7
8
require 'cases/helper'
Original file line number Diff line number Diff line change
1
+ require 'active_record/connection_adapters/sqlserver_adapter'
2
+
3
+ module SqlIgnoredCache
4
+ extend ActiveSupport ::Concern
5
+
6
+ IGNORED_SQL = [
7
+ /INFORMATION_SCHEMA\. (TABLES|VIEWS|COLUMNS|KEY_COLUMN_USAGE)/im ,
8
+ /SELECT @@version/ ,
9
+ /SELECT @@TRANCOUNT/ ,
10
+ /(BEGIN|COMMIT|ROLLBACK|SAVE) TRANSACTION/ ,
11
+ /SELECT CAST\( .* AS .*\) AS value/ ,
12
+ /SELECT DATABASEPROPERTYEX/im
13
+ ]
14
+
15
+ # We don't want to coerce every ActiveRecord test that relies on `query_cache`
16
+ # just because we do more queries than the other adapters.
17
+ #
18
+ # Removing internal queries from the cache will make AR tests pass without
19
+ # compromising cache outside tests.
20
+ def cache_sql ( sql , name , binds )
21
+ result = super
22
+ @query_cache . delete_if { |k , v | k =~ Regexp . union ( IGNORED_SQL ) }
23
+ result
24
+ end
25
+ end
26
+
27
+ ActiveSupport . on_load ( :active_record ) do
28
+ ActiveRecord ::ConnectionAdapters ::SQLServerAdapter . prepend ( SqlIgnoredCache )
29
+ end
You can’t perform that action at this time.
0 commit comments