(SQL Server) Example: Crypt2.DecodeString method
Demonstrates how to call the DecodeString method.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @crypt2 int
EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt2 OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- The string "Hello World" in base64 (using the utf-8 byte representation) is "SGVsbG8gV29ybGQ="
DECLARE @encodedStr nvarchar(4000)
SELECT @encodedStr = 'SGVsbG8gV29ybGQ='
DECLARE @encoding nvarchar(4000)
SELECT @encoding = 'base64'
DECLARE @charset nvarchar(4000)
SELECT @charset = 'utf-8'
DECLARE @str nvarchar(4000)
EXEC sp_OAMethod @crypt2, 'DecodeString', @str OUT, @encodedStr, @charset, @encoding
PRINT @str
-- Output is "Hello World"
EXEC @hr = sp_OADestroy @crypt2
END
GO
|