Skip to content

Commit b363c60

Browse files
committed
feat(parser): replace SelectFinder with SimpleSelectFinder
Refactor SQL command parsing to improve performance and maintainability. The new implementation utilizes a regex for simple SELECT statements and a dedicated visitor class for parsing. - Added a using directive for `Microsoft.SqlServer.Management.SqlParser.Parser` in `Command.cs`. - Introduced a private static readonly regex `SimpleSelectRegex` in `Command.cs`. - Removed the previous implementation of `SimpleSelectRegex`. - Updated `Command.cs` to use `SimpleSelectFinder` for SQL command parsing. - Removed the `SelectFinder` class from `SelectFinder.cs`. - Added `SimpleSelectFinder` class in `SimpleSelectFinder.cs` with visit methods for various SQL code objects. - Updated `SQLHelper.DB.csproj` to remove the `SQLParser` package reference.
1 parent 7ed91e2 commit b363c60

File tree

5 files changed

+1486
-106
lines changed

5 files changed

+1486
-106
lines changed

SQLHelper.SpeedTests/Tests/AltImplementations/HelperClasses/Command.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

1717
using BigBook;
18+
using Microsoft.SqlServer.Management.SqlParser.Parser;
1819
using SQLHelperDBTests.HelperClasses.Interfaces;
1920
using System;
2021
using System.Collections.Generic;
@@ -91,6 +92,11 @@ public Command(Action<ICommand, List<dynamic>, TCallbackData> callBack, TCallbac
9192
Header = header;
9293
}
9394

95+
/// <summary>
96+
/// The simple select regex
97+
/// </summary>
98+
private static readonly Regex SimpleSelectRegex = new Regex(@"^SELECT\s|\sSELECT\s", RegexOptions.IgnoreCase | RegexOptions.Compiled);
99+
94100
/// <summary>
95101
/// Call back
96102
/// </summary>
@@ -135,11 +141,6 @@ public Command(Action<ICommand, List<dynamic>, TCallbackData> callBack, TCallbac
135141
/// <value><c>true</c> if [transaction needed]; otherwise, <c>false</c>.</value>
136142
public bool TransactionNeeded { get; set; }
137143

138-
/// <summary>
139-
/// The simple select regex
140-
/// </summary>
141-
private static readonly Regex SimpleSelectRegex = new Regex(@"^SELECT\s|\sSELECT\s", RegexOptions.IgnoreCase | RegexOptions.Compiled);
142-
143144
/// <summary>
144145
/// Determines if the objects are equal
145146
/// </summary>
@@ -239,8 +240,9 @@ private void DetermineFinalizable(string parameterStarter, string ComparisonStri
239240

240241
if (parameterStarter == "@" && ComparisonSpan.Contains("SELECT ", StringComparison.Ordinal) && ComparisonSpan.Contains("IF ", StringComparison.Ordinal))
241242
{
242-
var TempParser = new SelectFinder();
243-
SQLParser.Parser.Parse(SQLCommand, TempParser, SQLParser.Enums.SQLType.TSql);
243+
var TempParser = new SimpleSelectFinder();
244+
ParseResult Results = Parser.Parse(SQLCommand);
245+
Results.Script.Accept(TempParser);
244246
Finalizable = TempParser.StatementFound;
245247
}
246248
else

SQLHelper.SpeedTests/Tests/AltImplementations/HelperClasses/SelectFinder.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)