SQL Server Requires Chilkat v11.7.0+
SQL Server
QR Code with Non-English Text (UTF-8 and ECI)
See more QR Code Examples
Demonstrates text outside ASCII. QrCode always stores text as UTF-8 bytes, which is what phones expect. A QR code can also say so explicitly with an ECI header: setting encoding.eci to 26 declares the bytes to be UTF-8, for readers that would otherwise assume another character set. The header costs a little space, and a few older readers do not understand it, so it is off by default.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.
-- The text is "Gruesse aus Muenchen" written with u-umlaut and sharp s. It is given here with
-- JSON escapes only so that this source is plain ASCII. Decode turns the escapes into characters.
DECLARE @sbText int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbText OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OAMethod @sbText, 'Append', @success OUT, 'Gr\u00fc\u00dfe aus M\u00fcnchen'
EXEC sp_OAMethod @sbText, 'Decode', @success OUT, 'json', 'utf-8'
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateSb', @success OUT, 'payload.text', @sbText
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.path', 'qa_output/qr_utf8.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, 'QrCode', @success OUT, 'generate', @json, @jsonOut
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @fmt, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @sbText
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @jsonOut
RETURN
END
-- 17 characters, three of which take two bytes in UTF-8.
EXEC sp_OAGetProperty @sbText, 'Length', @iTmp0 OUT
PRINT 'characters: ' + @iTmp0
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp0 OUT, 'symbols[0].payloadBytes'
PRINT 'bytes encoded: ' + @iTmp0
EXEC sp_OAMethod @jsonOut, 'HasMember', @iTmp0 OUT, 'symbols[0].selectedEncoding.eci'
PRINT 'ECI header: ' + @iTmp0
-- Without an ECI header (qa_output/qr_utf8.png):
--
-- The same text with an ECI header declaring UTF-8.
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'encoding.eci', 26
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'output.path', 'qa_output/qr_utf8_eci.png'
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 @sbText
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @jsonOut
RETURN
END
EXEC sp_OAMethod @jsonOut, 'HasMember', @iTmp0 OUT, 'symbols[0].selectedEncoding.eci'
EXEC sp_OAMethod @jsonOut, 'IntOf', @iTmp1 OUT, 'symbols[0].selectedEncoding.eci'
PRINT 'with encoding.eci = 26, ECI header: ' + @iTmp0 + ', value ' + @iTmp1
-- With the ECI header (qa_output/qr_utf8_eci.png). Both scan as the same text:
--
-- Sample output:
-- characters: 17
-- bytes encoded: 20
-- ECI header: False
-- with encoding.eci = 26, ECI header: True, value 26
EXEC @hr = sp_OADestroy @sbText
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @fmt
EXEC @hr = sp_OADestroy @jsonOut
END
GO