SQL Server
SQL Server
Add a Query Parameter from a StringBuilder
See more REST Examples
Demonstrates Rest.AddQueryParamSb, which adds or replaces a query parameter whose value is read from a StringBuilder. The 1st argument is the name and the 2nd is the StringBuilder.
Background. This variant is convenient when the parameter value has already been assembled in a StringBuilder, avoiding an extra conversion to a plain string.
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
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @rest int
EXEC @hr = sp_OACreate 'Chilkat.Rest', @rest OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Connect to the REST server. The 3rd argument enables TLS (use 1 for HTTPS on port 443),
-- and the 4th enables automatic reconnection if the connection is dropped between requests.
DECLARE @bTls int
SELECT @bTls = 1
DECLARE @bAutoReconnect int
SELECT @bAutoReconnect = 1
EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'example.com', 443, @bTls, @bAutoReconnect
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
RETURN
END
-- The parameter value can also be supplied from a StringBuilder. The 1st argument is the name and
-- the 2nd is the StringBuilder holding the value.
DECLARE @sbValue int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbValue OUT
EXEC sp_OAMethod @sbValue, 'Append', @success OUT, 'chilkat rest'
EXEC sp_OAMethod @rest, 'AddQueryParamSb', @success OUT, 'q', @sbValue
DECLARE @responseText nvarchar(4000)
EXEC sp_OAMethod @rest, 'FullRequestNoBody', @responseText OUT, 'GET', '/api/search'
EXEC sp_OAGetProperty @rest, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @sbValue
RETURN
END
PRINT @responseText
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @sbValue
END
GO