SQL Server Requires Chilkat v11.7.0+
SQL Server
Generate a QR Code with the Barcode Method
See more QR Code Examples
Demonstrates the Barcode method, which is the general form of QrCode: the request names the symbology, and everything else is the same. QrCode is Barcode with the symbology already set to qr, and identical requests to the two methods give identical results. A program that will produce more than one kind of barcode can use Barcode for all of them.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @iTmp1 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 @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, 'symbology', 'qr'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payload.text', 'https://www.chilkatsoft.com/'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.path', 'qa_output/qr_from_barcode.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, 'Barcode', @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, 'symbols[0].symbology'
PRINT 'symbology: ' + @sTmp0
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].selectedEncoding.version'
PRINT 'QR version: ' + @iTmp0
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'outputs[0].width'
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp1 OUT, 'outputs[0].height'
PRINT 'image: ' + @iTmp0 + ' x ' + @iTmp1 + ' pixels'
-- The image written to qa_output/qr_from_barcode.png:
--
-- Barcode requires the symbology. QrCode does not.
DECLARE @json2 int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json2 OUT
EXEC sp_OAMethod @json2, 'UpdateString', @success OUT, 'payload.text', 'https://www.chilkatsoft.com/'
EXEC sp_OAMethod @fmt, 'Barcode', @success OUT, 'generate', @json2, @jsonOut
IF @success = 0
BEGIN
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp0 OUT, 'errors[0].code'
EXEC sp_OAMethod @jsonOut, 'StringOf', @sTmp1 OUT, 'errors[0].path'
PRINT 'without a symbology: ' + @sTmp0 + ' at ' + @sTmp1
END
-- Sample output:
-- symbology: qr
-- QR version: 3
-- image: 148 x 148 pixels
-- without a symbology: missingOption at /symbology
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @jsonOut
EXEC @hr = sp_OADestroy @json2
END
GO