mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-09 01:32:38 -05:00
Binary file not shown.
BIN
bin/nuget/Microsoft.SqlServer.Smo.140.2.9.nupkg
Normal file
BIN
bin/nuget/Microsoft.SqlServer.Smo.140.2.9.nupkg
Normal file
Binary file not shown.
@@ -19,7 +19,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.8" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.9" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.0.0" />
|
||||
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
<Reference Include="System.Data.SqlClient" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.8" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.9" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="**\*.cs" />
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts
|
||||
Insert = 2,
|
||||
Update = 3,
|
||||
Delete = 4,
|
||||
Execute = 5
|
||||
Execute = 5,
|
||||
Alter = 6
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
||||
switch (this.Parameters.Operation)
|
||||
{
|
||||
case ScriptingOperationType.Create:
|
||||
case ScriptingOperationType.Alter:
|
||||
case ScriptingOperationType.Delete: // Using Delete here is wrong. delete usually means delete rows from table but sqlopsstudio sending the operation name as delete instead of drop
|
||||
resultScript = GenerateScriptAs(server, urns, options);
|
||||
break;
|
||||
@@ -438,6 +439,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
||||
try
|
||||
{
|
||||
scripter = new SqlServer.Management.Smo.Scripter(server);
|
||||
if(this.Parameters.Operation == ScriptingOperationType.Alter)
|
||||
{
|
||||
options.ScriptForAlter = true;
|
||||
foreach (var urn in urns)
|
||||
{
|
||||
SqlSmoObject smoObject = server.GetSmoObject(urn);
|
||||
|
||||
// without calling the toch method, no alter script get generated from smo
|
||||
smoObject.Touch();
|
||||
}
|
||||
}
|
||||
|
||||
scripter.Options = options;
|
||||
scripter.ScriptingError += ScripterScriptingError;
|
||||
|
||||
@@ -163,7 +163,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
||||
// To script Select, alter and execute use scripting as operation. The other operation doesn't support those types
|
||||
if( (parameters.ScriptingObjects != null && parameters.ScriptingObjects.Count == 1 && parameters.ScriptOptions != null
|
||||
&& parameters.ScriptOptions.TypeOfDataToScript == "SchemaOnly" && parameters.ScriptDestination == "ToEditor") ||
|
||||
parameters.Operation == ScriptingOperationType.Select || parameters.Operation == ScriptingOperationType.Execute)
|
||||
parameters.Operation == ScriptingOperationType.Select || parameters.Operation == ScriptingOperationType.Execute ||
|
||||
parameters.Operation == ScriptingOperationType.Alter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<PackageReference Include="xunit" Version="2.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.8" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.9" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
|
||||
@@ -12,6 +12,7 @@ using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Moq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
@@ -113,10 +114,51 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Scripting
|
||||
Type = "Table"
|
||||
};
|
||||
string expectedScript = null;
|
||||
|
||||
await VerifyScriptAs(query, scriptingObject, scriptCreateDrop, expectedScript);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void VerifyScriptAsAlter()
|
||||
{
|
||||
string query = @"CREATE PROCEDURE testSp1 @StartProductID [int] AS BEGIN Select * from sys.all_columns END
|
||||
GO
|
||||
CREATE VIEW testView1 AS SELECT * from sys.all_columns
|
||||
GO
|
||||
CREATE FUNCTION testFun1() RETURNS [int] AS BEGIN RETURN 1 END
|
||||
GO";
|
||||
ScriptingOperationType scriptCreateDrop = ScriptingOperationType.Alter;
|
||||
|
||||
List<ScriptingObject> scriptingObjects = new List<ScriptingObject>
|
||||
{
|
||||
new ScriptingObject
|
||||
{
|
||||
Name = "testSp1",
|
||||
Schema = "dbo",
|
||||
Type = "StoredProcedure"
|
||||
},
|
||||
new ScriptingObject
|
||||
{
|
||||
Name = "testView1",
|
||||
Schema = "dbo",
|
||||
Type = "View"
|
||||
},
|
||||
new ScriptingObject
|
||||
{
|
||||
Name = "testFun1",
|
||||
Schema = "dbo",
|
||||
Type = "UserDefinedFunction"
|
||||
}
|
||||
};
|
||||
List<string> expectedScripts = new List<string>
|
||||
{
|
||||
"ALTER PROCEDURE [dbo].[testSp1]",
|
||||
"ALTER VIEW [dbo].[testView1]",
|
||||
"ALTER FUNCTION [dbo].[testFun1]"
|
||||
};
|
||||
|
||||
await VerifyScriptAsForMultipleObjects(query, scriptingObjects, scriptCreateDrop, expectedScripts);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void VerifyScriptAsExecuteStoredProcedure()
|
||||
{
|
||||
@@ -238,6 +280,11 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Scripting
|
||||
}
|
||||
|
||||
private async Task VerifyScriptAs(string query, ScriptingObject scriptingObject, ScriptingOperationType operation, string expectedScript)
|
||||
{
|
||||
await VerifyScriptAsForMultipleObjects(query, new List<ScriptingObject> { scriptingObject }, operation, new List<string> { expectedScript });
|
||||
}
|
||||
|
||||
private async Task VerifyScriptAsForMultipleObjects(string query, List<ScriptingObject> scriptingObjects, ScriptingOperationType operation, List<string> expectedScripts)
|
||||
{
|
||||
var testDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, query, "ScriptingTests");
|
||||
try
|
||||
@@ -271,10 +318,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Scripting
|
||||
ScriptCreateDrop = scriptCreateOperation,
|
||||
};
|
||||
|
||||
scriptingParams.ScriptingObjects = new List<ScriptingObject>
|
||||
{
|
||||
scriptingObject
|
||||
};
|
||||
scriptingParams.ScriptingObjects = scriptingObjects;
|
||||
|
||||
|
||||
ScriptingService service = new ScriptingService();
|
||||
@@ -282,7 +326,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Scripting
|
||||
Thread.Sleep(2000);
|
||||
await service.ScriptingTask;
|
||||
|
||||
requestContext.Verify(x => x.SendResult(It.Is<ScriptingResult>(r => VerifyScriptingResult(r, expectedScript))));
|
||||
requestContext.Verify(x => x.SendResult(It.Is<ScriptingResult>(r => VerifyScriptingResult(r, expectedScripts))));
|
||||
connectionService.Disconnect(new ServiceLayer.Connection.Contracts.DisconnectParams
|
||||
{
|
||||
OwnerUri = queryTempFile.FilePath
|
||||
@@ -299,9 +343,21 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Scripting
|
||||
}
|
||||
}
|
||||
|
||||
private static bool VerifyScriptingResult(ScriptingResult result, string expected)
|
||||
private static bool VerifyScriptingResult(ScriptingResult result, List<string> expectedScripts)
|
||||
{
|
||||
return string.IsNullOrEmpty(expected) ? string.IsNullOrEmpty(result.Script) : !string.IsNullOrEmpty(result.Script) && result.Script.Contains(expected);
|
||||
if (expectedScripts == null || (expectedScripts.Count > 0 && expectedScripts.All(x => x == null)))
|
||||
{
|
||||
return string.IsNullOrEmpty(result.Script);
|
||||
}
|
||||
|
||||
foreach (string expectedScript in expectedScripts)
|
||||
{
|
||||
if (!result.Script.Contains(expectedScript))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<PackageReference Include="xunit" Version="2.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.8" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.9" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Scripts/CreateTestDatabaseObjects.sql" />
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<PackageReference Include="xunit" Version="2.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.8" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.9" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../src/Microsoft.SqlTools.Hosting/Microsoft.SqlTools.Hosting.csproj" />
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<PackageReference Include="xunit" Version="2.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.8" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.9" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
|
||||
Reference in New Issue
Block a user