mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Feature/timestamp messages (#68)
* added support for timestamps * fixed tests * Moved message class to own file; added 'z' to end of date strings * added default time constructor * removed unnecessary z * added time string format info in comment * changed from utc time to using local time
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration >
|
<configuration >
|
||||||
<packageSources>
|
<packageSources>
|
||||||
|
<add key="Nuget" value="https://www.nuget.org/api/v2" />
|
||||||
<add key="DataTools Nuget" value="http://dtnuget/api/v2/" />
|
<add key="DataTools Nuget" value="http://dtnuget/api/v2/" />
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Internal representation of the messages so we can modify internally
|
/// Internal representation of the messages so we can modify internally
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly List<string> resultMessages;
|
private readonly List<ResultMessage> resultMessages;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Internal representation of the result sets so we can modify internally
|
/// Internal representation of the result sets so we can modify internally
|
||||||
@@ -58,7 +58,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
Selection = new SelectionData(startLine, startColumn, endLine, endColumn);
|
Selection = new SelectionData(startLine, startColumn, endLine, endColumn);
|
||||||
HasExecuted = false;
|
HasExecuted = false;
|
||||||
resultSets = new List<ResultSet>();
|
resultSets = new List<ResultSet>();
|
||||||
resultMessages = new List<string>();
|
resultMessages = new List<ResultMessage>();
|
||||||
this.outputFileFactory = outputFileFactory;
|
this.outputFileFactory = outputFileFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Messages that have come back from the server
|
/// Messages that have come back from the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<string> ResultMessages
|
public IEnumerable<ResultMessage> ResultMessages
|
||||||
{
|
{
|
||||||
get { return resultMessages; }
|
get { return resultMessages; }
|
||||||
}
|
}
|
||||||
@@ -168,9 +168,9 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
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
|
// Create a message with the number of affected rows -- IF the query affects rows
|
||||||
resultMessages.Add(reader.RecordsAffected >= 0
|
resultMessages.Add(new ResultMessage(reader.RecordsAffected >= 0
|
||||||
? SR.QueryServiceAffectedRows(reader.RecordsAffected)
|
? SR.QueryServiceAffectedRows(reader.RecordsAffected)
|
||||||
: SR.QueryServiceCompletedSuccessfully);
|
: SR.QueryServiceCompletedSuccessfully));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
resultSets.Add(resultSet);
|
resultSets.Add(resultSet);
|
||||||
|
|
||||||
// Add a message for the number of rows the query returned
|
// Add a message for the number of rows the query returned
|
||||||
resultMessages.Add(SR.QueryServiceAffectedRows(resultSet.RowCount));
|
resultMessages.Add(new ResultMessage(SR.QueryServiceAffectedRows(resultSet.RowCount)));
|
||||||
} while (await reader.NextResultAsync(cancellationToken));
|
} while (await reader.NextResultAsync(cancellationToken));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,7 +244,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
/// <param name="args">Arguments from the event</param>
|
/// <param name="args">Arguments from the event</param>
|
||||||
private void StoreDbMessage(object sender, SqlInfoMessageEventArgs args)
|
private void StoreDbMessage(object sender, SqlInfoMessageEventArgs args)
|
||||||
{
|
{
|
||||||
resultMessages.Add(args.Message);
|
resultMessages.Add(new ResultMessage(args.Message));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -268,13 +268,13 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
string message = string.Format("Msg {0}, Level {1}, State {2}, Line {3}{4}{5}",
|
string message = string.Format("Msg {0}, Level {1}, State {2}, Line {3}{4}{5}",
|
||||||
sqlError.Number, sqlError.Class, sqlError.State, lineNumber,
|
sqlError.Number, sqlError.Class, sqlError.State, lineNumber,
|
||||||
Environment.NewLine, sqlError.Message);
|
Environment.NewLine, sqlError.Message);
|
||||||
resultMessages.Add(message);
|
resultMessages.Add(new ResultMessage(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
resultMessages.Add(dbe.Message);
|
resultMessages.Add(new ResultMessage(dbe.Message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Any messages that came back from the server during execution of the batch
|
/// Any messages that came back from the server during execution of the batch
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] Messages { get; set; }
|
public ResultMessage[] Messages { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The summaries of the result sets inside the batch
|
/// The summaries of the result sets inside the batch
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Result message object with timestamp and actual message
|
||||||
|
/// </summary>
|
||||||
|
public class ResultMessage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Timestamp of the message
|
||||||
|
/// Stored in UTC ISO 8601 format; should be localized before displaying to any user
|
||||||
|
/// </summary>
|
||||||
|
public string Time { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Message contents
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Full constructor
|
||||||
|
/// </summary>
|
||||||
|
public ResultMessage(string timeStamp, string message)
|
||||||
|
{
|
||||||
|
Time = timeStamp;
|
||||||
|
Message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor with default "Now" time
|
||||||
|
/// </summary>
|
||||||
|
public ResultMessage(string message)
|
||||||
|
{
|
||||||
|
Time = DateTime.Now.ToString("o");
|
||||||
|
Message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -74,7 +74,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
|
|
||||||
// ... There should be a message for how many rows were affected
|
// ... There should be a message for how many rows were affected
|
||||||
Assert.Equal(1, batch.ResultMessages.Count());
|
Assert.Equal(1, batch.ResultMessages.Count());
|
||||||
Assert.Contains("1 ", batch.ResultMessages.First());
|
Assert.Contains("1 ", batch.ResultMessages.First().Message);
|
||||||
// NOTE: 1 is expected because this test simulates a 'update' statement where 1 row was affected.
|
// NOTE: 1 is expected because this test simulates a 'update' statement where 1 row was affected.
|
||||||
// The 1 in quotes is to make sure the 1 isn't part of a larger number
|
// The 1 in quotes is to make sure the 1 isn't part of a larger number
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
|
|
||||||
// ... There should be a message for how many rows were affected
|
// ... There should be a message for how many rows were affected
|
||||||
Assert.Equal(resultSets, batch.ResultMessages.Count());
|
Assert.Equal(resultSets, batch.ResultMessages.Count());
|
||||||
Assert.Contains(Common.StandardRows.ToString(), batch.ResultMessages.First());
|
Assert.Contains(Common.StandardRows.ToString(), batch.ResultMessages.First().Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -155,7 +155,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
Assert.Equal(resultSets, batch.ResultMessages.Count());
|
Assert.Equal(resultSets, batch.ResultMessages.Count());
|
||||||
foreach (var rsm in batch.ResultMessages)
|
foreach (var rsm in batch.ResultMessages)
|
||||||
{
|
{
|
||||||
Assert.Contains(Common.StandardRows.ToString(), rsm);
|
Assert.Contains(Common.StandardRows.ToString(), rsm.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user