Insert/Update Tblobfield (Aka Image) Using SQL Parameters

Insert/update TBlobfield (aka image) using sql parameters

Should be something like:

qry.Parameters.Clear; 
qry.Parameters.AddParameter.Name := 'blobVal';
qry.Parameters.ParamByName('blobVal').LoadFromFile('c:\sample.jpg', ftBlob);
// or load from stream:
// qry.Parameters.ParamByName('blobVal').LoadFromStream(MyStream, ftBlob);
qry.Parameters.AddParameter.Name := 'idVal';
qry.Parameters.ParamByName('idVal').Value := 1;
qry.SQL.Text := 'update tbl set pic = :blobVal where id = :idVal';
qry.ExecSQL;

To read the BLOB back from the DB:

qry.SQL.Text := 'select id, pic from tbl where id = 1';
qry.Open;
TBlobField(qry.FieldByName('pic')).SaveToFile('c:\sample_2.jpg');

What is the most efficient way to read tile data (MBTiles) from SQLite table by using AnyDAC (FireDAC)?

Definitely use TADQuery. Unless you set the query to Unidirectional, it will buffer all the records returned from the database in memory (default 50). Since you are dealing with blobs, your query should be written to retrieve the minimum number of records you need.

Use a parameterized query, like the following the query

SELECT * FROM ATable
WHERE X = :X AND Y = :Y AND Z = :Z

Once you have initially opened the query, you can change the parameters, then use the Refresh method to retrieve the next record.

A memory table could not be used to retrieve data from the database, it would have to be populated via a query. It could be used to replace your TTileCache records, but I would not recommend it because it would have more overhead than your memory cache implementation.



Related Topics



Leave a reply



Submit