diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Batch.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Batch.cs index bd29f1d6..4b81dfc4 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Batch.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Batch.cs @@ -64,9 +64,14 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution } } + /// + /// The 0-indexed line number that this batch started on + /// + private int StartLine { get; set; } + #endregion - public Batch(string batchText) + public Batch(string batchText, int startLine) { // Sanity check for input if (string.IsNullOrEmpty(batchText)) @@ -76,6 +81,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution // Initialize the internal state BatchText = batchText; + StartLine = startLine - 1; HasExecuted = false; ResultSets = new List(); ResultMessages = new List(); @@ -222,8 +228,9 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution SqlError sqlError = error as SqlError; if (sqlError != null) { + int lineNumber = sqlError.LineNumber + StartLine; string message = String.Format("Msg {0}, Level {1}, State {2}, Line {3}{4}{5}", - sqlError.Number, sqlError.Class, sqlError.State, sqlError.LineNumber, + sqlError.Number, sqlError.Class, sqlError.State, lineNumber, Environment.NewLine, sqlError.Message); ResultMessages.Add(message); } diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Query.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Query.cs index 66243763..add05b34 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Query.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Query.cs @@ -117,7 +117,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution { BatchSeparator = settings.BatchSeparator }); - Batches = parseResult.Script.Batches.Select(b => new Batch(b.Sql)).ToArray(); + Batches = parseResult.Script.Batches.Select(b => new Batch(b.Sql, b.StartLocation.LineNumber)).ToArray(); } ///