Skip to content

Commit 24e53cd

Browse files
committed
Support SET parameter type. Fixes #1491
1 parent 20c39aa commit 24e53cd

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/MySqlConnector/Core/CachedProcedure.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ internal static List<CachedParameter> ParseParameters(string parametersSql)
153153
return [];
154154

155155
// strip precision specifier containing comma
156-
parametersSql = s_numericTypes.Replace(parametersSql, @"$1");
156+
parametersSql = s_numericTypes.Replace(parametersSql, "$1");
157157

158158
// strip enum values containing commas (these would have been stripped by ParseDataType anyway)
159-
parametersSql = s_enum.Replace(parametersSql, "ENUM");
159+
parametersSql = s_enumOrSet.Replace(parametersSql, "$1");
160160

161161
var parameters = parametersSql.Split(',');
162162
var cachedParameters = new List<CachedParameter>(parameters.Length);
@@ -195,7 +195,7 @@ internal static string ParseDataType(string sql, out bool unsigned, out int leng
195195
{
196196
sql = s_characterSet.Replace(sql, "");
197197
sql = s_collate.Replace(sql, "");
198-
sql = s_enum.Replace(sql, "ENUM");
198+
sql = s_enumOrSet.Replace(sql, "$1");
199199

200200
length = 0;
201201
var match = s_length.Match(sql);
@@ -260,7 +260,7 @@ private static CachedParameter CreateCachedParameter(int ordinal, string? direct
260260
private static readonly Regex s_singleLineComments = new(@"(^|\s)--.*?$", RegexOptions.Multiline);
261261
private static readonly Regex s_multipleSpaces = new(@"\s+");
262262
private 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);
263-
private static readonly Regex s_enum = new(@"ENUM\s*\([^)]+\)", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
263+
private static readonly Regex s_enumOrSet = new(@"(ENUM|SET)\s*\([^)]+\)", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
264264
private static readonly Regex s_parameterName = new(@"^(?:`((?:[\u0001-\u005F\u0061-\uFFFF]+|``)+)`|([A-Za-z0-9$_\u0080-\uFFFF]+)) (.*)$");
265265
private static readonly Regex s_characterSet = new(" (CHARSET|CHARACTER SET) [A-Za-z0-9_]+", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
266266
private static readonly Regex s_collate = new(" (COLLATE) [A-Za-z0-9_]+", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

tests/MySqlConnector.Tests/CachedProcedureTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ public static IEnumerable<object[]> CreateParseableParameters()
121121
new CachedParameter(1, "INOUT", "param", "LONGTEXT", false, 0),
122122
}
123123
],
124+
[
125+
"ColSet set('set1','set2','set3')", new object[]
126+
{
127+
new CachedParameter(1, "IN", "ColSet", "SET", false, 0),
128+
}
129+
],
124130
[
125131
@"IN param1 DATETIME(6),
126132
-- ignored1
@@ -189,6 +195,7 @@ param4 INTEGER(3)
189195
[InlineData("NUMERIC(12)", "DECIMAL", false, 12)]
190196
[InlineData("FIXED(12)", "DECIMAL", false, 12)]
191197
[InlineData("ENUM('a','b','c')", "ENUM", false, 0)]
198+
[InlineData("SET('a','b','c')", "SET", false, 0)]
192199
public void ParseDataType(string sql, string expectedDataType, bool expectedUnsigned, int expectedLength)
193200
{
194201
var dataType = CachedProcedure.ParseDataType(sql, out var unsigned, out var length);

0 commit comments

Comments
 (0)