mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Replace <default> values in Owner and Collation fields for Create Database dialog (#2086)
This commit is contained in:
@@ -151,11 +151,19 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
if (dataContainer.Server.ServerType != DatabaseEngineType.SqlAzureDatabase)
|
if (dataContainer.Server.ServerType != DatabaseEngineType.SqlAzureDatabase)
|
||||||
{
|
{
|
||||||
var logins = new List<string>();
|
var logins = new List<string>();
|
||||||
logins.Add(SR.general_default);
|
|
||||||
foreach (Login login in dataContainer.Server.Logins)
|
foreach (Login login in dataContainer.Server.Logins)
|
||||||
{
|
{
|
||||||
logins.Add(login.Name);
|
logins.Add(login.Name);
|
||||||
}
|
}
|
||||||
|
// If we don't have a default database owner, then move the current login to the front of the list to use as the default.
|
||||||
|
string firstOwner = prototype.Exists ? prototype.Owner : dataContainer.Server.ConnectionContext.TrueLogin;
|
||||||
|
int swapIndex = logins.FindIndex(login => login.Equals(firstOwner, StringComparison.InvariantCultureIgnoreCase));
|
||||||
|
if (swapIndex > 0)
|
||||||
|
{
|
||||||
|
logins.RemoveAt(swapIndex);
|
||||||
|
logins.Insert(0, firstOwner);
|
||||||
|
}
|
||||||
|
|
||||||
databaseViewInfo.LoginNames = logins.ToArray();
|
databaseViewInfo.LoginNames = logins.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,11 +262,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (database.Owner != null && database.Owner != SR.general_default)
|
if (database.Owner != null)
|
||||||
{
|
{
|
||||||
prototype.Owner = database.Owner;
|
prototype.Owner = database.Owner;
|
||||||
}
|
}
|
||||||
if (database.CollationName != null && database.CollationName != SR.general_default)
|
if (database.CollationName != null)
|
||||||
{
|
{
|
||||||
prototype.Collation = database.CollationName;
|
prototype.Collation = database.CollationName;
|
||||||
}
|
}
|
||||||
@@ -314,12 +322,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
var collationItems = new List<string>();
|
var collationItems = new List<string>();
|
||||||
bool isSphinxServer = (server.VersionMajor < minimumVersionForWritableCollation);
|
bool isSphinxServer = (server.VersionMajor < minimumVersionForWritableCollation);
|
||||||
|
|
||||||
// if we're creating a new database or this is a Sphinx Server, add "<default>" to the list
|
|
||||||
if (isNewObject || isSphinxServer)
|
|
||||||
{
|
|
||||||
collationItems.Add(SR.general_default);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the server is shiloh or later, add specific collations to the list
|
// if the server is shiloh or later, add specific collations to the list
|
||||||
if (!isSphinxServer)
|
if (!isSphinxServer)
|
||||||
{
|
{
|
||||||
@@ -334,15 +336,14 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prototype.Exists)
|
// If this database already exists, then put its collation at the front of the list.
|
||||||
|
// Otherwise use the server's collation as the default first value.
|
||||||
|
string firstCollation = prototype.Exists ? prototype.Collation : server.Collation;
|
||||||
|
int index = collationItems.FindIndex(collation => collation.Equals(firstCollation, StringComparison.InvariantCultureIgnoreCase));
|
||||||
|
if (index > 0)
|
||||||
{
|
{
|
||||||
// Put the prototype's current collation at the front of the list
|
collationItems.RemoveAt(index);
|
||||||
int index = collationItems.FindIndex(collation => collation.Equals(prototype.Collation, StringComparison.InvariantCultureIgnoreCase));
|
collationItems.Insert(0, firstCollation);
|
||||||
if (index > 0)
|
|
||||||
{
|
|
||||||
collationItems.RemoveAt(index);
|
|
||||||
collationItems.Insert(0, prototype.Collation);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return collationItems.ToArray();
|
return collationItems.ToArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectManagement
|
|||||||
return new DatabaseInfo()
|
return new DatabaseInfo()
|
||||||
{
|
{
|
||||||
Name = "TestDatabaseName_" + new Random().NextInt64(10000000, 90000000).ToString(),
|
Name = "TestDatabaseName_" + new Random().NextInt64(10000000, 90000000).ToString(),
|
||||||
Owner = "<default>",
|
Owner = "sa",
|
||||||
CollationName = "SQL_Latin1_General_CP1_CI_AS",
|
CollationName = "SQL_Latin1_General_CP1_CI_AS",
|
||||||
CompatibilityLevel = "SQL Server 2022 (160)",
|
CompatibilityLevel = "SQL Server 2022 (160)",
|
||||||
ContainmentType = "None",
|
ContainmentType = "None",
|
||||||
|
|||||||
Reference in New Issue
Block a user