Sample code for 30+ languages & platforms
SQL Server Requires Chilkat v11.7.0+

QR Code with Binary Data

See more QR Code Examples

Demonstrates a QR code that holds arbitrary bytes rather than text. The payload type is binary and the bytes are given as base64 in payload.base64. Any byte value may be used, including zero. Keep in mind that many phone camera apps expect text, so binary payloads are for readers that you control.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  This example requires the Chilkat API to have been previously unlocked.
    --  See Global Unlock Sample for sample code.

    --  The bytes to encode.  Here they come from hex, but they could be loaded from a file with LoadFile.
    DECLARE @bd int
    EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @bd, 'AppendEncoded', @success OUT, '000102030405FF00FE4368696C6B6174', 'hex'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @bd, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @bd
        RETURN
      END

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.type', 'binary'
    EXEC sp_OAMethod @bd, 'GetEncoded', @sTmp0 OUT, 'base64'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.base64', @sTmp0
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.path', 'qa_output/qr_binary.png'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'output.overwrite', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.return', 'none'

    DECLARE @fmt int
    EXEC @hr = sp_OACreate 'Chilkat.Formats', @fmt OUT

    DECLARE @jsonOut int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonOut OUT

    EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'generate', @json, @jsonOut
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @fmt, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @bd
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @fmt
        EXEC @hr = sp_OADestroy @jsonOut
        RETURN
      END


    EXEC sp_OAGetProperty @bd, 'NumBytes', @iTmp0 OUT
    PRINT 'bytes given: ' + @iTmp0

    EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].payloadBytes'
    PRINT 'bytes encoded: ' + @iTmp0

    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'symbols[0].selectedEncoding.mode'
    PRINT 'mode: ' + @sTmp0

    EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].selectedEncoding.version'
    PRINT 'QR version: ' + @iTmp0

    --  The image written to qa_output/qr_binary.png:

    --  image

    --  Sample output:

    --  bytes given: 16
    --  bytes encoded: 16
    --  mode: byte
    --  QR version: 2

    EXEC @hr = sp_OADestroy @bd
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @fmt
    EXEC @hr = sp_OADestroy @jsonOut


END
GO