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

Split Data across Several QR Codes (Structured Append)

See more QR Code Examples

Demonstrates structured append, the QR feature for data too large for one symbol of the size wanted. The data is divided over up to 16 symbols, and each carries its position, the total, and a parity byte that ties the set together. With encoding.structuredAppend.enabled, QrCode uses as few symbols as it can. output.pathTemplate writes one file per symbol, with {index} replaced by 1, 2, 3 and so on. The reader must support structured append to put the parts back together. Many phone camera apps do not, and show each part separately.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @iTmp1 int
    DECLARE @iTmp2 int
    DECLARE @iTmp3 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.

    --  Some text that is too long for one symbol of the size allowed below.
    DECLARE @sbText int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbText OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @i int

    SELECT @i = 1
    WHILE @i <= 20
      BEGIN
        EXEC sp_OAMethod @sbText, 'Append', @success OUT, 'Line '
        EXEC sp_OAMethod @sbText, 'AppendInt', @success OUT, @i
        EXEC sp_OAMethod @sbText, 'AppendLine', @success OUT, ' of a message that is too long for one small QR code.', 1
        SELECT @i = @i + 1
      END

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

    EXEC sp_OAMethod @json, 'UpdateSb', @success OUT, 'payload.text', @sbText

    --  Keep each symbol small (version 10 is 57 modules wide) and allow a set of symbols.
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'encoding.qr.maxVersion', 10
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'encoding.structuredAppend.enabled', 1

    --  One file for each symbol: qr_part_1.png, qr_part_2.png, ...
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.pathTemplate', 'qa_output/qr_part_{index}.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 @sbText
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @fmt
        EXEC @hr = sp_OADestroy @jsonOut
        RETURN
      END


    EXEC sp_OAGetProperty @sbText, 'Length', @iTmp0 OUT
    PRINT 'text length: ' + @iTmp0
    DECLARE @numSymbols int
    EXEC sp_OAMethod @jsonOut, 'SizeOfArray', @numSymbols OUT, 'symbols'

    PRINT 'symbols: ' + @numSymbols
    SELECT @i = 0
    WHILE @i <= @numSymbols - 1
      BEGIN
        EXEC sp_OASetProperty @jsonOut, 'I', @i
        --  structuredAppend.index counts from 0.
        EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'outputs[i].path'

        EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[i].structuredAppend.index'

        EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp1 OUT, 'symbols[i].structuredAppend.total'

        EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp2 OUT, 'symbols[i].selectedEncoding.version'

        EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp3 OUT, 'symbols[i].payloadBytes'

        PRINT @sTmp0 + ': symbol ' + (@iTmp0 + 1) + ' of ' + @iTmp1 + ', version ' + @iTmp2 + ', ' + @iTmp3 + ' bytes'
        SELECT @i = @i + 1
      END
    --  Every symbol of a set carries the same parity byte, which is how a reader knows they belong together.

    EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].structuredAppend.parity'
    PRINT 'parity: ' + @iTmp0

    --  The six symbols:

    --  image

    --  Sample output:

    --  text length: 1231
    --  symbols: 6
    --  qa_output/qr_part_1.png: symbol 1 of 6, version 10, 206 bytes
    --  qa_output/qr_part_2.png: symbol 2 of 6, version 10, 205 bytes
    --  qa_output/qr_part_3.png: symbol 3 of 6, version 10, 205 bytes
    --  qa_output/qr_part_4.png: symbol 4 of 6, version 10, 205 bytes
    --  qa_output/qr_part_5.png: symbol 5 of 6, version 10, 205 bytes
    --  qa_output/qr_part_6.png: symbol 6 of 6, version 10, 205 bytes
    --  parity: 50

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


END
GO