mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
Fix/merge xml rows (#85)
* Concatenate rows for 'for Xml' and 'for Json' * Modify select * remove get set for isSingleColumnXmlJsonResultSet * Remove toList
This commit is contained in:
@@ -7,6 +7,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
@@ -54,6 +55,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private bool hasBeenRead;
|
private bool hasBeenRead;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether resultSet is a 'for xml' or 'for json' result
|
||||||
|
/// </summary>
|
||||||
|
private bool isSingleColumnXmlJsonResultSet;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The name of the temporary file we're using to output these results in
|
/// The name of the temporary file we're using to output these results in
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -156,13 +162,29 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
|
|
||||||
return Task.Factory.StartNew(() =>
|
return Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
// Figure out which rows we need to read back
|
|
||||||
IEnumerable<long> rowOffsets = FileOffsets.Skip(startRow).Take(rowCount);
|
|
||||||
|
|
||||||
// Iterate over the rows we need and process them into output
|
string[][] rows;
|
||||||
string[][] rows = rowOffsets.Select(rowOffset =>
|
// If result set is 'for xml' or 'for json',
|
||||||
fileStreamReader.ReadRow(rowOffset, Columns).Select(cell => cell.DisplayValue).ToArray())
|
// Concatenate all the rows together into one row
|
||||||
.ToArray();
|
if (isSingleColumnXmlJsonResultSet)
|
||||||
|
{
|
||||||
|
// Iterate over all the rows and process them into a list of string builders
|
||||||
|
IEnumerable<StringBuilder> sbRows = FileOffsets.Select(rowOffset => fileStreamReader.ReadRow(rowOffset, Columns)
|
||||||
|
.Select(cell => cell.DisplayValue).Aggregate(new StringBuilder(), (sb, value) => sb.Append(value)));
|
||||||
|
rows = new[] { new[] { string.Join(string.Empty, sbRows) } };
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Figure out which rows we need to read back
|
||||||
|
IEnumerable<long> rowOffsets = FileOffsets.Skip(startRow).Take(rowCount);
|
||||||
|
|
||||||
|
// Iterate over the rows we need and process them into output
|
||||||
|
rows = rowOffsets.Select(rowOffset =>
|
||||||
|
fileStreamReader.ReadRow(rowOffset, Columns).Select(cell => cell.DisplayValue).ToArray())
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve the subset of the results as per the request
|
// Retrieve the subset of the results as per the request
|
||||||
return new ResultSetSubset
|
return new ResultSetSubset
|
||||||
@@ -243,15 +265,19 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void SingleColumnXmlJsonResultSet() {
|
private void SingleColumnXmlJsonResultSet() {
|
||||||
|
|
||||||
if (Columns?.Length == 1)
|
if (Columns?.Length == 1 && RowCount != 0)
|
||||||
{
|
{
|
||||||
if (Columns[0].ColumnName.Equals(NameOfForXMLColumn, StringComparison.Ordinal))
|
if (Columns[0].ColumnName.Equals(NameOfForXMLColumn, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
Columns[0].IsXml = true;
|
Columns[0].IsXml = true;
|
||||||
|
isSingleColumnXmlJsonResultSet = true;
|
||||||
|
RowCount = 1;
|
||||||
}
|
}
|
||||||
else if (Columns[0].ColumnName.Equals(NameOfForJSONColumn, StringComparison.Ordinal))
|
else if (Columns[0].ColumnName.Equals(NameOfForJSONColumn, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
Columns[0].IsJson = true;
|
Columns[0].IsJson = true;
|
||||||
|
isSingleColumnXmlJsonResultSet = true;
|
||||||
|
RowCount = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user