Files
sqltoolsservice/src/Microsoft.SqlTools.ServiceLayer/EditData/EditColumnMetadata.cs
Benjamin Russell 16b3874f28 Remove SELECT * from edit/initialize Query (#288)
* Major refactor of EditDataMetadata providers

* EditMetadataFactory generates "basic" EditTableMetadata objects based entirely on SMO metadata
* SmoEditTableMetadata no longer depends on SMO, making it unecessary to mock it
* Renamed SmoEditTableMetadata to EditTableMetadata
* EditTableMetadata can be extended with DbColumnWrappers

* Moving logic for extending a EditColumnMetadata into that class

* I *think* this will work for async execution of initialize tasks

* Fixing unit tests for new Edit(Table|Column)Metadata classes

* Async stuff that works! And passes unit tests

* Adding unit tests
Adding .idea to gitignore

* Adding message to the EditSessionReadyEvent

* Fixes from dev merge

* Fixing unit tests that Rider didn't catch as failing
May have been a bit heavy-handed with the async/await stuff

* Couple changes as per PR comments
2017-03-22 10:53:24 -07:00

114 lines
3.7 KiB
C#

//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Data;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ServiceLayer.EditData
{
/// <summary>
/// Small class that stores information needed by the edit data service to properly process
/// edits into scripts.
/// </summary>
public class EditColumnMetadata
{
/// <summary>
/// Constructs a simple edit column metadata provider
/// </summary>
public EditColumnMetadata()
{
HasExtendedProperties = false;
}
#region Basic Properties (properties provided by SMO)
/// <summary>
/// If set, this is a string representation of the default value. If set to null, then the
/// column does not have a default value.
/// </summary>
public string DefaultValue { get; set; }
/// <summary>
/// Escaped identifier for the name of the column
/// </summary>
public string EscapedName { get; set; }
/// <summary>
/// Whether or not the column is computed
/// </summary>
public bool IsComputed { get; set; }
/// <summary>
/// Whether or not the column is deterministically computed
/// </summary>
public bool IsDeterministic { get; set; }
/// <summary>
/// Whether or not the column is an identity column
/// </summary>
public bool IsIdentity { get; set; }
/// <summary>
/// The ordinal ID of the column
/// </summary>
public int Ordinal { get; set; }
#endregion
#region Extended Properties (properties provided by SqlClient)
public DbColumnWrapper DbColumn { get; private set; }
/// <summary>
/// Whether or not the column has extended properties
/// </summary>
public bool HasExtendedProperties { get; private set; }
/// <summary>
/// Whether or not the column is calculated on the server side. This could be a computed
/// column or a identity column.
/// </summary>
public bool? IsCalculated { get; private set; }
/// <summary>
/// Whether or not the column is used in a key to uniquely identify a row
/// </summary>
public bool? IsKey { get; private set; }
/// <summary>
/// Whether or not the column can be trusted for uniqueness
/// </summary>
public bool? IsTrustworthyForUniqueness { get; private set; }
#endregion
/// <summary>
/// Extracts extended column properties from the database columns from SQL Client
/// </summary>
/// <param name="dbColumn">The column information provided by SQL Client</param>
public void Extend(DbColumnWrapper dbColumn)
{
Validate.IsNotNull(nameof(dbColumn), dbColumn);
DbColumn = dbColumn;
// A column is trustworthy for uniqueness if it can be updated or it has an identity
// property. If both of these are false (eg, timestamp) we can't trust it to uniquely
// identify a row in the table
IsTrustworthyForUniqueness = dbColumn.IsUpdatable || dbColumn.IsIdentity.HasTrue();
// A key column is determined by whether it is a key
IsKey = dbColumn.IsKey;
// A column is calculated if it is identity, computed, or otherwise not updatable
IsCalculated = IsIdentity || IsComputed || !dbColumn.IsUpdatable;
// Mark the column as extended
HasExtendedProperties = true;
}
}
}