mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-16 09:35:36 -05:00
load the schema information (#1274)
* load the schema information * pr comments
This commit is contained in:
@@ -6,7 +6,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||
using Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts;
|
||||
|
||||
@@ -17,6 +19,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
/// </summary>
|
||||
public sealed class TableDesignerService : IDisposable
|
||||
{
|
||||
// The query is copied from SSMS table designer, sys and INFORMATION_SCHEMA can not be selected.
|
||||
const string GetSchemasQuery = "select name from sys.schemas where principal_id <> 3 and principal_id <> 4 order by name";
|
||||
|
||||
private bool disposed = false;
|
||||
private static readonly Lazy<TableDesignerService> instance = new Lazy<TableDesignerService>(() => new TableDesignerService());
|
||||
|
||||
@@ -59,15 +64,15 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO: populate the data and view information
|
||||
TableViewModel tableModel = new TableViewModel();
|
||||
TableDesignerView view = new TableDesignerView();
|
||||
var schemas = this.GetSchemas(tableInfo);
|
||||
var viewModel = this.GetTableViewModel(tableInfo, schemas);
|
||||
var view = this.GetDesignerViewInfo(tableInfo);
|
||||
await requestContext.SendResult(new TableDesignerInfo()
|
||||
{
|
||||
ViewModel = tableModel,
|
||||
ViewModel = viewModel,
|
||||
View = view,
|
||||
ColumnTypes = this.GetSupportedColumnTypes(tableInfo),
|
||||
Schemas = this.GetSchemas(tableInfo)
|
||||
Schemas = schemas
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -170,10 +175,46 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
return columnTypes;
|
||||
}
|
||||
|
||||
private TableViewModel GetTableViewModel(TableInfo tableInfo, List<string> schemas)
|
||||
{
|
||||
var tableViewModel = new TableViewModel();
|
||||
// Schema
|
||||
if (tableInfo.IsNewTable)
|
||||
{
|
||||
tableViewModel.Schema.Value = schemas.Contains("dbo") ? "dbo" : schemas[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
tableViewModel.Schema.Value = tableInfo.Schema;
|
||||
}
|
||||
|
||||
// Table Name
|
||||
if (!tableInfo.IsNewTable)
|
||||
{
|
||||
tableViewModel.Name.Value = tableInfo.Name;
|
||||
}
|
||||
|
||||
// TODO: set other properties of the table
|
||||
return tableViewModel;
|
||||
}
|
||||
|
||||
private TableDesignerView GetDesignerViewInfo(TableInfo tableInfo)
|
||||
{
|
||||
// TODO: set the view information
|
||||
var view = new TableDesignerView();
|
||||
return view;
|
||||
}
|
||||
|
||||
private List<string> GetSchemas(TableInfo tableInfo)
|
||||
{
|
||||
//TODO: get the schemas.
|
||||
var schemas = new List<string>();
|
||||
ReliableConnectionHelper.ExecuteReader(tableInfo.ConnectionString, GetSchemasQuery, (reader) =>
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
schemas.Add(reader[0].ToString());
|
||||
}
|
||||
});
|
||||
return schemas;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user