mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Make sample work with current code (#707)
This commit is contained in:
@@ -14,7 +14,7 @@ using Microsoft.SqlTools.Hosting.Protocol.Channel;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||||
namespace Microsoft.SqlTools.JsonRpc.Driver
|
namespace Microsoft.SqlTools.JsonRpc.Driver
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -59,6 +59,7 @@ namespace Microsoft.SqlTools.JsonRpc.Driver
|
|||||||
startTime = DateTime.Now;
|
startTime = DateTime.Now;
|
||||||
|
|
||||||
// Launch the process
|
// Launch the process
|
||||||
|
this.protocolClient.Initialize();
|
||||||
await this.protocolClient.Start();
|
await this.protocolClient.Start();
|
||||||
await Task.Delay(1000); // Wait for the service host to start
|
await Task.Delay(1000); // Wait for the service host to start
|
||||||
|
|
||||||
@@ -67,7 +68,7 @@ namespace Microsoft.SqlTools.JsonRpc.Driver
|
|||||||
// Setup events to queue for testing
|
// Setup events to queue for testing
|
||||||
this.QueueEventsForType(ConnectionCompleteNotification.Type);
|
this.QueueEventsForType(ConnectionCompleteNotification.Type);
|
||||||
this.QueueEventsForType(IntelliSenseReadyNotification.Type);
|
this.QueueEventsForType(IntelliSenseReadyNotification.Type);
|
||||||
this.QueueEventsForType(QueryExecuteCompleteEvent.Type);
|
this.QueueEventsForType(QueryCompleteEvent.Type);
|
||||||
this.QueueEventsForType(PublishDiagnosticsNotification.Type);
|
this.QueueEventsForType(PublishDiagnosticsNotification.Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.SqlTools.JsonRpc.Utility;
|
using Microsoft.SqlTools.JsonRpc.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.JsonRpc.ExecuteQuery
|
namespace Microsoft.SqlTools.JsonRpc.ExecuteQuery
|
||||||
{
|
{
|
||||||
@@ -19,10 +20,11 @@ namespace Microsoft.SqlTools.JsonRpc.ExecuteQuery
|
|||||||
internal static void Main(string[] args)
|
internal static void Main(string[] args)
|
||||||
{
|
{
|
||||||
// set SQLTOOLSSERVICE_EXE to location of SQL Tools Service executable
|
// set SQLTOOLSSERVICE_EXE to location of SQL Tools Service executable
|
||||||
Environment.SetEnvironmentVariable("SQLTOOLSSERVICE_EXE", @"Microsoft.SqlTools.ServiceLayer.exe");
|
Environment.SetEnvironmentVariable("SQLTOOLSSERVICE_EXE", @"MicrosoftSqlToolsServiceLayer.exe");
|
||||||
|
|
||||||
// execute a query against localhost, master, with IntegratedAuth
|
// execute a query against localhost, master, with IntegratedAuth
|
||||||
ExecuteQuery("SELECT * FROM sys.objects").Wait();
|
ExecuteQuery("SELECT * FROM sys.objects").Wait();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task ExecuteQuery(string query)
|
internal static async Task ExecuteQuery(string query)
|
||||||
@@ -43,7 +45,7 @@ namespace Microsoft.SqlTools.JsonRpc.ExecuteQuery
|
|||||||
await testHelper.Connect(queryTempFile.FilePath, connectParams);
|
await testHelper.Connect(queryTempFile.FilePath, connectParams);
|
||||||
|
|
||||||
// execute the query
|
// execute the query
|
||||||
QueryExecuteCompleteParams queryComplete =
|
QueryCompleteParams queryComplete =
|
||||||
await testHelper.RunQuery(queryTempFile.FilePath, query);
|
await testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||||
|
|
||||||
if (queryComplete.BatchSummaries != null && queryComplete.BatchSummaries.Length > 0)
|
if (queryComplete.BatchSummaries != null && queryComplete.BatchSummaries.Length > 0)
|
||||||
@@ -54,7 +56,7 @@ namespace Microsoft.SqlTools.JsonRpc.ExecuteQuery
|
|||||||
var resultSet = batch.ResultSetSummaries[0];
|
var resultSet = batch.ResultSetSummaries[0];
|
||||||
|
|
||||||
// retrive the results
|
// retrive the results
|
||||||
QueryExecuteSubsetResult querySubset = await testHelper.ExecuteSubset(
|
SubsetResult querySubset = await testHelper.ExecuteSubset(
|
||||||
queryTempFile.FilePath, batch.Id,
|
queryTempFile.FilePath, batch.Id,
|
||||||
resultSet.Id, 0, (int)resultSet.RowCount);
|
resultSet.Id, 0, (int)resultSet.RowCount);
|
||||||
|
|
||||||
@@ -70,7 +72,7 @@ namespace Microsoft.SqlTools.JsonRpc.ExecuteQuery
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < resultSet.ColumnInfo.Length; ++i)
|
for (int i = 0; i < resultSet.ColumnInfo.Length; ++i)
|
||||||
{
|
{
|
||||||
Console.Write(row.GetValue(i) + ", ");
|
Console.Write(row[i].DisplayValue + ", ");
|
||||||
}
|
}
|
||||||
Console.Write(Environment.NewLine);
|
Console.Write(Environment.NewLine);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.JsonRpc.Utility
|
namespace Microsoft.SqlTools.JsonRpc.Utility
|
||||||
{
|
{
|
||||||
@@ -119,9 +120,9 @@ namespace Microsoft.SqlTools.JsonRpc.Utility
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Request the active SQL script is parsed for errors
|
/// Request the active SQL script is parsed for errors
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<QueryExecuteSubsetResult> RequestQueryExecuteSubset(QueryExecuteSubsetParams subsetParams)
|
public async Task<SubsetResult> RequestQueryExecuteSubset(SubsetParams subsetParams)
|
||||||
{
|
{
|
||||||
return await Driver.SendRequest(QueryExecuteSubsetRequest.Type, subsetParams);
|
return await Driver.SendRequest(SubsetRequest.Type, subsetParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -171,21 +172,21 @@ namespace Microsoft.SqlTools.JsonRpc.Utility
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Run a query using a given connection bound to a URI
|
/// Run a query using a given connection bound to a URI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<QueryExecuteCompleteParams> RunQuery(string ownerUri, string query, int timeoutMilliseconds = 5000)
|
public async Task<QueryCompleteParams> RunQuery(string ownerUri, string query, int timeoutMilliseconds = 5000)
|
||||||
{
|
{
|
||||||
// Write the query text to a backing file
|
// Write the query text to a backing file
|
||||||
WriteToFile(ownerUri, query);
|
WriteToFile(ownerUri, query);
|
||||||
|
|
||||||
var queryParams = new QueryExecuteParams
|
var queryParams = new ExecuteDocumentSelectionParams
|
||||||
{
|
{
|
||||||
OwnerUri = ownerUri,
|
OwnerUri = ownerUri,
|
||||||
QuerySelection = null
|
QuerySelection = null
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = await Driver.SendRequest(QueryExecuteRequest.Type, queryParams);
|
var result = await Driver.SendRequest(ExecuteDocumentSelectionRequest.Type, queryParams);
|
||||||
if (result != null && string.IsNullOrEmpty(result.Messages))
|
if (result != null)
|
||||||
{
|
{
|
||||||
var eventResult = await Driver.WaitForEvent(QueryExecuteCompleteEvent.Type, timeoutMilliseconds);
|
var eventResult = await Driver.WaitForEvent(QueryCompleteEvent.Type, timeoutMilliseconds);
|
||||||
return eventResult;
|
return eventResult;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -231,16 +232,16 @@ namespace Microsoft.SqlTools.JsonRpc.Utility
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Request a subset of results from a query
|
/// Request a subset of results from a query
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<QueryExecuteSubsetResult> ExecuteSubset(string ownerUri, int batchIndex, int resultSetIndex, int rowStartIndex, int rowCount)
|
public async Task<SubsetResult> ExecuteSubset(string ownerUri, int batchIndex, int resultSetIndex, int rowStartIndex, int rowCount)
|
||||||
{
|
{
|
||||||
var subsetParams = new QueryExecuteSubsetParams();
|
var subsetParams = new SubsetParams();
|
||||||
subsetParams.OwnerUri = ownerUri;
|
subsetParams.OwnerUri = ownerUri;
|
||||||
subsetParams.BatchIndex = batchIndex;
|
subsetParams.BatchIndex = batchIndex;
|
||||||
subsetParams.ResultSetIndex = resultSetIndex;
|
subsetParams.ResultSetIndex = resultSetIndex;
|
||||||
subsetParams.RowsStartIndex = rowStartIndex;
|
subsetParams.RowsStartIndex = rowStartIndex;
|
||||||
subsetParams.RowsCount = rowCount;
|
subsetParams.RowsCount = rowCount;
|
||||||
|
|
||||||
var result = await Driver.SendRequest(QueryExecuteSubsetRequest.Type, subsetParams);
|
var result = await Driver.SendRequest(SubsetRequest.Type, subsetParams);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
docs/samples/jsonrpc/netcore/executequery/jsonrpc.csproj
Normal file
16
docs/samples/jsonrpc/netcore/executequery/jsonrpc.csproj
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<!-- <PackageReference Include="Microsoft.SqlServer.Smo" Version="12.0.2000.8" /> -->
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
|
||||||
|
<PackageReference Include="System.Data.SqlClient" Version="4.5.1" />
|
||||||
|
<!-- <PackageReference Include="System.Data.SqlClient" Version="4.4.0-sqltools-24613-04" /> -->
|
||||||
|
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.17279.0-xplat" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\..\..\..\src\Microsoft.SqlTools.ServiceLayer\Microsoft.SqlTools.ServiceLayer.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user