Recent

Author Topic: SQLite save QRCode how to improve speed?  (Read 1010 times)

Int3g3r

  • New Member
  • *
  • Posts: 41
SQLite save QRCode how to improve speed?
« on: October 23, 2025, 04:41:54 pm »
Hello

I write one QR and one Barcode into a SQLite database.
This takes for 600 records around 60s.
Is there way to improve it?

I do it like this (pseudo code):

Code: Pascal  [Select][+][-]
  1. procedure GenerateBarcode
  2. begin
  3.    if qryGrid.RecountCount > 0 then
  4.    begin
  5.      while not qryGrid.EOF do
  6.      begin
  7.         GenerateBarcode; //TBitmap
  8.         GenerateQRCode; //TBitmap
  9.         qryGrid.Edit;
  10.         qryGrid.CreateBlobStream(Barcode);
  11.         BarcodeStream.SaveToStream(bgStream);
  12.         qryGrid.CreateBlobStream(QRCode);
  13.         QrCodeStream.SaveToStream(qrStream);
  14.         qryGrid.Post;
  15.         qryGrid.Next;
  16.      end;
  17.    end;
  18. end;
  19.  

Would threading improve this, if so which part should i thread?
Is it possible to edit 100 records at once (in memory), and then post all 100 to the sqlite database, would this improve the speed?
Great would be 1000 records in around 10-20seconds.

Regards Int3g3r
« Last Edit: October 23, 2025, 04:43:59 pm by Int3g3r »

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: SQLite save QRCode how to improve speed?
« Reply #1 on: October 23, 2025, 05:51:48 pm »
The bottleneck is probably the barcode and qrcode generation. What information do you store in it, especially the qrcode, because that can contain *a lot* of info. There is not necessarily anything wrong with your code that I can see except for those two. If you replace these two with dummies it is mere seconds, not minutes. Even milliseconds:600 is not a big number.

Then again: the whole loop is full of things that are possibly computationally expensive by nature.

I would focus on the bar/qrcode generation. And yes, those two can probably be parallelized.
To reassure you: it is not sqlite, which can store 1000ths of records in a second, not a minute, and even on old hardware.
« Last Edit: October 23, 2025, 06:07:19 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

wp

  • Hero Member
  • *****
  • Posts: 13401
Re: SQLite save QRCode how to improve speed?
« Reply #2 on: October 23, 2025, 11:48:34 pm »
Why do you want to store the bar/QRcode in the database directly? These are images, and images in databases is something which should be avoided because they are large and can stuff buffers. You can store the text encoded in the barcode/QRCode directly and create the bar/QRCodes on the fly when needed.

The attached demo creates a table with an integer and a text column for 20,000 records within less than a second. And when you scroll through the database an interleaved-2-of-5 barcode is created instantly from the currently active numeric field (plus checksum in case you are using the current svn version of LazBarCodes), and a QRCode is created from the text field in the same way, just by assigning the field values to the Text property of the bar/QRcode components.

Zvoni

  • Hero Member
  • *****
  • Posts: 3300
Re: SQLite save QRCode how to improve speed?
« Reply #3 on: October 24, 2025, 08:23:59 am »
Why do you want to store the bar/QRcode in the database directly? These are images, and images in databases is something which should be avoided because they are large and can stuff buffers. You can store the text encoded in the barcode/QRCode directly and create the bar/QRCodes on the fly when needed.
Correct.
Don't store the Image, store the information within the QR/Barcode.
Upside: If you change your QR/Barcode to another Format, the content is (more or less) the same
e.g. Old Barcode Code39 to Code 128 for 1-D or PDF417 to DataMatrix for 2-D.
The Information is still the same, they just look different.

It's the same old discussion with Date-Types:
Never store how something is displayed in the Database, only the Information
« Last Edit: October 24, 2025, 08:27:44 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Int3g3r

  • New Member
  • *
  • Posts: 41
Re: SQLite save QRCode how to improve speed?
« Reply #4 on: October 24, 2025, 09:49:10 am »
Thank you very much for your help and advice.

My biggest problem was that LazReport cannot generate QR codes.
I have also just noticed that the checksum for the 2of5 barcode does not work in LazReport either.

So I decided to save the QR codes as images in the database.
I can then easily read them out later with LazReport.
 
Would there have been a better method?
Would it have been better to save the QR/barcode images on the hard drive and only save the file names in the database?
Which is faster, reading the images from SQLite or from the hard drive?

Regards Int3g3r

paweld

  • Hero Member
  • *****
  • Posts: 1571
Re: SQLite save QRCode how to improve speed?
« Reply #5 on: October 24, 2025, 10:24:12 am »
Quote from: Int3g3r
So I decided to save the QR codes as images in the database.
I can then easily read them out later with LazReport.
see example in the attachment
Best regards / Pozdrawiam
paweld

Zvoni

  • Hero Member
  • *****
  • Posts: 3300
Re: SQLite save QRCode how to improve speed?
« Reply #6 on: October 24, 2025, 10:59:37 am »
Thank you very much for your help and advice.

My biggest problem was that LazReport cannot generate QR codes.
I have also just noticed that the checksum for the 2of5 barcode does not work in LazReport either.

So I decided to save the QR codes as images in the database.
I can then easily read them out later with LazReport.
 
Would there have been a better method?
Would it have been better to save the QR/barcode images on the hard drive and only save the file names in the database?
Which is faster, reading the images from SQLite or from the hard drive?

Regards Int3g3r

You have seen that there is a Package called "LazBarcodes" in OPM?

One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Int3g3r

  • New Member
  • *
  • Posts: 41
Re: SQLite save QRCode how to improve speed?
« Reply #7 on: October 24, 2025, 11:58:29 am »
Quote
You have seen that there is a Package called "LazBarcodes" in OPM?

Yes, I use LazBarcodes to generate the barcodes.

Quote
see example in the attachment

I didn't know that I could transfer the QR barcode via MemoryStream.
I've learned something new, thanks for the example.

Regards Int3g3r

paweld

  • Hero Member
  • *****
  • Posts: 1571
Re: SQLite save QRCode how to improve speed?
« Reply #8 on: October 24, 2025, 12:16:35 pm »
I quoted the wrong part in my previous post.

The example shows how to generate codes on the fly and transfer them to the report - you place a picture object on the report, stet them a name (in the example, “gs1”), and then, in the OnEnterRect event of the report, you load the graphic with the code into the picture object.
Best regards / Pozdrawiam
paweld

 

TinyPortal © 2005-2018