Skip to content

Commit

Permalink
2747 Fixed IsUnknownType error for Kusto (#989)
Browse files Browse the repository at this point in the history
* 2747 Removed unused directives in Kusto > DbColumnWrapper. Refactored IsUnknownType to handle null DataTypeName

* 2747 Reverted IsUnknownType change in DbColumnWrapper. Changed DataTypeName to get calue from ColumnType. Refactored SafeGetValue to type check before hard casting to reduce case exceptions.
  • Loading branch information
JustinMDotNet authored Jun 30, 2020
1 parent 05ca0ed commit 81047d7
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlTypes;
using System.Diagnostics;
using Microsoft.SqlTools.Utility;

namespace Microsoft.Kusto.ServiceLayer.QueryExecution.Contracts
{
Expand Down Expand Up @@ -91,18 +88,24 @@ public DbColumnWrapper(DataRow row)
NumericPrecision = SafeGetValue<int?>(row, "NumericPrecision");
NumericScale = SafeGetValue<int?>(row, "NumericScale");
UdtAssemblyQualifiedName = SafeGetValue<string>(row, "UdtAssemblyQualifiedName");
DataType = SafeGetValue<System.Type>(row, "DataType");
DataTypeName = SafeGetValue<string>(row, "DataTypeName");
DataType = SafeGetValue<Type>(row, "DataType");
DataTypeName = SafeGetValue<string>(row, "ColumnType");
ColumnName = SafeGetValue<string>(row, "ColumnName");
}

internal T SafeGetValue<T>(DataRow row, string attribName)
private T SafeGetValue<T>(DataRow row, string attribName)
{
try
{
return (T)row[attribName];
if (row[attribName] is T value)
{
return value;
}
}
catch{} // Ignore exceptions
catch
{
// Ignore exceptions
}

return default(T);
}
Expand Down Expand Up @@ -176,7 +179,7 @@ public DbColumnWrapper()
/// Logic taken from SSDT determination of unknown columns. It may not even be possible to
/// have "unknown" column types with the .NET Core SqlClient.
/// </remarks>
public bool IsUnknownType => DataType == typeof(object) &&
public bool IsUnknownType => DataType == typeof(object) &&
DataTypeName.Equals(UnknownTypeName, StringComparison.OrdinalIgnoreCase);

#endregion
Expand Down

0 comments on commit 81047d7

Please sign in to comment.