Skip to content

Commit fa85ec6

Browse files
committed
Move read-only Dictionary to a static field.
1 parent 07b149e commit fa85ec6

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

src/MySqlConnector/Core/CachedProcedure.cs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -206,30 +206,12 @@ internal static string ParseDataType(string sql, out bool unsigned, out int leng
206206
sql = Regex.Replace(sql, @"\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\)", "");
207207
}
208208

209-
var typeMapping = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
210-
{
211-
{"BOOL", "TINYINT"},
212-
{"BOOLEAN", "TINYINT"},
213-
{"INTEGER", "INT"},
214-
{"NUMERIC", "DECIMAL"},
215-
{"FIXED", "DECIMAL"},
216-
{"REAL", "DOUBLE"},
217-
{"DOUBLE PRECISION", "DOUBLE"},
218-
{"NVARCHAR", "VARCHAR"},
219-
{"CHARACTER VARYING", "VARCHAR"},
220-
{"NATIONAL VARCHAR", "VARCHAR"},
221-
{"NCHAR", "CHAR"},
222-
{"CHARACTER", "CHAR"},
223-
{"NATIONAL CHAR", "CHAR"},
224-
{"CHAR BYTE", "BINARY"}
225-
};
226-
227209
var list = sql.Trim().Split(new char[] {' '});
228210
var type = string.Empty;
229211

230-
if (list.Length < 2 || !typeMapping.TryGetValue(list[0] + ' ' + list[1], out type))
212+
if (list.Length < 2 || !s_typeMapping.TryGetValue(list[0] + ' ' + list[1], out type))
231213
{
232-
if (typeMapping.TryGetValue(list[0], out type))
214+
if (s_typeMapping.TryGetValue(list[0], out type))
233215
{
234216
if (list[0].StartsWith("BOOL", StringComparison.OrdinalIgnoreCase))
235217
{
@@ -257,6 +239,23 @@ private static CachedParameter CreateCachedParameter(int ordinal, string? direct
257239
string FullyQualified => $"`{m_schema}`.`{m_component}`";
258240

259241
static readonly IMySqlConnectorLogger Log = MySqlConnectorLogManager.CreateLogger(nameof(CachedProcedure));
242+
static readonly IReadOnlyDictionary<string, string> s_typeMapping = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
243+
{
244+
{ "BOOL", "TINYINT" },
245+
{ "BOOLEAN", "TINYINT" },
246+
{ "INTEGER", "INT" },
247+
{ "NUMERIC", "DECIMAL" },
248+
{ "FIXED", "DECIMAL" },
249+
{ "REAL", "DOUBLE" },
250+
{ "DOUBLE PRECISION", "DOUBLE" },
251+
{ "NVARCHAR", "VARCHAR" },
252+
{ "CHARACTER VARYING", "VARCHAR" },
253+
{ "NATIONAL VARCHAR", "VARCHAR" },
254+
{ "NCHAR", "CHAR" },
255+
{ "CHARACTER", "CHAR" },
256+
{ "NATIONAL CHAR", "CHAR" },
257+
{ "CHAR BYTE", "BINARY" }
258+
};
260259

261260
readonly string m_schema;
262261
readonly string m_component;

0 commit comments

Comments
 (0)