mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
fixed the bug with not closing data reader for oe (#352)
* fixed the bug with not closing data reader for oe * fixed the bug with triggers not sending back status
This commit is contained in:
@@ -23,18 +23,23 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
|
|
||||||
public override IEnumerable<TreeNode> Expand(TreeNode parent, bool refresh)
|
public override IEnumerable<TreeNode> Expand(TreeNode parent, bool refresh)
|
||||||
{
|
{
|
||||||
|
List<TreeNode> allChildren = new List<TreeNode>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<TreeNode> allChildren = new List<TreeNode>();
|
|
||||||
OnExpandPopulateFolders(allChildren, parent);
|
OnExpandPopulateFolders(allChildren, parent);
|
||||||
RemoveFoldersFromInvalidSqlServerVersions(allChildren, parent);
|
RemoveFoldersFromInvalidSqlServerVersions(allChildren, parent);
|
||||||
OnExpandPopulateNonFolders(allChildren, parent, refresh);
|
OnExpandPopulateNonFolders(allChildren, parent, refresh);
|
||||||
OnBeginAsyncOperations(parent);
|
OnBeginAsyncOperations(parent);
|
||||||
return allChildren;
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Write(LogLevel.Error, $"Failed expanding oe children. error:{ex.Message} {ex.StackTrace}");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
return allChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
public abstract class SmoQuerier : IComposableService
|
public abstract class SmoQuerier : IComposableService
|
||||||
{
|
{
|
||||||
public abstract Type[] SupportedObjectTypes { get; }
|
public abstract Type[] SupportedObjectTypes { get; }
|
||||||
|
private static object lockObject = new object();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queries SMO for a collection of objects using the <see cref="SmoQueryContext"/>
|
/// Queries SMO for a collection of objects using the <see cref="SmoQueryContext"/>
|
||||||
@@ -78,21 +79,26 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected HashSet<string> GetUrns(EnumResult enumResult)
|
protected HashSet<string> GetUrns(EnumResult enumResult)
|
||||||
{
|
{
|
||||||
HashSet<string> urns = null;
|
lock (lockObject)
|
||||||
if (enumResult != null && enumResult.Data != null)
|
|
||||||
{
|
{
|
||||||
urns = new HashSet<string>();
|
HashSet<string> urns = null;
|
||||||
IDataReader reader = GetDataReader(enumResult.Data);
|
if (enumResult != null && enumResult.Data != null)
|
||||||
if (reader != null)
|
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
urns = new HashSet<string>();
|
||||||
|
using (IDataReader reader = GetDataReader(enumResult.Data))
|
||||||
{
|
{
|
||||||
urns.Add(reader.GetString(0));
|
if (reader != null)
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
urns.Add(reader.GetString(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return urns;
|
return urns;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,14 +10,27 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Status for triggers
|
/// Status for triggers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SmoTriggerCustomNode
|
internal partial class TriggersChildFactory : SmoChildFactoryBase
|
||||||
{
|
{
|
||||||
internal partial class TriggersChildFactory : SmoChildFactoryBase
|
public override string GetNodeStatus(object context)
|
||||||
{
|
{
|
||||||
public override string GetNodeStatus(object context)
|
return TriggersCustomeNodeHelper.GetStatus(context);
|
||||||
{
|
}
|
||||||
return TriggersCustomeNodeHelper.GetStatus(context);
|
}
|
||||||
}
|
|
||||||
|
internal partial class ServerLevelServerTriggersChildFactory : SmoChildFactoryBase
|
||||||
|
{
|
||||||
|
public override string GetNodeStatus(object context)
|
||||||
|
{
|
||||||
|
return TriggersCustomeNodeHelper.GetStatus(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal partial class DatabaseTriggersChildFactory : SmoChildFactoryBase
|
||||||
|
{
|
||||||
|
public override string GetNodeStatus(object context)
|
||||||
|
{
|
||||||
|
return TriggersCustomeNodeHelper.GetStatus(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +47,24 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerDdlTrigger serverDdlTrigger = context as ServerDdlTrigger;
|
||||||
|
if (serverDdlTrigger != null)
|
||||||
|
{
|
||||||
|
if (!serverDdlTrigger.IsEnabled)
|
||||||
|
{
|
||||||
|
return "Disabled";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DatabaseDdlTrigger databaseDdlTrigger = context as DatabaseDdlTrigger;
|
||||||
|
if (databaseDdlTrigger != null)
|
||||||
|
{
|
||||||
|
if (!databaseDdlTrigger.IsEnabled)
|
||||||
|
{
|
||||||
|
return "Disabled";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,42 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void VerifyServerTriggers()
|
||||||
|
{
|
||||||
|
var query = @"IF EXISTS (SELECT * FROM sys.server_triggers WHERE name = 'OE_ddl_trig_database')
|
||||||
|
|
||||||
|
Begin
|
||||||
|
DROP TRIGGER OE_ddl_trig_database ON ALL SERVER
|
||||||
|
|
||||||
|
ENd
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE TRIGGER OE_ddl_trig_database
|
||||||
|
ON ALL SERVER
|
||||||
|
FOR CREATE_DATABASE
|
||||||
|
AS
|
||||||
|
PRINT 'Database Created.'
|
||||||
|
GO
|
||||||
|
GO
|
||||||
|
Disable TRIGGER OE_ddl_trig_database ON ALL SERVER ;";
|
||||||
|
string databaseName = "tempdb";
|
||||||
|
await RunTest(databaseName, query, "TepmDb", async (testDbName, session) =>
|
||||||
|
{
|
||||||
|
var serverChildren = await _service.ExpandNode(session, session.Root.GetNodePath());
|
||||||
|
var serverObjectsNode = serverChildren.FirstOrDefault(x => x.Label == SR.SchemaHierarchy_ServerObjects);
|
||||||
|
var serverObjectsChildren = await _service.ExpandNode(session, serverObjectsNode.NodePath);
|
||||||
|
var triggersNode = serverObjectsChildren.FirstOrDefault(x => x.Label == SR.SchemaHierarchy_Triggers);
|
||||||
|
var triggersChildren = await _service.ExpandNode(session, triggersNode.NodePath);
|
||||||
|
var trigger = triggersChildren.FirstOrDefault(x => x.Label == "OE_ddl_trig_database");
|
||||||
|
Assert.NotNull(trigger);
|
||||||
|
|
||||||
|
Assert.True(trigger.NodeStatus == "Disabled");
|
||||||
|
await TestServiceProvider.Instance.RunQueryAsync(TestServerType.OnPrem, testDbName, "DROP TRIGGER OE_ddl_trig_database");
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void CreateSessionAndExpandOnTheDatabaseShouldReturnDatabaseAsTheRoot()
|
public async void CreateSessionAndExpandOnTheDatabaseShouldReturnDatabaseAsTheRoot()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user