TatukGIS menu

Q&A - Question

How to save a bitmap in SQLite field

Danv asked on June 27, 2022, keyword: Developer Kernel
Hi all,

I am able to read a bitmap from a field and display it in a TImage.
This using the sqlQueryGetBlob function.

Now I want it the other way around: save a bitmap in the field.
So I found the sqlTableSetBlob procedure but I can not figure out the use of it.

Anyway ever used this and can show me a few lines how it is done?

Thanks in advance, Danny.
Artur Redzko (TatukGIS) replied June 27, 2022
here is a sample code:
procedure SaveBitmap;
  cfg : TStringList ;
  odb : TGIS_DbSqlite ;
  stm : TGIS_MemoryStream ;
  bmp : TGIS_Bitmap ;
  odb := TGIS_DbSqlite.Create ;
    odb.InitializeProvider ;
    cfg := TStringList.Create ;
      cfg.Values[ 'Sqlite' ] := 'c:\tmp\test.db' ;
      // solve "a database is locked" issue
      cfg.Values['PRAGMA journal_mode'] := 'WAL';
      cfg.Text := cfg.Text + #13#10 + GetSQLDialect( 'SQLITE' ) ;
      odb.sqlInitialize( cfg, cfg ) ;
      odb.sqlConnect( '', cfg ) ;
    cfg.Free ;

    bmp := TGIS_Bitmap.Create ;
    bmp.LoadFromFile( 'c:\tmp\test.jpg') ;
    stm := TGIS_MemoryStream.Create ;
    bmp.Free ;

    odb.sqlTableOpenWrite(1, 'UPDATE test SET Foto =:Foto WHERE id=1');
    odb.sqlTableSetBlob(1, 'Foto', Unassigned, stm);
    stm.Free ;
    odb.sqlDisconnect ;
  odb.Free ;
If you would like to answer the question please Sign In.
Please review our recent Privacy Policy.
If you have any questions or requests, please contact us.
The Questions and Answers (Q & A) is intended to provide a means of communication between TatukGIS customers.
  1. Licensed users (with active maintenance play) of TatukGIS products may contribute to the Q & A content. Read-only access is available to anyone.
  2. Keep the content positive and professional.
  3. Be courteous to others by posting information when a question or issue asked on the Q & A is answered or resolved by other means (such as with help from TatukGIS technical support). Offer others at least a hint how the posted question was answered or the issue was resolved.
  4. The Q & A is not a replacement for TatukGIS technical support. TatukGIS team may or may not regularly follow or contribute content.