Skip to content

Commit c24a31d

Browse files
committed
Reorganize quoting methods
This makes the quote_column_name and quote_table_names methods organized more similarly to how they are the new mysql and postgres adapters.
1 parent b47d581 commit c24a31d

File tree

1 file changed

+47
-47
lines changed
  • lib/active_record/connection_adapters/oracle_enhanced

1 file changed

+47
-47
lines changed

lib/active_record/connection_adapters/oracle_enhanced/quoting.rb

+47-47
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,60 @@ module ActiveRecord
44
module ConnectionAdapters
55
module OracleEnhanced
66
module Quoting
7+
extend ActiveSupport::Concern
78
# QUOTING ==================================================
89
#
910
# see: abstract/quoting.rb
1011
QUOTED_COLUMN_NAMES = Concurrent::Map.new # :nodoc:
1112
QUOTED_TABLE_NAMES = Concurrent::Map.new # :nodoc:
1213

13-
def quote_column_name(name) # :nodoc:
14-
name = name.to_s
15-
QUOTED_COLUMN_NAMES[name] ||= if /\A[a-z][a-z_0-9$#]*\Z/.match?(name)
16-
"\"#{name.upcase}\""
17-
else
18-
# remove double quotes which cannot be used inside quoted identifier
19-
"\"#{name.delete('"')}\""
14+
module ClassMethods # :nodoc:
15+
def column_name_matcher
16+
/
17+
\A
18+
(
19+
(?:
20+
# "table_name"."column_name" | function(one or no argument)
21+
((?:\w+\.|"\w+"\.)?(?:\w+|"\w+") | \w+\((?:|\g<2>)\))
22+
)
23+
(?:(?:\s+AS)?\s+(?:\w+|"\w+"))?
24+
)
25+
(?:\s*,\s*\g<1>)*
26+
\z
27+
/ix
28+
end
29+
30+
def column_name_with_order_matcher
31+
/
32+
\A
33+
(
34+
(?:
35+
# "table_name"."column_name" | function(one or no argument)
36+
((?:\w+\.|"\w+"\.)?(?:\w+|"\w+") | \w+\((?:|\g<2>)\))
37+
)
38+
(?:\s+ASC|\s+DESC)?
39+
(?:\s+NULLS\s+(?:FIRST|LAST))?
40+
)
41+
(?:\s*,\s*\g<1>)*
42+
\z
43+
/ix
44+
end
45+
46+
def quote_column_name(name) # :nodoc:
47+
name = name.to_s
48+
QUOTED_COLUMN_NAMES[name] ||= if /\A[a-z][a-z_0-9$#]*\Z/.match?(name)
49+
"\"#{name.upcase}\""
50+
else
51+
# remove double quotes which cannot be used inside quoted identifier
52+
"\"#{name.delete('"')}\""
53+
end
54+
end
55+
56+
def quote_table_name(name) # :nodoc:
57+
name, _link = name.to_s.split("@")
58+
QUOTED_TABLE_NAMES[name] ||= [name.split(".").map { |n| quote_column_name(n) }].join(".")
2059
end
60+
2161
end
2262

2363
# This method is used in add_index to identify either column name (which is quoted)
@@ -67,10 +107,6 @@ def self.mixed_case?(name)
67107
!!(object_name =~ /[A-Z]/ && object_name =~ /[a-z]/)
68108
end
69109

70-
def quote_table_name(name) # :nodoc:
71-
name, _link = name.to_s.split("@")
72-
QUOTED_TABLE_NAMES[name] ||= [name.split(".").map { |n| quote_column_name(n) }].join(".")
73-
end
74110

75111
def quote_string(s) # :nodoc:
76112
s.gsub(/'/, "''")
@@ -131,42 +167,6 @@ def type_cast(value)
131167
end
132168
end
133169

134-
def column_name_matcher
135-
COLUMN_NAME
136-
end
137-
138-
def column_name_with_order_matcher
139-
COLUMN_NAME_WITH_ORDER
140-
end
141-
142-
COLUMN_NAME = /
143-
\A
144-
(
145-
(?:
146-
# "table_name"."column_name" | function(one or no argument)
147-
((?:\w+\.|"\w+"\.)?(?:\w+|"\w+") | \w+\((?:|\g<2>)\))
148-
)
149-
(?:(?:\s+AS)?\s+(?:\w+|"\w+"))?
150-
)
151-
(?:\s*,\s*\g<1>)*
152-
\z
153-
/ix
154-
155-
COLUMN_NAME_WITH_ORDER = /
156-
\A
157-
(
158-
(?:
159-
# "table_name"."column_name" | function(one or no argument)
160-
((?:\w+\.|"\w+"\.)?(?:\w+|"\w+") | \w+\((?:|\g<2>)\))
161-
)
162-
(?:\s+ASC|\s+DESC)?
163-
(?:\s+NULLS\s+(?:FIRST|LAST))?
164-
)
165-
(?:\s*,\s*\g<1>)*
166-
\z
167-
/ix
168-
private_constant :COLUMN_NAME, :COLUMN_NAME_WITH_ORDER
169-
170170
private
171171
def oracle_downcase(column_name)
172172
return nil if column_name.nil?

0 commit comments

Comments
 (0)