Q&A - Question
How to save a bitmap in SQLite field
Danv asked on June 27, 2022, keyword: Developer Kernel
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:
cfg : TStringList ;
odb : TGIS_DbSqlite ;
stm : TGIS_MemoryStream ;
bmp : TGIS_Bitmap ;
odb := TGIS_DbSqlite.Create ;
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 ) ;
bmp := TGIS_Bitmap.Create ;
bmp.LoadFromFile( 'c:\tmp\test.jpg') ;
stm := TGIS_MemoryStream.Create ;
odb.sqlTableOpenWrite(1, 'UPDATE test SET Foto =:Foto WHERE id=1');
odb.sqlTableSetBlob(1, 'Foto', Unassigned, stm);
If you would like to answer the question please Sign In.
The Questions and Answers (Q & A) is intended to provide a means of communication between TatukGIS customers.
- Licensed users (with active maintenance play) of TatukGIS products may contribute to the Q & A content. Read-only access is available to anyone.
- Keep the content positive and professional.
- 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.
- The Q & A is not a replacement for TatukGIS technical support. TatukGIS team may or may not regularly follow or contribute content.