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

Validate a QR Code Request

See more QR Code Examples

Demonstrates the validate operation, which examines a request without producing anything. The scope says how far to look: definition checks the options, capacity also checks that the data fits a QR symbol, and layout also checks the rendered size against the limits. The response has a validationStatus of valid or invalid, a list of checks, and findings[] describing what is wrong. A request that cannot be understood at all, such as one with a misspelled option, still makes the call fail in the usual way.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @sTmp1 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.

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

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

    DECLARE @i int

    DECLARE @n int

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

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'target', 'symbol'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'validation.scope', 'capacity'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', 'https://www.chilkatsoft.com/barcode_overview.asp'

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

    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'validationStatus'
    PRINT 'status: ' + @sTmp0
    EXEC sp_OAMethod @jsonOut, 'SizeOfArray', @n OUT, 'checks'
    SELECT @i = 0
    WHILE @i <= @n - 1
      BEGIN
        EXEC sp_OASetProperty @jsonOut, 'I', @i

        EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'checks[i].name'

        EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp1 OUT, 'checks[i].status'
        PRINT '  ' + @sTmp0 + ': ' + @sTmp1
        SELECT @i = @i + 1
      END

    --  The same text does not fit version 2 at error-correction level H.
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'encoding.qr.maxVersion', 2
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'encoding.qr.errorCorrection', 'H'

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

    EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'validationStatus'
    PRINT 'status: ' + @sTmp0
    EXEC sp_OAMethod @jsonOut, 'SizeOfArray', @n OUT, 'checks'
    SELECT @i = 0
    WHILE @i <= @n - 1
      BEGIN
        EXEC sp_OASetProperty @jsonOut, 'I', @i

        EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'checks[i].name'

        EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp1 OUT, 'checks[i].status'
        PRINT '  ' + @sTmp0 + ': ' + @sTmp1
        SELECT @i = @i + 1
      END
    EXEC sp_OAMethod @jsonOut, 'SizeOfArray', @n OUT, 'findings'
    SELECT @i = 0
    WHILE @i <= @n - 1
      BEGIN
        EXEC sp_OASetProperty @jsonOut, 'I', @i

        EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'findings[i].code'

        EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp1 OUT, 'findings[i].path'
        PRINT 'finding: ' + @sTmp0 + ' at ' + @sTmp1

        EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'findings[i].message'
        PRINT '  ' + @sTmp0
        SELECT @i = @i + 1
      END

    --  Sample output:

    --  status: valid
    --    definition: passed
    --    capacity: passed
    --    layout: notApplicable
    --  status: invalid
    --    definition: passed
    --    capacity: failed
    --    layout: notApplicable
    --  finding: capacityExceeded at /payload
    --    the payload does not fit any admitted QR version at the selected error-correction level

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


END
GO