mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-15 17:23:32 -05:00
port batch parser wrapper (#232)
* Initial commit for GitHub IO pages * Add initial doxfx content * Update manifest.json * Update manifest.json * Set theme jekyll-theme-cayman * Set theme jekyll-theme-slate * Set theme jekyll-theme-minimal * Set theme jekyll-theme-tactile * Clear out theme setting * Remove API docs * Revert "Adding Milliseconds to DateTime fields (#173)" (#197) This reverts commit431dfa4156. * ported new BatchParser * added BatchParser tests * fixing merge conflicts * fix build issues * cleaned code and addressed comments from code review * addressed code review and made BatchParser logic more efficient * fixed batch parser tests * changed class name to fix build issues * fixed merge conflicts * added path for lab mode baseline tests * changed env path for lab mode * added env variable to appveyor * testing env variable for appveyor * fixed lab build * debug appveyor build * testing changes for appveyor * changed trace env path * debugging appveyor build * changed baseline env path * debugging * debugging * debugging * switched on trace flag * debugging * debugging * changed build config * changed baseline files * checking baseline output * changed baseline files * debug baseline tests * debugging baseline * debugging * debugging * debug * debugging * testing baseline format * debug * debug * debug * debug * debug * newline debug * changed baseline file * debug * test * try new way to read * added execution engine tests * change test * testing file encoding * moved execution engine tests to integration * try compare without spaces * removed no op test * added env variable for travis * put batch parser tests to integration too * put batch parser in integration * try new baseline string match * compare baseline test logic changed * changed baseline logic as well as cleaned tests * fix build for travis CI * fix travis CI issues * fixed highlighting bugs on vscode * code review changes * ported new BatchParser * added BatchParser tests * Initial commit for GitHub IO pages * Add initial doxfx content * Update manifest.json * Update manifest.json * Set theme jekyll-theme-cayman * Set theme jekyll-theme-slate * Set theme jekyll-theme-minimal * Set theme jekyll-theme-tactile * Clear out theme setting * Remove API docs * Revert "Adding Milliseconds to DateTime fields (#173)" (#197) This reverts commit431dfa4156. * fixing merge conflicts * fix build issues * cleaned code and addressed comments from code review * addressed code review and made BatchParser logic more efficient * fixed batch parser tests * changed class name to fix build issues * fixed merge conflicts * added path for lab mode baseline tests changed env path for lab mode added env variable to appveyor testing env variable for appveyor fixed lab build debug appveyor build testing changes for appveyor changed trace env path debugging appveyor build changed baseline env path debugging debugging debugging switched on trace flag debugging debugging changed build config changed baseline files checking baseline output changed baseline files debug baseline tests debugging baseline debugging debugging debug debugging testing baseline format debug debug debug debug debug newline debug changed baseline file debug test try new way to read added execution engine tests change test testing file encoding moved execution engine tests to integration try compare without spaces removed no op test added env variable for travis * put batch parser tests to integration too * put batch parser in integration try new baseline string match * compare baseline test logic changed * changed baseline logic as well as cleaned tests * fix build for travis CI * fix travis CI issues * fixed highlighting bugs on vscode * code review changes * fixed filestream writer test * added localization string * added localization string * generated new string files again * code review changes
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
@@ -487,7 +487,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
if (se != null)
|
||||
{
|
||||
var errors = se.Errors.Cast<SqlError>().ToList();
|
||||
|
||||
|
||||
// Detect user cancellation errors
|
||||
if (errors.Any(error => error.Class == 11 && error.Number == 0))
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
{
|
||||
/// <summary>
|
||||
@@ -16,6 +17,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
{
|
||||
int WriteRow(StorageDataReader dataReader);
|
||||
void WriteRow(IList<DbCellValue> row, IList<DbColumnWrapper> columns);
|
||||
|
||||
void FlushBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
/// <param name="fileName">Path to the file to delete</param>
|
||||
public void DisposeFile(string fileName)
|
||||
{
|
||||
FileUtils.SafeFileDelete(fileName);
|
||||
FileUtilities.SafeFileDelete(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
/// <param name="fileName">Path to the file to delete</param>
|
||||
public void DisposeFile(string fileName)
|
||||
{
|
||||
FileUtils.SafeFileDelete(fileName);
|
||||
FileUtilities.SafeFileDelete(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
/// <param name="fileName">The file to dispose of</param>
|
||||
public void DisposeFile(string fileName)
|
||||
{
|
||||
FileUtils.SafeFileDelete(fileName);
|
||||
FileUtilities.SafeFileDelete(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,6 +324,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
{
|
||||
long ticks = BitConverter.ToInt64(buffer, 0);
|
||||
return new DateTime(ticks);
|
||||
|
||||
}, null, dt =>
|
||||
{
|
||||
// Switch based on the type of column
|
||||
@@ -354,6 +355,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
}
|
||||
|
||||
return dt.ToString(formatString);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
internal int WriteNull()
|
||||
{
|
||||
byteBuffer[0] = 0x00;
|
||||
return FileUtils.WriteWithLength(fileStream, byteBuffer, 1);
|
||||
return FileUtilities.WriteWithLength(fileStream, byteBuffer, 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -244,7 +244,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
byteBuffer[0] = 0x02; // length
|
||||
shortBuffer[0] = val;
|
||||
Buffer.BlockCopy(shortBuffer, 0, byteBuffer, 1, 2);
|
||||
return FileUtils.WriteWithLength(fileStream, byteBuffer, 3);
|
||||
return FileUtilities.WriteWithLength(fileStream, byteBuffer, 3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -256,7 +256,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
byteBuffer[0] = 0x04; // length
|
||||
intBuffer[0] = val;
|
||||
Buffer.BlockCopy(intBuffer, 0, byteBuffer, 1, 4);
|
||||
return FileUtils.WriteWithLength(fileStream, byteBuffer, 5);
|
||||
return FileUtilities.WriteWithLength(fileStream, byteBuffer, 5);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -268,7 +268,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
byteBuffer[0] = 0x08; // length
|
||||
longBuffer[0] = val;
|
||||
Buffer.BlockCopy(longBuffer, 0, byteBuffer, 1, 8);
|
||||
return FileUtils.WriteWithLength(fileStream, byteBuffer, 9);
|
||||
return FileUtilities.WriteWithLength(fileStream, byteBuffer, 9);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -280,7 +280,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
byteBuffer[0] = 0x02; // length
|
||||
charBuffer[0] = val;
|
||||
Buffer.BlockCopy(charBuffer, 0, byteBuffer, 1, 2);
|
||||
return FileUtils.WriteWithLength(fileStream, byteBuffer, 3);
|
||||
return FileUtilities.WriteWithLength(fileStream, byteBuffer, 3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -291,7 +291,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
{
|
||||
byteBuffer[0] = 0x01; // length
|
||||
byteBuffer[1] = (byte) (val ? 0x01 : 0x00);
|
||||
return FileUtils.WriteWithLength(fileStream, byteBuffer, 2);
|
||||
return FileUtilities.WriteWithLength(fileStream, byteBuffer, 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -302,7 +302,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
{
|
||||
byteBuffer[0] = 0x01; // length
|
||||
byteBuffer[1] = val;
|
||||
return FileUtils.WriteWithLength(fileStream, byteBuffer, 2);
|
||||
return FileUtilities.WriteWithLength(fileStream, byteBuffer, 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -314,7 +314,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
byteBuffer[0] = 0x04; // length
|
||||
floatBuffer[0] = val;
|
||||
Buffer.BlockCopy(floatBuffer, 0, byteBuffer, 1, 4);
|
||||
return FileUtils.WriteWithLength(fileStream, byteBuffer, 5);
|
||||
return FileUtilities.WriteWithLength(fileStream, byteBuffer, 5);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -326,7 +326,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
byteBuffer[0] = 0x08; // length
|
||||
doubleBuffer[0] = val;
|
||||
Buffer.BlockCopy(doubleBuffer, 0, byteBuffer, 1, 8);
|
||||
return FileUtils.WriteWithLength(fileStream, byteBuffer, 9);
|
||||
return FileUtilities.WriteWithLength(fileStream, byteBuffer, 9);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -350,7 +350,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
|
||||
// data value
|
||||
Buffer.BlockCopy(arrInt32, 0, byteBuffer, 3, iLen - 3);
|
||||
iTotalLen += FileUtils.WriteWithLength(fileStream, byteBuffer, iLen);
|
||||
iTotalLen += FileUtilities.WriteWithLength(fileStream, byteBuffer, iLen);
|
||||
return iTotalLen; // len+data
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
int iTotalLen = WriteLength(iLen); // length
|
||||
|
||||
Buffer.BlockCopy(arrInt32, 0, byteBuffer, 0, iLen);
|
||||
iTotalLen += FileUtils.WriteWithLength(fileStream, byteBuffer, iLen);
|
||||
iTotalLen += FileUtilities.WriteWithLength(fileStream, byteBuffer, iLen);
|
||||
|
||||
return iTotalLen; // len+data
|
||||
}
|
||||
@@ -394,7 +394,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
longBufferOffset[0] = dtoVal.Ticks;
|
||||
longBufferOffset[1] = dtoVal.Offset.Ticks;
|
||||
Buffer.BlockCopy(longBufferOffset, 0, byteBuffer, 1, 16);
|
||||
return FileUtils.WriteWithLength(fileStream, byteBuffer, 17);
|
||||
return FileUtilities.WriteWithLength(fileStream, byteBuffer, 17);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -426,7 +426,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
byteBuffer[3] = 0x00;
|
||||
byteBuffer[4] = 0x00;
|
||||
|
||||
iTotalLen = FileUtils.WriteWithLength(fileStream, byteBuffer, 5);
|
||||
iTotalLen = FileUtilities.WriteWithLength(fileStream, byteBuffer, 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -435,7 +435,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
|
||||
// convert char array into byte array and write it out
|
||||
iTotalLen = WriteLength(bytes.Length);
|
||||
iTotalLen += FileUtils.WriteWithLength(fileStream, bytes, bytes.Length);
|
||||
iTotalLen += FileUtilities.WriteWithLength(fileStream, bytes, bytes.Length);
|
||||
}
|
||||
return iTotalLen; // len+data
|
||||
}
|
||||
@@ -458,12 +458,12 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
byteBuffer[3] = 0x00;
|
||||
byteBuffer[4] = 0x00;
|
||||
|
||||
iTotalLen = FileUtils.WriteWithLength(fileStream, byteBuffer, 5);
|
||||
iTotalLen = FileUtilities.WriteWithLength(fileStream, byteBuffer, 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
iTotalLen = WriteLength(bytesVal.Length);
|
||||
iTotalLen += FileUtils.WriteWithLength(fileStream, bytesVal, bytesVal.Length);
|
||||
iTotalLen += FileUtilities.WriteWithLength(fileStream, bytesVal, bytesVal.Length);
|
||||
}
|
||||
return iTotalLen; // len+data
|
||||
}
|
||||
@@ -515,7 +515,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
int iTmp = iLen & 0x000000FF;
|
||||
|
||||
byteBuffer[0] = Convert.ToByte(iTmp);
|
||||
return FileUtils.WriteWithLength(fileStream, byteBuffer, 1);
|
||||
return FileUtilities.WriteWithLength(fileStream, byteBuffer, 1);
|
||||
}
|
||||
// The length won't fit in 1 byte, so we need to use 1 byte to signify that the length
|
||||
// is a full 4 bytes.
|
||||
@@ -524,7 +524,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
// convert int32 into array of bytes
|
||||
intBuffer[0] = iLen;
|
||||
Buffer.BlockCopy(intBuffer, 0, byteBuffer, 1, 4);
|
||||
return FileUtils.WriteWithLength(fileStream, byteBuffer, 5);
|
||||
return FileUtilities.WriteWithLength(fileStream, byteBuffer, 5);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -8,14 +8,14 @@ using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlServer.Management.SqlParser.Parser;
|
||||
using Microsoft.SqlTools.ServiceLayer.BatchParser;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
@@ -112,23 +112,20 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
querySettings = settings;
|
||||
streamOutputFactory = outputFactory;
|
||||
|
||||
// Process the query into batches
|
||||
ParseResult parseResult = Parser.Parse(queryText, new ParseOptions
|
||||
{
|
||||
BatchSeparator = settings.BatchSeparator
|
||||
});
|
||||
// NOTE: We only want to process batches that have statements (ie, ignore comments and empty lines)
|
||||
var batchSelection = parseResult.Script.Batches
|
||||
.Where(batch => batch.Statements.Count > 0)
|
||||
.Select((batch, index) =>
|
||||
new Batch(batch.Sql,
|
||||
// Process the query into batches
|
||||
BatchParserWrapper parser = new BatchParserWrapper();
|
||||
List<BatchDefinition> parserResult = parser.GetBatches(queryText);
|
||||
|
||||
var batchSelection = parserResult
|
||||
.Select((batchDefinition, index) =>
|
||||
new Batch(batchDefinition.BatchText,
|
||||
new SelectionData(
|
||||
batch.StartLocation.LineNumber - 1,
|
||||
batch.StartLocation.ColumnNumber - 1,
|
||||
batch.EndLocation.LineNumber - 1,
|
||||
batch.EndLocation.ColumnNumber - 1),
|
||||
batchDefinition.StartLine-1,
|
||||
batchDefinition.StartColumn-1,
|
||||
batchDefinition.EndLine-1,
|
||||
batchDefinition.EndColumn-1),
|
||||
index, outputFactory));
|
||||
|
||||
|
||||
Batches = batchSelection.ToArray();
|
||||
|
||||
// Create our batch lists
|
||||
|
||||
Reference in New Issue
Block a user