From 2230f06f13636e19c3d90cffc9f89c5ecec9232b Mon Sep 17 00:00:00 2001 From: Christopher Jolly Date: Mon, 25 Sep 2023 01:37:31 +0800 Subject: [PATCH] With InlineTopParameters it didn't handle the case of a sum of two constant valuees --- src/EFCore.Jet.Data/JetCommand.cs | 38 ++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/EFCore.Jet.Data/JetCommand.cs b/src/EFCore.Jet.Data/JetCommand.cs index 3047cb5..41add08 100644 --- a/src/EFCore.Jet.Data/JetCommand.cs +++ b/src/EFCore.Jet.Data/JetCommand.cs @@ -23,6 +23,7 @@ namespace EntityFrameworkCore.Jet.Data private static readonly Regex _createProcedureExpression = new Regex(@"^\s*create\s*procedure\b", RegexOptions.IgnoreCase); private static readonly Regex _topParameterRegularExpression = new Regex(@"(?<=(?:^|\s)select\s+top\s+)(?:@\w+|\?)(?=\s)", RegexOptions.IgnoreCase); private static readonly Regex _topMultiParameterRegularExpression = new Regex(@"(?<=(?:^|\s)select\s+top\s+)(?'first'@\w+|\?)(\s)(\+)(\s+)(?'sec'@\w+|\?)", RegexOptions.IgnoreCase); + private static readonly Regex _topMultiArgumentRegularExpression = new Regex(@"(?<=(?:^|\s)SELECT\s+TOP\s+)(?'first'\d+|\?)(\s)(\+)(\s+)(?'sec'\d+|\?)", RegexOptions.IgnoreCase); private static readonly Regex _outerSelectTopValueRegularExpression = new Regex(@"(?<=^\s*select\s+top\s+)\d+(?=\s)", RegexOptions.IgnoreCase); private static readonly Regex _outerSelectSkipValueOrParameterRegularExpression = new Regex(@"(?<=^\s*select)\s+skip\s+(?@\w+|\?|\d+)(?=\s)", RegexOptions.IgnoreCase); private static readonly Regex _selectRowCountRegularExpression = new Regex(@"^\s*select\s*@@rowcount\s*;?\s*$", RegexOptions.IgnoreCase); @@ -536,18 +537,19 @@ namespace EntityFrameworkCore.Jet.Data var lastCommandText = InnerCommand.CommandText; var commandText = lastCommandText; - var matchm = _topMultiParameterRegularExpression.Match(lastCommandText); - if (matchm.Success) + while ((commandText = _topMultiParameterRegularExpression.Replace( + lastCommandText, + match => + { + var first = match.Groups["first"]; + var sec = match.Groups["sec"]; + var sp = Convert.ToInt32(ExtractParameter(commandText, sec.Index, parameters).Value); + var fp = Convert.ToInt32(ExtractParameter(commandText, first.Index, parameters).Value); + var total = fp + sp; + return total.ToString(); + }, + 1)) != lastCommandText) { - var first = matchm.Groups["first"]; - var sec = matchm.Groups["sec"]; - var sp = Convert.ToInt32(ExtractParameter(commandText, sec.Index, parameters).Value); - var fp = Convert.ToInt32(ExtractParameter(commandText, first.Index, parameters).Value); - var total = fp + sp; - commandText = _topMultiParameterRegularExpression.Replace( - lastCommandText, - match => total.ToString(), - 1); lastCommandText = commandText; } @@ -562,6 +564,20 @@ namespace EntityFrameworkCore.Jet.Data lastCommandText = commandText; } + while ((commandText = _topMultiArgumentRegularExpression.Replace( + lastCommandText, + match => + { + var first = match.Groups["first"]; + var sec = match.Groups["sec"]; + return (Convert.ToInt32(first.Value) + Convert.ToInt32(sec.Value)).ToString(); + }, + 1)) != lastCommandText) + { + lastCommandText = commandText; + } + + InnerCommand.CommandText = commandText; InnerCommand.Parameters.Clear();