@@ -4,9 +4,53 @@ module ActiveRecord
4
4
module ConnectionAdapters
5
5
module SQLServer
6
6
module Quoting
7
+ extend ActiveSupport ::Concern
8
+
7
9
QUOTED_COLUMN_NAMES = Concurrent ::Map . new # :nodoc:
8
10
QUOTED_TABLE_NAMES = Concurrent ::Map . new # :nodoc:
9
11
12
+ module ClassMethods
13
+ def column_name_matcher
14
+ /
15
+ \A
16
+ (
17
+ (?:
18
+ # [database_name].[database_owner].[table_name].[column_name] | function(one or no argument)
19
+ ((?:\w +\. |\[ \w +\] \. )?(?:\w +\. |\[ \w +\] \. )?(?:\w +\. |\[ \w +\] \. )?(?:\w +|\[ \w +\] ) | \w +\( (?:|\g <2>)\) )
20
+ )
21
+ (?:\s +AS\s +(?:\w +|\[ \w +\] ))?
22
+ )
23
+ (?:\s *,\s *\g <1>)*
24
+ \z
25
+ /ix
26
+ end
27
+
28
+ def column_name_with_order_matcher
29
+ /
30
+ \A
31
+ (
32
+ (?:
33
+ # [database_name].[database_owner].[table_name].[column_name] | function(one or no argument)
34
+ ((?:\w +\. |\[ \w +\] \. )?(?:\w +\. |\[ \w +\] \. )?(?:\w +\. |\[ \w +\] \. )?(?:\w +|\[ \w +\] ) | \w +\( (?:|\g <2>)\) )
35
+ )
36
+ (?:\s +COLLATE\s +\w +)?
37
+ (?:\s +ASC|\s +DESC)?
38
+ (?:\s +NULLS\s +(?:FIRST|LAST))?
39
+ )
40
+ (?:\s *,\s *\g <1>)*
41
+ \z
42
+ /ix
43
+ end
44
+
45
+ def quote_column_name ( name )
46
+ QUOTED_COLUMN_NAMES [ name ] ||= SQLServer ::Utils . extract_identifiers ( name ) . quoted
47
+ end
48
+
49
+ def quote_table_name ( name )
50
+ QUOTED_TABLE_NAMES [ name ] ||= SQLServer ::Utils . extract_identifiers ( name ) . quoted
51
+ end
52
+ end
53
+
10
54
def fetch_type_metadata ( sql_type , sqlserver_options = { } )
11
55
cast_type = lookup_cast_type ( sql_type )
12
56
@@ -33,14 +77,6 @@ def quote_string_single_national(s)
33
77
SQLServer ::Utils . quote_string_single_national ( s )
34
78
end
35
79
36
- def quote_column_name ( name )
37
- QUOTED_COLUMN_NAMES [ name ] ||= SQLServer ::Utils . extract_identifiers ( name ) . quoted
38
- end
39
-
40
- def quote_table_name ( name )
41
- QUOTED_TABLE_NAMES [ name ] ||= SQLServer ::Utils . extract_identifiers ( name ) . quoted
42
- end
43
-
44
80
def quote_default_expression ( value , column )
45
81
cast_type = lookup_cast_type ( column . sql_type )
46
82
if cast_type . type == :uuid && value . is_a? ( String ) && value . include? ( '()' )
@@ -76,44 +112,6 @@ def quoted_date(value)
76
112
end
77
113
end
78
114
79
- def column_name_matcher
80
- COLUMN_NAME
81
- end
82
-
83
- def column_name_with_order_matcher
84
- COLUMN_NAME_WITH_ORDER
85
- end
86
-
87
- COLUMN_NAME = /
88
- \A
89
- (
90
- (?:
91
- # [database_name].[database_owner].[table_name].[column_name] | function(one or no argument)
92
- ((?:\w +\. |\[ \w +\] \. )?(?:\w +\. |\[ \w +\] \. )?(?:\w +\. |\[ \w +\] \. )?(?:\w +|\[ \w +\] ) | \w +\( (?:|\g <2>)\) )
93
- )
94
- (?:\s +AS\s +(?:\w +|\[ \w +\] ))?
95
- )
96
- (?:\s *,\s *\g <1>)*
97
- \z
98
- /ix
99
-
100
- COLUMN_NAME_WITH_ORDER = /
101
- \A
102
- (
103
- (?:
104
- # [database_name].[database_owner].[table_name].[column_name] | function(one or no argument)
105
- ((?:\w +\. |\[ \w +\] \. )?(?:\w +\. |\[ \w +\] \. )?(?:\w +\. |\[ \w +\] \. )?(?:\w +|\[ \w +\] ) | \w +\( (?:|\g <2>)\) )
106
- )
107
- (?:\s +COLLATE\s +\w +)?
108
- (?:\s +ASC|\s +DESC)?
109
- (?:\s +NULLS\s +(?:FIRST|LAST))?
110
- )
111
- (?:\s *,\s *\g <1>)*
112
- \z
113
- /ix
114
-
115
- private_constant :COLUMN_NAME , :COLUMN_NAME_WITH_ORDER
116
-
117
115
def quote ( value )
118
116
case value
119
117
when Type ::Binary ::Data
0 commit comments