mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-19 17:23:55 -05:00
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
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Linq;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides metadata about the table or view being edited
|
||||
/// </summary>
|
||||
public class EditTableMetadata
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs a simple edit table metadata provider
|
||||
/// </summary>
|
||||
public EditTableMetadata()
|
||||
{
|
||||
HasExtendedProperties = false;
|
||||
}
|
||||
|
||||
#region Basic Properties (properties provided by SMO)
|
||||
|
||||
/// <summary>
|
||||
/// List of columns in the object being edited
|
||||
/// </summary>
|
||||
public EditColumnMetadata[] Columns { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Full escaped multipart identifier for the object being edited
|
||||
/// </summary>
|
||||
public string EscapedMultipartName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the object being edited is memory optimized
|
||||
/// </summary>
|
||||
public bool IsMemoryOptimized { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Extended Properties (properties provided by SqlClient)
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the table has had extended properties added to it
|
||||
/// </summary>
|
||||
public bool HasExtendedProperties { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of columns that are used to uniquely identify a row
|
||||
/// </summary>
|
||||
public EditColumnMetadata[] KeyColumns { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Extracts extended column properties from the database columns from SQL Client
|
||||
/// </summary>
|
||||
/// <param name="dbColumnWrappers">The column information provided by SQL Client</param>
|
||||
public void Extend(DbColumnWrapper[] dbColumnWrappers)
|
||||
{
|
||||
Validate.IsNotNull(nameof(dbColumnWrappers), dbColumnWrappers);
|
||||
|
||||
// Iterate over the column wrappers and improve the columns we have
|
||||
for (int i = 0; i < Columns.Length; i++)
|
||||
{
|
||||
Columns[i].Extend(dbColumnWrappers[i]);
|
||||
}
|
||||
|
||||
// Determine what the key columns are
|
||||
KeyColumns = Columns.Where(c => c.IsKey.HasTrue()).ToArray();
|
||||
if (KeyColumns.Length == 0)
|
||||
{
|
||||
// We didn't find any explicit key columns. Instead, we'll use all columns that are
|
||||
// trustworthy for uniqueness (usually all the columns)
|
||||
KeyColumns = Columns.Where(c => c.IsTrustworthyForUniqueness.HasTrue()).ToArray();
|
||||
}
|
||||
|
||||
// Mark that the table is now extended
|
||||
HasExtendedProperties = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user