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 - Delete Bucket (REST API)

Deletes an Amazon S3 bucket using the REST API. This example deletes the bucket named "chilkat3".

Download Chilkat XML ActiveX

Download Chilkat Crypt ActiveX

Download Chilkat HTTP ActiveX

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 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

    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

    --  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

    --  Delete the bucket named "chilkat3"
    DECLARE @strToSign nvarchar(4000)

ERROR-CONCAT    SELECT @strToSign = 'DELETE' + CHAR(10) + CHAR(10) + CHAR(10) + @curDateTime + CHAR(10) + '/chilkat3/'

    --  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 = 'zzzzzzzzzzzzzzzzzzzzzzzzzzz'

    --  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 deleted is specified in the Host header.
    --  In this example, the "chilkat3" bucket is deleted
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Host', 'chilkat3.s3.amazonaws.com'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', @authValue
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Date', @curDateTime

    --  Send the DELETE request.
    DECLARE @responseStr nvarchar(4000)

    EXEC sp_OAMethod @http, 'QuickDeleteStr', @responseStr OUT, 'http://s3.amazonaws.com/'

    IF @responseStr 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 response string, and
        --  a response status of 204.
        EXEC sp_OAGetProperty @http, 'LastStatus', @sTmp0 OUT
        IF @sTmp0 = 204
          BEGIN
            PRINT 'Bucket deleted!'

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

            PRINT @sTmp0

          END
        ELSE
          BEGIN

            --  Is this a temporary redirect?
            EXEC sp_OAGetProperty @http, 'LastStatus', @sTmp0 OUT
            IF @sTmp0 = 307
              BEGIN

                --  The new endpoint is in the XML contained within responseStr.
                DECLARE @xml int
                EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml OUT
                IF @hr <> 0
                BEGIN
                    PRINT 'Failed to create ActiveX component'
                    RETURN
                END

                EXEC sp_OAMethod @xml, 'LoadXml', NULL, @responseStr
                DECLARE @endpoint nvarchar(4000)

                EXEC sp_OAMethod @xml, 'GetChildContent', @endpoint OUT, 'Endpoint'
                EXEC sp_OAMethod @http, 'QuickDeleteStr', @responseStr OUT, @endpoint
                EXEC sp_OAGetProperty @http, 'LastStatus', @sTmp0 OUT
                IF @sTmp0 = 204
                  BEGIN
                    PRINT 'Bucket deleted after redirect!'

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

                    PRINT @sTmp0

                  END
                ELSE
                  BEGIN
                    --  What happened???

                    EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT

                    PRINT 'LastStatus: ' + @iTmp0

                    PRINT '---'

                    PRINT @responseStr

                    PRINT '---'
                    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
            ELSE
              BEGIN
                --  What response is this???

                EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT

                PRINT 'LastStatus: ' + @iTmp0

                PRINT '---'

                PRINT @responseStr

                PRINT '---'
                --  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
END
GO

 

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