mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-18 17:23:52 -05:00
Feature/sqlcmd : Enable running scripts with SQLCMD variables - Part 1 (#839)
* Part1 : Changes to make cmdcmd script to work with parameters in script * Stop SQL intellisense for SQLCMD * Adding test for Intellisense handling of SQLCMD page * Removing unintentional spacing changes caused by formatting * Updating with smaller CR comments. Will discuss regarding script vs other options in batch info * Removing unintentional change * Adding latest PR comments
This commit is contained in:
@@ -51,7 +51,7 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser
|
||||
int offset = offsets[0];
|
||||
int startColumn = batchInfos[0].startColumn;
|
||||
int count = batchInfos.Count;
|
||||
string batchText = content.Substring(offset, batchInfos[0].length);
|
||||
string batchText = batchInfos[0].batchText;
|
||||
|
||||
// if there's only one batch then the line difference is just startLine
|
||||
if (count > 1)
|
||||
@@ -82,15 +82,15 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser
|
||||
}
|
||||
|
||||
// Generate the rest batch definitions
|
||||
for (int index = 1; index < count - 1; index++)
|
||||
for (int index = 1; index < count - 1 ; index++)
|
||||
{
|
||||
lineDifference = batchInfos[index + 1].startLine - batchInfos[index].startLine;
|
||||
position = ReadLines(reader, lineDifference, endLine);
|
||||
endLine = position.Item1;
|
||||
endColumn = position.Item2;
|
||||
offset = offsets[index];
|
||||
batchText = content.Substring(offset, batchInfos[index].length);
|
||||
startLine = batchInfos[index].startLine;
|
||||
batchText = batchInfos[index].batchText;
|
||||
startLine = batchInfos[index].startLine + 1; //positions is 0 index based
|
||||
startColumn = batchInfos[index].startColumn;
|
||||
|
||||
// make a new batch definition for each batch
|
||||
@@ -109,7 +109,7 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser
|
||||
if (count > 1)
|
||||
{
|
||||
|
||||
batchText = content.Substring(offsets[count-1], batchInfos[count - 1].length);
|
||||
batchText = batchInfos[count - 1].batchText;
|
||||
BatchDefinition lastBatchDef = GetLastBatchDefinition(reader, batchInfos[count - 1], batchText);
|
||||
batchDefinitionList.Add(lastBatchDef);
|
||||
}
|
||||
@@ -209,7 +209,7 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser
|
||||
private static BatchDefinition GetLastBatchDefinition(StringReader reader,
|
||||
BatchInfo batchInfo, string batchText)
|
||||
{
|
||||
int startLine = batchInfo.startLine;
|
||||
int startLine = batchInfo.startLine + 1;
|
||||
int startColumn = batchInfo.startColumn;
|
||||
string prevLine = null;
|
||||
string line = reader.ReadLine();
|
||||
@@ -328,12 +328,12 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser
|
||||
/// <summary>
|
||||
/// Takes in a query string and returns a list of BatchDefinitions
|
||||
/// </summary>
|
||||
public List<BatchDefinition> GetBatches(string sqlScript)
|
||||
public List<BatchDefinition> GetBatches(string sqlScript, ExecutionEngineConditions conditions = null)
|
||||
{
|
||||
batchInfos = new List<BatchInfo>();
|
||||
|
||||
// execute the script - all communication / integration after here happen via event handlers
|
||||
executionEngine.ParseScript(sqlScript, notificationHandler);
|
||||
executionEngine.ParseScript(sqlScript, notificationHandler, conditions);
|
||||
|
||||
// retrieve a list of BatchDefinitions
|
||||
List<BatchDefinition> batchDefinitionList = ConvertToBatchDefinitionList(sqlScript, batchInfos);
|
||||
@@ -381,7 +381,7 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser
|
||||
}
|
||||
|
||||
// Add the script info
|
||||
batchInfos.Add(new BatchInfo(args.Batch.TextSpan.iStartLine, args.Batch.TextSpan.iStartIndex, batchTextLength, args.Batch.ExpectedExecutionCount));
|
||||
batchInfos.Add(new BatchInfo(args.Batch.TextSpan.iStartLine, args.Batch.TextSpan.iStartIndex, batchText, args.Batch.ExpectedExecutionCount));
|
||||
}
|
||||
}
|
||||
catch (NotImplementedException)
|
||||
@@ -474,17 +474,17 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser
|
||||
|
||||
private class BatchInfo
|
||||
{
|
||||
public BatchInfo(int startLine, int startColumn, int length, int repeatCount = 1)
|
||||
public BatchInfo(int startLine, int startColumn, string batchText, int repeatCount = 1)
|
||||
{
|
||||
this.startLine = startLine;
|
||||
this.startColumn = startColumn;
|
||||
this.length = length;
|
||||
this.executionCount = repeatCount;
|
||||
this.batchText = batchText;
|
||||
}
|
||||
public int startLine;
|
||||
public int startColumn;
|
||||
public int length;
|
||||
public int executionCount;
|
||||
public string batchText;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode
|
||||
batchParser.HaltParser = new BatchParser.HaltParserDelegate(OnHaltParser);
|
||||
batchParser.StartingLine = startingLine;
|
||||
|
||||
if (isLocalParse)
|
||||
if (isLocalParse && !sqlCmdMode)
|
||||
{
|
||||
batchParser.DisableVariableSubstitution();
|
||||
}
|
||||
@@ -1045,23 +1045,27 @@ namespace Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode
|
||||
/// Parses the script locally
|
||||
/// </summary>
|
||||
/// <param name="script">script to parse</param>
|
||||
/// <param name="batchEventsHandler">batch handler</param>
|
||||
/// <param name="batchEventsHandler">batch handler</param>
|
||||
/// <param name="conditions">execution engine conditions if specified</param>
|
||||
/// <remarks>
|
||||
/// The batch parser functionality is used in this case
|
||||
/// </remarks>
|
||||
public void ParseScript(string script, IBatchEventsHandler batchEventsHandler)
|
||||
public void ParseScript(string script, IBatchEventsHandler batchEventsHandler, ExecutionEngineConditions conditions = null)
|
||||
{
|
||||
Validate.IsNotNull(nameof(script), script);
|
||||
Validate.IsNotNull(nameof(batchEventsHandler), batchEventsHandler);
|
||||
|
||||
|
||||
if (conditions != null)
|
||||
{
|
||||
this.conditions = conditions;
|
||||
}
|
||||
this.script = script;
|
||||
batchEventHandlers = batchEventsHandler;
|
||||
isLocalParse = true;
|
||||
|
||||
DoExecute(/* isBatchParser */ true);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Close the current connection
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user