SQL Server
SQL Server
Example: Crypt2.EncodeString method
Demonstrates how to call the EncodeString method.Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @crypt int
EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @s nvarchar(4000)
SELECT @s = 'Hello World'
EXEC sp_OAMethod @crypt, 'EncodeString', @sTmp0 OUT, @s, 'utf-8', 'hex'
PRINT @sTmp0
-- Output: 48656C6C6F20576F726C64
EXEC sp_OAMethod @crypt, 'EncodeString', @sTmp0 OUT, @s, 'utf-16', 'hex'
PRINT @sTmp0
-- Output: 480065006C006C006F00200057006F0072006C006400
EXEC sp_OAMethod @crypt, 'EncodeString', @sTmp0 OUT, @s, 'utf-8', 'base64'
PRINT @sTmp0
-- Output: SGVsbG8gV29ybGQ=
SELECT @s = 'électricité'
EXEC sp_OAMethod @crypt, 'EncodeString', @sTmp0 OUT, @s, 'utf-8', 'hex'
PRINT @sTmp0
-- Output: C3A96C6563747269636974C3A9
EXEC sp_OAMethod @crypt, 'EncodeString', @sTmp0 OUT, @s, 'windows-1252', 'hex'
PRINT @sTmp0
-- Output: E96C6563747269636974E9
EXEC sp_OAMethod @crypt, 'EncodeString', @sTmp0 OUT, @s, 'windows-1252', 'hex_lower'
PRINT @sTmp0
-- Output: e96c6563747269636974e9
EXEC sp_OAMethod @crypt, 'EncodeString', @sTmp0 OUT, @s, 'utf-8', 'url'
PRINT @sTmp0
-- Output: %C3%A9lectricit%C3%A9
EXEC @hr = sp_OADestroy @crypt
END
GO