SQL Server Requires Chilkat v11.7.0+
SQL Server
QR Code Error Correction Levels
See more QR Code Examples
Demonstrates the four QR error-correction levels. L, M, Q and H allow a reader to recover the data when about 7%, 15%, 25% and 30% of the symbol is damaged or covered. More error correction leaves less room for data, so the same text needs a larger symbol at a higher level. The default is M. The example also shows boostErrorCorrection, which raises the level for free when the chosen version has room to spare.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @iTmp1 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
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', 'https://www.chilkatsoft.com/barcode_overview.asp'
-- Encode the same text at each level.
DECLARE @levels int
EXEC @hr = sp_OACreate 'Chilkat.JsonArray', @levels OUT
EXEC sp_OAMethod @levels, 'Load', @success OUT, '["L","M","Q","H"]'
DECLARE @i int
SELECT @i = 0
WHILE @i <= 3
BEGIN
EXEC sp_OAMethod @levels, 'StringAt', @sTmp0 OUT, @i
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'encoding.qr.errorCorrection', @sTmp0
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 @fmt
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @jsonOut
EXEC @hr = sp_OADestroy @levels
RETURN
END
EXEC sp_OAMethod @levels, 'StringAt', @sTmp0 OUT, @i
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].selectedEncoding.version'
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp1 OUT, 'symbols[0].dimensions.modulesWide'
PRINT 'level ' + @sTmp0 + ': version ' + @iTmp0 + ', ' + @iTmp1 + ' modules wide'
SELECT @i = @i + 1
END
-- The four symbols. They hold the same text, and the higher the level, the larger the symbol:
--
-- A symbol often has room left over. boostErrorCorrection uses it: the level is raised
-- as far as the same version allows, so the symbol is no larger but is more robust.
DECLARE @json2 int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json2 OUT
EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'payload.text', 'https://chilkatsoft.com'
EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'encoding.qr.errorCorrection', 'L'
EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'generate', @json2, @jsonOut
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @fmt, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @jsonOut
EXEC @hr = sp_OADestroy @levels
EXEC @hr = sp_OADestroy @json2
RETURN
END
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].selectedEncoding.version'
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'symbols[0].selectedEncoding.errorCorrection'
PRINT 'level L requested: version ' + @iTmp0 + ', level ' + @sTmp0
EXEC sp_OAMethod @json2, 'UpdateBool', @success OUT, 'encoding.qr.boostErrorCorrection', 1
EXEC sp_OAMethod @fmt, 'QrCode', @success OUT, 'generate', @json2, @jsonOut
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @fmt, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @jsonOut
EXEC @hr = sp_OADestroy @levels
EXEC @hr = sp_OADestroy @json2
RETURN
END
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].selectedEncoding.version'
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'symbols[0].selectedEncoding.errorCorrection'
PRINT 'level L with boost: version ' + @iTmp0 + ', level ' + @sTmp0
-- Level L, and level M reached by the boost. The two symbols are the same size:
--
-- Sample output:
-- level L: version 3, 29 modules wide
-- level M: version 4, 33 modules wide
-- level Q: version 5, 37 modules wide
-- level H: version 6, 41 modules wide
-- level L requested: version 2, level L
-- level L with boost: version 2, level M
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @jsonOut
EXEC @hr = sp_OADestroy @levels
EXEC @hr = sp_OADestroy @json2
END
GO