SQL Server Requires Chilkat v11.7.0+
SQL Server
Generate a QR Code PNG File
See more QR Code Examples
Demonstrates the simplest way to create a QR code: the text to encode goes in payload.text, and output.path names the PNG file to write. QrCode chooses the smallest QR version that holds the text at error-correction level M, and the response reports what it chose and the size of the image. The request and the response are both JSON objects, and they must be two different objects.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @iTmp1 int
DECLARE @iTmp2 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 @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', 'https://www.chilkatsoft.com/'
-- Each module (one of the small squares) is drawn 8 pixels wide. The default is 4.
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'render.moduleSize', 8
-- Write the image to a file. An existing file is replaced only when output.overwrite is true.
-- Otherwise the call fails and the existing file is left as it was.
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.path', 'qa_output/qr_chilkat.png'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'output.overwrite', 1
-- The image is also returned in the response as base64 unless output.return is "none".
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 @json
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @jsonOut
RETURN
END
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'outputs[0].path'
PRINT 'file: ' + @sTmp0
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'outputs[0].width'
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp1 OUT, 'outputs[0].height'
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp2 OUT, 'outputs[0].byteCount'
PRINT 'image: ' + @iTmp0 + ' x ' + @iTmp1 + ' pixels, ' + @iTmp2 + ' bytes'
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].selectedEncoding.version'
PRINT 'QR version: ' + @iTmp0
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'symbols[0].selectedEncoding.errorCorrection'
PRINT 'error correction: ' + @sTmp0
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].dimensions.modulesWide'
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp1 OUT, 'symbols[0].dimensions.modulesHigh'
PRINT 'modules: ' + @iTmp0 + ' x ' + @iTmp1
-- The image written to qa_output/qr_chilkat.png:
--
-- Sample output:
-- file: qa_output/qr_chilkat.png
-- image: 296 x 296 pixels, 1251 bytes
-- QR version: 3
-- error correction: M
-- modules: 29 x 29
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @jsonOut
END
GO