mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Export headers in an empty result set (#1434)
* Minimal changes to make headers appear on empty result sets * Columns for everyone! * Updating tests - some don't pass yet * Adding some more tests to verify the changes for column/row selection * null default columns * Updates to comments as per PR comments
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.
|
||||
//
|
||||
@@ -7,6 +7,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
{
|
||||
@@ -21,18 +22,31 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream that will be written to</param>
|
||||
/// <param name="requestParams">The SaveAs request parameters</param>
|
||||
protected SaveAsStreamWriter(Stream stream, SaveResultsRequestParams requestParams)
|
||||
/// <param name="columns">
|
||||
/// The entire list of columns for the result set. Used to determine which columns to
|
||||
/// output.
|
||||
/// </param>
|
||||
protected SaveAsStreamWriter(Stream stream, SaveResultsRequestParams requestParams, IReadOnlyList<DbColumnWrapper> columns)
|
||||
{
|
||||
Validate.IsNotNull(nameof(stream), stream);
|
||||
Validate.IsNotNull(nameof(columns), columns);
|
||||
|
||||
FileStream = stream;
|
||||
var saveParams = requestParams;
|
||||
if (requestParams.IsSaveSelection)
|
||||
{
|
||||
// ReSharper disable PossibleInvalidOperationException IsSaveSelection verifies these values exist
|
||||
ColumnStartIndex = saveParams.ColumnStartIndex.Value;
|
||||
ColumnEndIndex = saveParams.ColumnEndIndex.Value;
|
||||
ColumnCount = saveParams.ColumnEndIndex.Value - saveParams.ColumnStartIndex.Value + 1;
|
||||
ColumnStartIndex = requestParams.ColumnStartIndex.Value;
|
||||
ColumnEndIndex = requestParams.ColumnEndIndex.Value;
|
||||
// ReSharper restore PossibleInvalidOperationException
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save request was for the entire result set, use default start/end
|
||||
ColumnStartIndex = 0;
|
||||
ColumnEndIndex = columns.Count - 1;
|
||||
}
|
||||
|
||||
ColumnCount = ColumnEndIndex - ColumnStartIndex + 1;
|
||||
}
|
||||
|
||||
#region Properties
|
||||
@@ -40,22 +54,22 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
/// <summary>
|
||||
/// Index of the first column to write to the output file
|
||||
/// </summary>
|
||||
protected int? ColumnStartIndex { get; private set; }
|
||||
protected int ColumnStartIndex { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of columns to write to the output file
|
||||
/// </summary>
|
||||
protected int? ColumnCount { get; private set; }
|
||||
protected int ColumnCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Index of the last column to write to the output file
|
||||
/// Index of the last column to write to the output file (inclusive).
|
||||
/// </summary>
|
||||
protected int? ColumnEndIndex { get; private set; }
|
||||
protected int ColumnEndIndex { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The file stream to use to write the output file
|
||||
/// </summary>
|
||||
protected Stream FileStream { get; private set; }
|
||||
protected Stream FileStream { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -73,7 +87,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
/// </summary>
|
||||
/// <param name="row">The row of data to output</param>
|
||||
/// <param name="columns">The list of columns to output</param>
|
||||
public abstract void WriteRow(IList<DbCellValue> row, IList<DbColumnWrapper> columns);
|
||||
public abstract void WriteRow(IList<DbCellValue> row, IReadOnlyList<DbColumnWrapper> columns);
|
||||
|
||||
/// <summary>
|
||||
/// Not implemented, do not use.
|
||||
|
||||
Reference in New Issue
Block a user