SQL Server Stored Procedure Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

SQL Server
Stored Procedure Examples

Quick Start
Encryption
File Access
IMAP
POP3
SMTP
Email Object
DKIM / DomainKey
FTP
HTML Conversion
HTTP
MHT
MIME
NTLM
RSA
Diffie-Hellman
DSA
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
String
Tar
Upload
XML
XMP
Zip

Amazon S3
Bz2
CSV
FileAccess
Byte Array
RSS
Atom
Self-Extractor

Amazon S3 - Create Bucket with PUT Request

Demonstrates how to create an Amazon S3 bucket by sending a PUT HTTP request.

Download Chilkat Crypt ActiveX

Download Chilkat HTTP ActiveX

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OAMethod @http, 'UnlockComponent', @success OUT, 'Anything for 30-day trial.'
    IF @success <> 1
      BEGIN
        --  Unlock failed.
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    --  The HTTP component now includes a method to generate
    --  the current date/time in RFC 2616 compliant format.
    --  Note: The GenTimeStamp method is available as a pre-release (as of 18-June-2008).
    --  It will become available in the next new version dated after
    --  18-June-2008.
    DECLARE @curDateTime nvarchar(4000)

    EXEC sp_OAMethod @http, 'GenTimeStamp', @curDateTime OUT

    PRINT @curDateTime

    --  The PUT request operation with a bucket URI creates a new bucket.
    DECLARE @strToSign nvarchar(4000)

ERROR-CONCAT    SELECT @strToSign = 'PUT' + CHAR(10) + CHAR(10) + CHAR(10) + @curDateTime + CHAR(10) + '/chilkat/'

    DECLARE @crypt int
    EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @crypt, 'UnlockComponent', @success OUT, 'Anything for 30-day trial.'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    --  We want SHA1 for the HMAC hash algorithm:
    EXEC sp_OASetProperty @crypt, 'HashAlgorithm', 'sha1'

    --  These must be changed for your account:
    DECLARE @AWSAccessKeyId nvarchar(4000)

    SELECT @AWSAccessKeyId = 'zzzzzzzzzzzzzzzzzzzzz'
    DECLARE @AWSSecretAccessKey nvarchar(4000)

    SELECT @AWSSecretAccessKey = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzz'

    --  Set the HMAC secret key:
    EXEC sp_OAMethod @crypt, 'SetHmacKeyString', NULL, @AWSSecretAccessKey

    --  By setting the charset = "utf-8", the string will be converted
    --  to utf-8 (internal to the Chilkat component) prior to signing:
    EXEC sp_OASetProperty @crypt, 'Charset', 'utf-8'

    --  Indicate that Base64 output is desired:
    EXEC sp_OASetProperty @crypt, 'EncodingMode', 'base64'

    DECLARE @signature nvarchar(4000)

    EXEC sp_OAMethod @crypt, 'HmacStringENC', @signature OUT, @strToSign

    DECLARE @authValue nvarchar(4000)

ERROR-CONCAT    SELECT @authValue = 'AWS ' + @AWSAccessKeyId + ':' + @signature

    --  The bucket to be created is specified in the Host header.
    --  In this example, the "chilkat" bucket is created:
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Host', 'chilkat.s3.amazonaws.com'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', @authValue
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Date', @curDateTime
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Length', '0'

    DECLARE @xmlResponse nvarchar(4000)

    EXEC sp_OAMethod @http, 'QuickPutStr', @xmlResponse OUT, 'http://s3.amazonaws.com/'
    IF @xmlResponse Is NULL 
      BEGIN
        --  Failed.  Show the last request header, response header,
        --  and response body.
        EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT

        PRINT @sTmp0

        PRINT '---'
        EXEC sp_OAGetProperty @http, 'LastResponseHeader', @sTmp0 OUT

        PRINT @sTmp0

        PRINT '---'
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT

        PRINT @sTmp0
      END
    ELSE
      BEGIN

        --  Success is indicated by an empty xmlResponse string, and
        --  a response status of 200.
        EXEC sp_OAGetProperty @http, 'LastStatus', @sTmp0 OUT
        IF @sTmp0 = 200
          BEGIN
            PRINT 'Bucket created!'

            --  Let's check out the response header anyway...
            EXEC sp_OAGetProperty @http, 'LastResponseHeader', @sTmp0 OUT

            PRINT @sTmp0

          END
        ELSE
          BEGIN
            --  Failed.  Show the last request header, response header,
            --  and response body.
            EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT

            PRINT @sTmp0

            PRINT '---'
            EXEC sp_OAGetProperty @http, 'LastResponseHeader', @sTmp0 OUT

            PRINT @sTmp0

            PRINT '---'
            EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT

            PRINT @sTmp0
          END

      END
END
GO

 

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.