Getting rid of new methods in favor of just assigning the base (#198)

This change is a refactor of the DbColumnWrapper class. This fixes a huge oversight/gotcha in the DbColumnWrapper where treating the DbColumnWrapper as a DbColumn (ie, polymorphism) would result in almost all the fields of the column being null. This is a highly unexpected behavior. This change fixes that.
This commit is contained in:
Benjamin Russell
2016-12-19 15:27:13 -08:00
committed by GitHub
parent ba12a80fbf
commit 1ada659a8a
3 changed files with 38 additions and 55 deletions

View File

@@ -52,8 +52,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
"datetime2" "datetime2"
}; };
private readonly DbColumn internalColumn;
/// <summary> /// <summary>
/// Constructor for a DbColumnWrapper /// Constructor for a DbColumnWrapper
/// </summary> /// </summary>
@@ -61,7 +59,34 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
/// <param name="column">The column we're wrapping around</param> /// <param name="column">The column we're wrapping around</param>
public DbColumnWrapper(DbColumn column) public DbColumnWrapper(DbColumn column)
{ {
internalColumn = column; // Set all the fields for the base
AllowDBNull = column.AllowDBNull;
BaseCatalogName = column.BaseCatalogName;
BaseColumnName = column.BaseColumnName;
BaseSchemaName = column.BaseSchemaName;
BaseServerName = column.BaseServerName;
BaseTableName = column.BaseTableName;
ColumnOrdinal = column.ColumnOrdinal;
ColumnSize = column.ColumnSize;
IsAliased = column.IsAliased;
IsAutoIncrement = column.IsAutoIncrement;
IsExpression = column.IsExpression;
IsHidden = column.IsHidden;
IsIdentity = column.IsIdentity;
IsKey = column.IsKey;
IsLong = column.IsLong;
IsReadOnly = column.IsLong;
IsUnique = column.IsUnique;
NumericPrecision = column.NumericPrecision;
NumericScale = column.NumericScale;
UdtAssemblyQualifiedName = column.UdtAssemblyQualifiedName;
DataType = column.DataType;
DataTypeName = column.DataTypeName;
// We want the display name for the column to always exist
ColumnName = string.IsNullOrEmpty(column.ColumnName)
? SR.QueryServiceColumnNull
: column.ColumnName;
switch (column.DataTypeName) switch (column.DataTypeName)
{ {
@@ -78,8 +103,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
//This is not the best fix that we could do but we are trying to minimize code impact //This is not the best fix that we could do but we are trying to minimize code impact
//at this point. Post Yukon we should review this code again and avoid //at this point. Post Yukon we should review this code again and avoid
//hard-coding special column name in multiple places. //hard-coding special column name in multiple places.
const string YukonXmlShowPlanColumn = "Microsoft SQL Server 2005 XML Showplan"; const string yukonXmlShowPlanColumn = "Microsoft SQL Server 2005 XML Showplan";
if (column.ColumnName == YukonXmlShowPlanColumn) if (column.ColumnName == yukonXmlShowPlanColumn)
{ {
// Indicate that this is xml to apply the right size limit // Indicate that this is xml to apply the right size limit
// Note we leave chars type as well to use the right retrieval mechanism. // Note we leave chars type as well to use the right retrieval mechanism.
@@ -133,7 +158,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
{ {
// udtassemblyqualifiedname property is used to find if the datatype is of hierarchyid assembly type // udtassemblyqualifiedname property is used to find if the datatype is of hierarchyid assembly type
// Internally hiearchyid is sqlbinary so providerspecific type and type is changed to sqlbinarytype // Internally hiearchyid is sqlbinary so providerspecific type and type is changed to sqlbinarytype
object assemblyQualifiedName = internalColumn.UdtAssemblyQualifiedName; object assemblyQualifiedName = column.UdtAssemblyQualifiedName;
const string hierarchyId = "MICROSOFT.SQLSERVER.TYPES.SQLHIERARCHYID"; const string hierarchyId = "MICROSOFT.SQLSERVER.TYPES.SQLHIERARCHYID";
if (assemblyQualifiedName != null && if (assemblyQualifiedName != null &&
@@ -171,11 +196,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
/// </summary> /// </summary>
public bool IsChars { get; private set; } public bool IsChars { get; private set; }
/// <summary>
/// Whether or not the column is a long type (eg, varchar(MAX))
/// </summary>
public new bool IsLong { get; private set; }
/// <summary> /// <summary>
/// Whether or not the column is a SqlVariant type /// Whether or not the column is a SqlVariant type
/// </summary> /// </summary>
@@ -198,42 +218,5 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
#endregion #endregion
#region DbColumn Fields
/// <summary>
/// Override for column name, if null or empty, we default to a "no column name" value
/// </summary>
public new string ColumnName
{
get
{
return string.IsNullOrEmpty(internalColumn.ColumnName)
? SR.QueryServiceColumnNull
: internalColumn.ColumnName;
}
}
public new bool? AllowDBNull { get { return internalColumn.AllowDBNull; } }
public new string BaseCatalogName { get { return internalColumn.BaseCatalogName; } }
public new string BaseColumnName { get { return internalColumn.BaseColumnName; } }
public new string BaseServerName { get { return internalColumn.BaseServerName; } }
public new string BaseTableName { get { return internalColumn.BaseTableName; } }
public new int? ColumnOrdinal { get { return internalColumn.ColumnOrdinal; } }
public new int? ColumnSize { get { return internalColumn.ColumnSize; } }
public new bool? IsAliased { get { return internalColumn.IsAliased; } }
public new bool? IsAutoIncrement { get { return internalColumn.IsAutoIncrement; } }
public new bool? IsExpression { get { return internalColumn.IsExpression; } }
public new bool? IsHidden { get { return internalColumn.IsHidden; } }
public new bool? IsIdentity { get { return internalColumn.IsIdentity; } }
public new bool? IsKey { get { return internalColumn.IsKey; } }
public new bool? IsReadOnly { get { return internalColumn.IsReadOnly; } }
public new bool? IsUnique { get { return internalColumn.IsUnique; } }
public new int? NumericPrecision { get { return internalColumn.NumericPrecision; } }
public new int? NumericScale { get { return internalColumn.NumericScale; } }
public new string UdtAssemblyQualifiedName { get { return internalColumn.UdtAssemblyQualifiedName; } }
public new Type DataType { get; private set; }
public new string DataTypeName { get { return internalColumn.DataTypeName; } }
#endregion
} }
} }

View File

@@ -140,12 +140,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
} }
else else
{ {
if (!ci.IsLong) if (ci.IsLong.HasValue && ci.IsLong.Value)
{
// not a long field
values[i] = reader.GetValue(i);
}
else
{ {
// this is a long field // this is a long field
if (ci.IsBytes) if (ci.IsBytes)
@@ -169,6 +164,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
Debug.Assert(false); Debug.Assert(false);
} }
} }
else
{
// not a long field
values[i] = reader.GetValue(i);
}
} }
} }

View File

@@ -57,7 +57,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
// Read the columns into a set of wrappers // Read the columns into a set of wrappers
Columns = DbDataReader.GetColumnSchema().Select(column => new DbColumnWrapper(column)).ToArray(); Columns = DbDataReader.GetColumnSchema().Select(column => new DbColumnWrapper(column)).ToArray();
HasLongColumns = Columns.Any(column => column.IsLong); HasLongColumns = Columns.Any(column => column.IsLong.HasValue && column.IsLong.Value);
} }
#region Properties #region Properties