mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
13159 Created SetDatabaseName in KustoClient to take database name from ( ). Changed ListDatabases in Kusto ConnnectionService to set DatabaseNames in a different format when the PrettyName doesn't match the name. (#1123)
This commit is contained in:
@@ -793,7 +793,8 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
|
|||||||
ListDatabasesResponse response = new ListDatabasesResponse();
|
ListDatabasesResponse response = new ListDatabasesResponse();
|
||||||
|
|
||||||
// Mainly used by "manage" dashboard
|
// Mainly used by "manage" dashboard
|
||||||
if(listDatabasesParams.IncludeDetails.HasTrue()){
|
if (listDatabasesParams.IncludeDetails.HasTrue())
|
||||||
|
{
|
||||||
IEnumerable<DataSourceObjectMetadata> databaseMetadataInfo = dataSource.GetChildObjects(objectMetadata, true);
|
IEnumerable<DataSourceObjectMetadata> databaseMetadataInfo = dataSource.GetChildObjects(objectMetadata, true);
|
||||||
List<DatabaseInfo> metadata = MetadataFactory.ConvertToDatabaseInfo(databaseMetadataInfo);
|
List<DatabaseInfo> metadata = MetadataFactory.ConvertToDatabaseInfo(databaseMetadataInfo);
|
||||||
response.Databases = metadata.ToArray();
|
response.Databases = metadata.ToArray();
|
||||||
@@ -802,7 +803,13 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
|
|||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<DataSourceObjectMetadata> databaseMetadata = dataSource.GetChildObjects(objectMetadata);
|
IEnumerable<DataSourceObjectMetadata> databaseMetadata = dataSource.GetChildObjects(objectMetadata);
|
||||||
if(databaseMetadata != null) response.DatabaseNames = databaseMetadata.Select(objMeta => objMeta.PrettyName).ToArray();
|
if (databaseMetadata != null)
|
||||||
|
{
|
||||||
|
response.DatabaseNames = databaseMetadata
|
||||||
|
.Select(objMeta => objMeta.PrettyName == objMeta.Name ? objMeta.PrettyName : $"{objMeta.PrettyName} ({objMeta.Name})")
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kusto.Cloud.Platform.Data;
|
using Kusto.Cloud.Platform.Data;
|
||||||
@@ -42,11 +43,23 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource
|
|||||||
{
|
{
|
||||||
_ownerUri = ownerUri;
|
_ownerUri = ownerUri;
|
||||||
ClusterName = GetClusterName(connectionString);
|
ClusterName = GetClusterName(connectionString);
|
||||||
DatabaseName = new SqlConnectionStringBuilder(connectionString).InitialCatalog;
|
|
||||||
|
var dbName = new SqlConnectionStringBuilder(connectionString).InitialCatalog;
|
||||||
|
SetDatabaseName(dbName);
|
||||||
|
|
||||||
Initialize(ClusterName, DatabaseName, azureAccountToken);
|
Initialize(ClusterName, DatabaseName, azureAccountToken);
|
||||||
SchemaState = LoadSchemaState();
|
SchemaState = LoadSchemaState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetDatabaseName(string databaseName)
|
||||||
|
{
|
||||||
|
var regex = new Regex(@"(?<=\().+?(?=\))");
|
||||||
|
|
||||||
|
DatabaseName = regex.IsMatch(databaseName)
|
||||||
|
? regex.Match(databaseName).Value
|
||||||
|
: databaseName;
|
||||||
|
}
|
||||||
|
|
||||||
private GlobalState LoadSchemaState()
|
private GlobalState LoadSchemaState()
|
||||||
{
|
{
|
||||||
IEnumerable<ShowDatabaseSchemaResult> tableSchemas = Enumerable.Empty<ShowDatabaseSchemaResult>();
|
IEnumerable<ShowDatabaseSchemaResult> tableSchemas = Enumerable.Empty<ShowDatabaseSchemaResult>();
|
||||||
@@ -297,7 +310,7 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource
|
|||||||
|
|
||||||
public void UpdateDatabase(string databaseName)
|
public void UpdateDatabase(string databaseName)
|
||||||
{
|
{
|
||||||
DatabaseName = databaseName;
|
SetDatabaseName(databaseName);
|
||||||
SchemaState = LoadSchemaState();
|
SchemaState = LoadSchemaState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user