Support 'for XML and for JSON' queries (#75)

* Set isXMl and isJson for 'for xml/json' resultSets

* Change string comparison

* Modify if-else
This commit is contained in:
Sharon Ravindran
2016-10-06 11:35:29 -07:00
committed by GitHub
parent 46f0638283
commit fea9bb43c5
2 changed files with 38 additions and 1 deletions

View File

@@ -182,7 +182,12 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
/// <summary>
/// Whether or not the column is XML
/// </summary>
public bool IsXml { get; private set; }
public bool IsXml { get; set; }
/// <summary>
/// Whether or not the column is JSON
/// </summary>
public bool IsJson { get; set; }
#endregion

View File

@@ -24,6 +24,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
// xml is a special case so number of chars to store is usually greater than for other long types
private const int DefaultMaxXmlCharsToStore = 2097152; // 2 MB - QE default
// Column names of 'for xml' and 'for json' queries
private const string NameOfForXMLColumn = "XML_F52E2B61-18A1-11d1-B105-00805F49916B";
private const string NameOfForJSONColumn = "JSON_F52E2B61-18A1-11d1-B105-00805F49916B";
#endregion
#region Member Variables
@@ -192,6 +197,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
currentFileOffset += fileWriter.WriteRow(DataReader);
}
}
// Check if resultset is 'for xml/json'. If it is, set isJson/isXml value in column metadata
SingleColumnXmlJsonResultSet();
// Mark that result has been read
hasBeenRead = true;
@@ -225,5 +232,30 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
}
#endregion
#region Private Helper Methods
/// <summary>
/// If the result set represented by this class corresponds to a single XML
/// column that contains results of "for xml" query, set isXml = true
/// If the result set represented by this class corresponds to a single JSON
/// column that contains results of "for json" query, set isJson = true
/// </summary>
private void SingleColumnXmlJsonResultSet() {
if (Columns?.Length == 1)
{
if (Columns[0].ColumnName.Equals(NameOfForXMLColumn, StringComparison.Ordinal))
{
Columns[0].IsXml = true;
}
else if (Columns[0].ColumnName.Equals(NameOfForJSONColumn, StringComparison.Ordinal))
{
Columns[0].IsJson = true;
}
}
}
#endregion
}
}