mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
Merge pull request #1031 from dbrownems/master
Updated T4 template for SQL Script and misc fixes
This commit is contained in:
@@ -9,10 +9,16 @@ using System.Threading;
|
||||
/// </summary>
|
||||
public partial class Curl
|
||||
{
|
||||
static Curl()
|
||||
{
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
||||
}
|
||||
|
||||
[SqlFunction]
|
||||
[return: SqlFacet(MaxSize = -1)]
|
||||
public static SqlChars Get(SqlChars H, SqlChars url)
|
||||
{
|
||||
|
||||
var client = new WebClient();
|
||||
AddHeader(H, client);
|
||||
return new SqlChars(
|
||||
@@ -24,6 +30,7 @@ public partial class Curl
|
||||
[SqlProcedure]
|
||||
public static void Post(SqlChars H, SqlChars d, SqlChars url)
|
||||
{
|
||||
|
||||
var client = new WebClient();
|
||||
AddHeader(H, client);
|
||||
if (d.IsNull)
|
||||
@@ -39,6 +46,7 @@ public partial class Curl
|
||||
[SqlProcedure]
|
||||
public static void PostWithRetry(SqlChars H, SqlChars d, SqlChars url)
|
||||
{
|
||||
|
||||
var client = new WebClient();
|
||||
AddHeader(H, client);
|
||||
if (d.IsNull)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SqlClr</RootNamespace>
|
||||
<AssemblyName>SqlClrCurl</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -24,27 +24,26 @@ SELECT @hash = hash
|
||||
FROM sys.trusted_assemblies ta
|
||||
WHERE ta.description = N'SqlClrCurl'
|
||||
|
||||
EXEC sp_drop_trusted_assembly @hash;
|
||||
if (@hash is not null)
|
||||
EXEC sp_drop_trusted_assembly @hash;
|
||||
GO
|
||||
|
||||
--Drop the assembly if it already exists
|
||||
DROP ASSEMBLY IF EXISTS SqlClrCurl;
|
||||
GO
|
||||
|
||||
|
||||
DECLARE @assembly VARBINARY(MAX) = <#= "0x" + BitConverter.ToString(System.IO.File.ReadAllBytes(this.Host.ResolvePath("bin\\Release\\SqlClrCurl.dll"))).Replace("-","") #>
|
||||
DECLARE @hash VARBINARY(64);
|
||||
SELECT @hash = HASHBYTES('SHA2_512', BulkColumn)
|
||||
FROM OPENROWSET(BULK '<#= this.Host.ResolvePath("bin\\Release\\SqlClrCurl.dll") #>', SINGLE_BLOB) AS assembly_content
|
||||
SELECT @hash = HASHBYTES('SHA2_512', @assembly)
|
||||
|
||||
IF(@hash IS NOT NULL)
|
||||
IF(not exists (select * from sys.trusted_assemblies where hash = @hash))
|
||||
EXEC sp_add_trusted_assembly @hash, N'SqlClrCurl'
|
||||
ELSE
|
||||
PRINT 'Cannot create hash for assembly!'
|
||||
GO
|
||||
print 'Hash already exists'
|
||||
|
||||
--Create the assembly
|
||||
CREATE ASSEMBLY SqlClrCurl
|
||||
FROM '<#= this.Host.ResolvePath("bin\\Release\\SqlClrCurl.dll") #>'
|
||||
FROM @assembly
|
||||
WITH PERMISSION_SET = EXTERNAL_ACCESS;
|
||||
GO
|
||||
|
||||
@@ -60,4 +59,4 @@ GO
|
||||
|
||||
CREATE PROCEDURE CURL.XPOST (@H NVARCHAR(MAX), @d NVARCHAR(MAX), @url NVARCHAR(4000))
|
||||
AS EXTERNAL NAME SqlClrCurl.Curl.Post;
|
||||
GO
|
||||
GO
|
||||
|
||||
Reference in New Issue
Block a user