diff --git a/build/version.props b/build/version.props index 49b413a1..b03539df 100644 --- a/build/version.props +++ b/build/version.props @@ -2,7 +2,7 @@ 4 1 - 63 + 64 $(VersionMajor).$(VersionMinor).$(VersionPatch) diff --git a/src/SmartSql.Test.Unit/Tags/SqlTextTest.cs b/src/SmartSql.Test.Unit/Tags/SqlTextTest.cs new file mode 100644 index 00000000..ffd3f9bb --- /dev/null +++ b/src/SmartSql.Test.Unit/Tags/SqlTextTest.cs @@ -0,0 +1,52 @@ +using SmartSql.Configuration.Tags; +using Xunit; + +namespace SmartSql.Test.Unit.Tags; + +public class SqlTextTest +{ + [Fact] + public void BuildSql() + { + var expected = "id=?id"; + SqlText sqlText = new SqlText(expected, "?"); + RequestContext requestContext = new RequestContext(); + sqlText.BuildSql(requestContext); + var actual = requestContext.SqlBuilder.ToString(); + Assert.Equal(expected, actual); + } + + [Fact] + public void BuildSqlWithIn() + { + SqlText sqlText = new SqlText("in ?Ids", "?"); + RequestContext requestContext = new RequestContext() + { + Request = new + { + Ids = new[] { 1, 2 } + } + }; + requestContext.SetupParameters(); + sqlText.BuildSql(requestContext); + var actual = requestContext.SqlBuilder.ToString(); + Assert.Equal("In (?Ids_0,?Ids_1)", actual); + } + + [Fact] + public void BuildSqlWithInAndSemicolon() + { + SqlText sqlText = new SqlText("in ?Ids;", "?"); + RequestContext requestContext = new RequestContext() + { + Request = new + { + Ids = new[] { 1, 2 } + } + }; + requestContext.SetupParameters(); + sqlText.BuildSql(requestContext); + var actual = requestContext.SqlBuilder.ToString(); + Assert.Equal("In (?Ids_0,?Ids_1);", actual); + } +} \ No newline at end of file diff --git a/src/SmartSql/Configuration/Tags/SqlText.cs b/src/SmartSql/Configuration/Tags/SqlText.cs index b71f1ec7..60a139a1 100644 --- a/src/SmartSql/Configuration/Tags/SqlText.cs +++ b/src/SmartSql/Configuration/Tags/SqlText.cs @@ -17,7 +17,7 @@ public SqlText(string bodyText, string dbPrefix) { BodyText = bodyText; _dbPrefix = dbPrefix; - _sqlInParamsTokens = new Regex(@"in\s*[" + dbPrefix + @"]([\S_.]+)", RegexOptions.IgnoreCase); + _sqlInParamsTokens = new Regex(@"in\s*[" + dbPrefix + @"]([\p{L}\p{N}_.]+)", RegexOptions.IgnoreCase); _hasInSyntax = _sqlInParamsTokens.IsMatch(bodyText); }