Binary data in blob field

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
viniciusfbb
Posts: 9
Joined: Thu 07 Mar 2019 01:00

Binary data in blob field

Post by viniciusfbb » Wed 02 Dec 2020 16:18

I am using the LiteDAC 4.3.2 and Delphi 10.4.1 and I have some blob fields in my sqlite3 that I store binary data and I am having problems with these fields.

To write I use:

Code: Select all

ADataSet.ParamByName('xxx').AsBytes
To read I use:

Code: Select all

ADataSet.FieldByName('xxx').AsBytes
The write is apparently working correctly, but the read is not and from what I noticed internally LiteDAC is considering the BLOB field as a string (In TField, the FDataType is ftWideString), and that's a problem.

This happened to me on MyDAC, but there were options that I set to work around this problem:

Code: Select all

     TCustomMyDataSet(ADataSet).Options.FieldsAsString := False;
     TCustomMyDataSet(ADataSet).Options.BinaryAsString := False;
But in LiteDAC I didn't find that option. How can I work around this?

(Sorry for my bad english)

viniciusfbb
Posts: 9
Joined: Thu 07 Mar 2019 01:00

Re: Binary data in blob field

Post by viniciusfbb » Wed 02 Dec 2020 17:59

Additional information: My field is a BLOB(16), when I change it to BLOB everything works. How could I make the field BLOB(16) considered as a blob and not as a ftWideString?

viniciusfbb
Posts: 9
Joined: Thu 07 Mar 2019 01:00

Re: Binary data in blob field

Post by viniciusfbb » Wed 02 Dec 2020 19:49

Sorry, I completely forgot that sqlite doesn't work with fixed sizes. The correct is BLOB and not BLOB(16).
Problem solved.

MaximG
Devart Team
Posts: 1551
Joined: Mon 06 Jul 2015 11:34

Re: Binary data in blob field

Post by MaximG » Tue 08 Dec 2020 08:08

We are glad to see the problem resolved. Please don't hesitate to contact us with questions concerning our product usage.

Mark2018
Posts: 8
Joined: Sat 04 Aug 2018 20:03

Re: Binary data in blob field

Post by Mark2018 » Sun 10 Jan 2021 16:34

Hello,
can you give me a sample code to write an read an array of floats (type single) into a Blob field ?

REgards

MaximG
Devart Team
Posts: 1551
Joined: Mon 06 Jul 2015 11:34

Re: Binary data in blob field

Post by MaximG » Sat 16 Jan 2021 13:59

This issue is not related to our components. You may try the following:

- save your array to TMemoryStream;
- load the contents of the stream to TBlobField using LoadFromStream :

Code: Select all

TBLOBField(LiteQuery.FieldByName('<your BLOB field name>')).LoadFromStream(Stream);

Post Reply