SQL Server Requires Chilkat v11.7.0+
SQL Server
Handle QR Code Errors
See more QR Code Examples
Demonstrates what happens when a request is refused. QrCode returns false and the response holds errors[0] with three members: a code that does not change between versions, the path of the request member at fault (a JSON Pointer such as /encoding/qr/version), and a message. Requests are checked strictly, so a misspelled option is an error rather than being silently ignored. LastErrorText has the same information in more detail.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr 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.
DECLARE @fmt int
EXEC @hr = sp_OACreate 'Chilkat.Formats', @fmt OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
DECLARE @jsonOut int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonOut OUT
-- 1. A misspelled option: "moduleSise" for "moduleSize".
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', 'https://www.chilkatsoft.com/'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'render.moduleSise', 8
EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'generate', @json, @jsonOut
IF @success = 0
BEGIN
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'errors[0].code'
PRINT 'code: ' + @sTmp0
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'errors[0].path'
PRINT 'path: ' + @sTmp0
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'errors[0].message'
PRINT 'message: ' + @sTmp0
END
-- 2. A value out of range: QR versions are 1 to 40.
EXEC sp_OAMethod @json, 'Clear', NULL
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', 'https://www.chilkatsoft.com/'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'encoding.qr.version', 41
EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'generate', @json, @jsonOut
IF @success = 0
BEGIN
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'errors[0].code'
PRINT 'code: ' + @sTmp0
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'errors[0].path'
PRINT 'path: ' + @sTmp0
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'errors[0].message'
PRINT 'message: ' + @sTmp0
END
-- 3. Too much data: this text does not fit a version 1 symbol.
EXEC sp_OAMethod @json, 'Clear', NULL
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', 'https://www.chilkatsoft.com/barcode_overview.asp'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'encoding.qr.version', 1
EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'generate', @json, @jsonOut
IF @success = 0
BEGIN
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'errors[0].code'
PRINT 'code: ' + @sTmp0
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'errors[0].path'
PRINT 'path: ' + @sTmp0
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'errors[0].message'
PRINT 'message: ' + @sTmp0
END
-- A program can act on the code.
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'errors[0].code'
IF @sTmp0 = 'capacityExceeded'
BEGIN
PRINT 'The text is too long for the symbol size allowed.'
END
-- Sample output:
-- code: unknownOption
-- path: /render/moduleSise
-- message: unknown option
-- code: outOfRange
-- path: /encoding/qr/version
-- message: the value is out of range
-- code: capacityExceeded
-- path: /payload
-- message: the payload does not fit the requested QR version at the requested error-correction level
-- The text is too long for the symbol size allowed.
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @jsonOut
END
GO