mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Merge pull request #22 from Microsoft/feature/queryExecuteServerMessages
Bug fix: Messages not returned on SELECT queries
This commit is contained in:
@@ -21,6 +21,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Query : IDisposable
|
public class Query : IDisposable
|
||||||
{
|
{
|
||||||
|
private const string RowsAffectedFormat = "({0} row(s) affected)";
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -114,13 +116,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
throw new InvalidOperationException("Query has already executed.");
|
throw new InvalidOperationException("Query has already executed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
DbConnection conn = null;
|
|
||||||
|
|
||||||
// Create a connection from the connection details
|
// Create a connection from the connection details
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string connectionString = ConnectionService.BuildConnectionString(EditorConnection.ConnectionDetails);
|
string connectionString = ConnectionService.BuildConnectionString(EditorConnection.ConnectionDetails);
|
||||||
using (conn = EditorConnection.Factory.CreateSqlConnection(connectionString))
|
using (DbConnection conn = EditorConnection.Factory.CreateSqlConnection(connectionString))
|
||||||
{
|
{
|
||||||
// If we have the message listener, bind to it
|
// If we have the message listener, bind to it
|
||||||
SqlConnection sqlConn = conn as SqlConnection;
|
SqlConnection sqlConn = conn as SqlConnection;
|
||||||
@@ -142,14 +142,14 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Create a message with the number of affected rows
|
// Skip this result set if there aren't any rows
|
||||||
if (reader.RecordsAffected >= 0)
|
|
||||||
{
|
|
||||||
ResultMessages.Add(String.Format("({0} row(s) affected)", reader.RecordsAffected));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!reader.HasRows && reader.FieldCount == 0)
|
if (!reader.HasRows && reader.FieldCount == 0)
|
||||||
{
|
{
|
||||||
|
// Create a message with the number of affected rows -- IF the query affects rows
|
||||||
|
ResultMessages.Add(reader.RecordsAffected >= 0
|
||||||
|
? string.Format(RowsAffectedFormat, reader.RecordsAffected)
|
||||||
|
: "Command Executed Successfully");
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,6 +168,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
|
|
||||||
// Add the result set to the results of the query
|
// Add the result set to the results of the query
|
||||||
ResultSets.Add(resultSet);
|
ResultSets.Add(resultSet);
|
||||||
|
|
||||||
|
// Add a message for the number of rows the query returned
|
||||||
|
ResultMessages.Add(string.Format(RowsAffectedFormat, resultSet.Rows.Count));
|
||||||
|
|
||||||
} while (await reader.NextResultAsync(cancellationSource.Token));
|
} while (await reader.NextResultAsync(cancellationSource.Token));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Data.SqlClient;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||||
@@ -106,7 +105,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
ServerName = "sqltools11"
|
ServerName = "sqltools11"
|
||||||
};
|
};
|
||||||
|
|
||||||
return new ConnectionInfo(CreateMockFactory(data, throwOnRead), "test://test", connDetails);
|
return new ConnectionInfo(CreateMockFactory(data, throwOnRead), OwnerUri, connDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -365,6 +365,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
VerifyQueryExecuteCallCount(requestContext, Times.Once(), Times.Never(), Times.Never());
|
VerifyQueryExecuteCallCount(requestContext, Times.Once(), Times.Never(), Times.Never());
|
||||||
Assert.NotNull(result.Messages);
|
Assert.NotNull(result.Messages);
|
||||||
Assert.NotEmpty(result.Messages);
|
Assert.NotEmpty(result.Messages);
|
||||||
|
|
||||||
|
// ... There should not be an active query
|
||||||
|
Assert.Empty(queryService.ActiveQueries);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -91,6 +91,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Utility
|
|||||||
|
|
||||||
public override int FieldCount { get { return Rows?.Current.Count ?? 0; } }
|
public override int FieldCount { get { return Rows?.Current.Count ?? 0; } }
|
||||||
|
|
||||||
|
public override int RecordsAffected
|
||||||
|
{
|
||||||
|
// Mimics the behavior of SqlDataReader
|
||||||
|
get { return Rows != null ? -1 : 1; }
|
||||||
|
}
|
||||||
|
|
||||||
#region Not Implemented
|
#region Not Implemented
|
||||||
|
|
||||||
public override bool GetBoolean(int ordinal)
|
public override bool GetBoolean(int ordinal)
|
||||||
@@ -200,7 +206,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Utility
|
|||||||
|
|
||||||
public override int Depth { get; }
|
public override int Depth { get; }
|
||||||
public override bool IsClosed { get; }
|
public override bool IsClosed { get; }
|
||||||
public override int RecordsAffected { get; }
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user