mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
add auto detect json based on first row of each column (#571)
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Collections.Concurrent;
|
|||||||
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.RegularExpressions;
|
||||||
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;
|
||||||
@@ -362,6 +363,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
}
|
}
|
||||||
// Check if resultset is 'for xml/json'. If it is, set isJson/isXml value in column metadata
|
// Check if resultset is 'for xml/json'. If it is, set isJson/isXml value in column metadata
|
||||||
SingleColumnXmlJsonResultSet();
|
SingleColumnXmlJsonResultSet();
|
||||||
|
CheckForIsJson();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -589,6 +591,28 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check columns for json type and set isJson if needed
|
||||||
|
/// </summary>
|
||||||
|
private void CheckForIsJson()
|
||||||
|
{
|
||||||
|
if (Columns?.Length > 0 && RowCount != 0)
|
||||||
|
{
|
||||||
|
Regex regex = new Regex(@"({.*?})");
|
||||||
|
var row = GetRow(0);
|
||||||
|
for (int i = 0; i < Columns.Length; i++)
|
||||||
|
{
|
||||||
|
if (Columns[i].DataTypeName.Equals("nvarchar"))
|
||||||
|
{
|
||||||
|
if (regex.IsMatch(row[i].DisplayValue))
|
||||||
|
{
|
||||||
|
Columns[i].IsJson = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determine the special action, if any, for this result set
|
/// Determine the special action, if any, for this result set
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user