@@ -138,20 +138,20 @@ internal MySqlParameterCollection AlignParamsWithDb(MySqlParameterCollection? pa
138138 internal static List < CachedParameter > ParseParameters ( string parametersSql )
139139 {
140140 // strip comments
141- parametersSql = Regex . Replace ( parametersSql , @"/\*.*?\*/" , "" , RegexOptions . Singleline ) ;
142- parametersSql = Regex . Replace ( parametersSql , @"(^|\s)--.*?$" , "" , RegexOptions . Multiline ) ;
141+ parametersSql = s_cStyleComments . Replace ( parametersSql , "" ) ;
142+ parametersSql = s_singleLineComments . Replace ( parametersSql , "" ) ;
143143
144144 // normalize spaces
145- parametersSql = Regex . Replace ( parametersSql , @"\s+" , " " ) ;
145+ parametersSql = s_multipleSpaces . Replace ( parametersSql , " " ) ;
146146
147147 if ( string . IsNullOrWhiteSpace ( parametersSql ) )
148148 return new List < CachedParameter > ( ) ;
149149
150150 // strip precision specifier containing comma
151- parametersSql = Regex . Replace ( parametersSql , @"(DECIMAL|DEC|FIXED|NUMERIC|FLOAT|DOUBLE PRECISION|DOUBLE|REAL)\s*\([0-9]+(,\s*[0-9]+)\)" , @" $1", RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ;
151+ parametersSql = s_numericTypes . Replace ( parametersSql , @"$1" ) ;
152152
153153 // strip enum values containing commas (these would have been stripped by ParseDataType anyway)
154- parametersSql = Regex . Replace ( parametersSql , @ "ENUM\s*\([^)]+\)" , "ENUM" , RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ;
154+ parametersSql = s_enum . Replace ( parametersSql , "ENUM" ) ;
155155
156156 var parameters = parametersSql . Split ( ',' ) ;
157157 var cachedParameters = new List < CachedParameter > ( parameters . Length ) ;
@@ -176,7 +176,7 @@ internal static List<CachedParameter> ParseParameters(string parametersSql)
176176 parameter = parameter . Substring ( 3 ) ;
177177 }
178178
179- var parts = Regex . Match ( parameter , @"^(?:`((?:[\u0001-\u005F\u0061-\uFFFF]+|``)+)`|([A-Za-z0-9$_\u0080-\uFFFF]+)) (.*)$" ) ;
179+ var parts = s_parameterName . Match ( parameter ) ;
180180 var name = parts . Groups [ 1 ] . Success ? parts . Groups [ 1 ] . Value . Replace ( "``" , "`" ) : parts . Groups [ 2 ] . Value ;
181181
182182 var dataType = ParseDataType ( parts . Groups [ 3 ] . Value , out var unsigned , out var length ) ;
@@ -188,16 +188,16 @@ internal static List<CachedParameter> ParseParameters(string parametersSql)
188188
189189 internal static string ParseDataType ( string sql , out bool unsigned , out int length )
190190 {
191- sql = Regex . Replace ( sql , " (CHARSET|CHARACTER SET) [A-Za-z0-9_]+" , "" , RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ;
192- sql = Regex . Replace ( sql , " (COLLATE) [A-Za-z0-9_]+" , "" , RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ;
193- sql = Regex . Replace ( sql , @ "ENUM\s*\([^)]+\)" , "ENUM" , RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ;
191+ sql = s_characterSet . Replace ( sql , "" ) ;
192+ sql = s_collate . Replace ( sql , "" ) ;
193+ sql = s_enum . Replace ( sql , "ENUM" ) ;
194194
195195 length = 0 ;
196- var match = Regex . Match ( sql , @"\s*\(\s*([0-9]+)\s*(?:,\s*[0-9]+\s*)?\)" ) ;
196+ var match = s_length . Match ( sql ) ;
197197 if ( match . Success )
198198 {
199199 length = int . Parse ( match . Groups [ 1 ] . Value , CultureInfo . InvariantCulture ) ;
200- sql = Regex . Replace ( sql , @"\s*\(\s*[0-9]+\s*(?:,\s*[0-9]+\s*)?\)" , "" ) ;
200+ sql = s_length . Replace ( sql , "" ) ;
201201 }
202202
203203 var list = sql . Trim ( ) . Split ( new char [ ] { ' ' } ) ;
@@ -251,6 +251,16 @@ private static CachedParameter CreateCachedParameter(int ordinal, string? direct
251251 { "CHAR BYTE" , "BINARY" }
252252 } ;
253253
254+ static readonly Regex s_cStyleComments = new ( @"/\*.*?\*/" , RegexOptions . Singleline ) ;
255+ static readonly Regex s_singleLineComments = new ( @"(^|\s)--.*?$" , RegexOptions . Multiline ) ;
256+ static readonly Regex s_multipleSpaces = new ( @"\s+" ) ;
257+ static readonly Regex s_numericTypes = new ( @"(DECIMAL|DEC|FIXED|NUMERIC|FLOAT|DOUBLE PRECISION|DOUBLE|REAL)\s*\([0-9]+(,\s*[0-9]+)\)" , RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ;
258+ static readonly Regex s_enum = new ( @"ENUM\s*\([^)]+\)" , RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ;
259+ static readonly Regex s_parameterName = new ( @"^(?:`((?:[\u0001-\u005F\u0061-\uFFFF]+|``)+)`|([A-Za-z0-9$_\u0080-\uFFFF]+)) (.*)$" ) ;
260+ static readonly Regex s_characterSet = new ( " (CHARSET|CHARACTER SET) [A-Za-z0-9_]+" , RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ;
261+ static readonly Regex s_collate = new ( " (COLLATE) [A-Za-z0-9_]+" , RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ) ;
262+ static readonly Regex s_length = new ( @"\s*\(\s*([0-9]+)\s*(?:,\s*[0-9]+\s*)?\)" ) ;
263+
254264 readonly string m_schema ;
255265 readonly string m_component ;
256266}
0 commit comments