microsoft / microsoft/sqlmanagementobjects
API to parse/split GO statements into batches
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 143
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
Description
Per comment on another issue I am opening this to ask for an API in similar effect to this wrapped function:
/// <summary>
/// Split/Parse a TSQL string into batches by the "GO" statement.
/// Mirrors SQL Management Studio's parsing (because it is the same)
/// </summary>
public static List<string> ParseSQLBatches(string tsql)
{
var batchParser = new Microsoft.SqlServer.Management.Common.ExecuteBatch();
var ret = batchParser.GetStatements(tsql);
return ret.Cast<string>().ToList();
}
The reasoning behind this is that we have scripts written by us for schema/data migrations that commonly utilize GO statements in many ways. We can't easily rely on a simplified "Split on bare GO statements outside of comments" due to sometimes having GO 20 or other such fun things, or multi-line strings etc that might have GO in them for unrelated reasons. Although we could write a parser, that SMO provided one that out of the box (as far as we noticed) was identical to SSMS's was very convenient for us. It seems that this exposed class/api that we were relying on was an implementation detail/surface that is going away in an upcoming release. So the ask here is to facilitate at least this minimal API of "given TSQL string, here it is split-and-duplicated-etc into individual batches".
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing Microsoft.SqlServer.Management.Common.ExecuteBatch and GetStatements usage described in the issue, along with the linked discussion in issue 4. Define the supported public API for splitting T-SQL into batches, including GO 20, comments, and multiline strings, then verify that its results match the expected SQL Management Studio behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- api, databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100