mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
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:
@@ -182,7 +182,12 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not the column is XML
|
/// Whether or not the column is XML
|
||||||
/// </summary>
|
/// </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
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
// 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
|
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
|
#endregion
|
||||||
|
|
||||||
#region Member Variables
|
#region Member Variables
|
||||||
@@ -192,6 +197,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
currentFileOffset += fileWriter.WriteRow(DataReader);
|
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
|
// Mark that result has been read
|
||||||
hasBeenRead = true;
|
hasBeenRead = true;
|
||||||
@@ -225,5 +232,30 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user