Skip to content

Commit f9bd30f

Browse files
committed
Simplify the string_split implementation
1 parent c6d4379 commit f9bd30f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Dapper/SqlMapper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,13 +1990,13 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj
19901990
private static bool TryStringSplit(ref IEnumerable list, int splitAt, string namePrefix, IDbCommand command)
19911991
{
19921992
if (list == null || splitAt < 0) return false;
1993-
if (list is IEnumerable<int>) return TryStringSplit<int>(ref list, splitAt, namePrefix, command, "int not null",
1993+
if (list is IEnumerable<int>) return TryStringSplit<int>(ref list, splitAt, namePrefix, command, "int",
19941994
(sb, i) => sb.Append(i.ToString(CultureInfo.InvariantCulture)));
1995-
if (list is IEnumerable<long>) return TryStringSplit<long>(ref list, splitAt, namePrefix, command, "bigint not null",
1995+
if (list is IEnumerable<long>) return TryStringSplit<long>(ref list, splitAt, namePrefix, command, "bigint",
19961996
(sb, i) => sb.Append(i.ToString(CultureInfo.InvariantCulture)));
1997-
if (list is IEnumerable<short>) return TryStringSplit<short>(ref list, splitAt, namePrefix, command, "smallint not null",
1997+
if (list is IEnumerable<short>) return TryStringSplit<short>(ref list, splitAt, namePrefix, command, "smallint",
19981998
(sb, i) => sb.Append(i.ToString(CultureInfo.InvariantCulture)));
1999-
if (list is IEnumerable<byte>) return TryStringSplit<byte>(ref list, splitAt, namePrefix, command, "tinyint not null",
1999+
if (list is IEnumerable<byte>) return TryStringSplit<byte>(ref list, splitAt, namePrefix, command, "tinyint",
20002000
(sb, i) => sb.Append(i.ToString(CultureInfo.InvariantCulture)));
20012001
return false;
20022002
}
@@ -2024,12 +2024,12 @@ private static bool TryStringSplit<T>(ref IEnumerable list, int splitAt, string
20242024
else
20252025
{
20262026
varName = variableName;
2027-
return "(select val from " + variableName + "_TSS)";
2027+
return "(select cast([value] as " + colType + ") from string_split(" + variableName + ",','))";
20282028
}
20292029
}, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.CultureInvariant);
20302030
if (varName == null) return false; // couldn't resolve the var!
20312031

2032-
command.CommandText = "declare " + varName + "_TSS table(val " + colType + ");insert " + varName + "_TSS (val) select value from string_split(" + varName + ",',');" + sql;
2032+
command.CommandText = sql;
20332033
var concatenatedParam = command.CreateParameter();
20342034
concatenatedParam.ParameterName = namePrefix;
20352035
concatenatedParam.DbType = DbType.AnsiString;

0 commit comments

Comments
 (0)