Welcome!
This community is for professionals and enthusiasts of the Genio platform.
Share your questions and challenges, and help your partners!
Save Qr Code in Database
Is there a way to save the QrCode generated as an image in the database? I know the the version 305.86 generates a QrCode, but the information saved in database it's the information behind the code and not the code it's self.
Yes, but you should not do it.
Why it should not be done
A QR code is, basically, a way of displaying text that cameras can easily read. Assuming the database already contains the information behind the QR code, storing its image representation (in bytes) would be a duplication of the information. Since the cost of storing an image (in bytes) is much higher than storing a simple text, the size of each record could significantly increase. For this reason alone, the QR code should be generated on demand, rather than being stored in the database.
Additionally, note that the server-side manual code to support this behavior will not be taken into consideration by the reindex steps: reindexing the database will not automatically update the stored QR code image.
How to generate the QR code on demand
As you mentioned, Genio currently offers a way to generate the QR code on demand, based on a given text input. Additional information regarding this topic can be found in https://geniodoc.quidgest.net/patterns/field-types/text#qr-code.
To support more complex use cases, such as displaying QR codes in SSRS reports, additional steps might be required to take. For a more in-depth guide on how to use a QR code in a SSRS report, please visit https://geniodoc.quidgest.net/guides/how-to-use-a-qr-code-in-a-ssrs-report.
Despite this, if you still find necessary to store the QR code image representation in the database, here is how you can do it using C#.
Solution
Create an image field that will be used to store the QR code.
Use manual C# code to change the value of the field before the record is saved. Use: Platform: CS | Type: BEFOREUPDATE | Parameters: <Table Name>.
Implement the body of the function. Example for a table called "Album":
// We will need:
// - a field with the source data (in this case, "LINKSRC")
// - a blank field to fill with the result (in this case, "QRCODE")
// Get the input text from the source field string inputText = (string)returnValueField("album.linksrc"); // Get the byte array that represents the image of the QR code byte[] bytes = GlobalFunctions.StringToQRcode(inputText);
// Update the value of the field
insertNameValueField("album.qrcode", bytes);
return StatusMessage.OK();
Keep Informed
About the Community
Question tools
Stats
Asked: 28/01/2022 07:43 |
Seen: 1606 times |
Last updated: 31/01/2022 18:41 |