How to check whether there is an image in Blob field of Table

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ninadbe
Posts: 2
Joined: Fri 06 Sep 2013 16:28

How to check whether there is an image in Blob field of Table

Post by ninadbe » Sat 16 Jul 2016 17:30

I have a SQLite database named userplays, which contain a BLOB field named image.

I want to check whether given row at a time contains image at BLOB field

I m using following code but it is not working properly, as it enters into the if loop even if there is no image at BLOB field.

Code: Select all

    if Assigned(UniTable1.FieldByName('image')) then
         begin
            //showmessagefmt('ID Value Inititally :- %d',[k]);
            Stream2[k] := TMemoryStream.Create;
            Stream2[k] := UniTable1.CreateBlobStream(TBlobField(UniTable1.FieldByName('image')), bmRead);
         end;
or

Code: Select all

    if UniTable1.FieldByName('image').ToString <> '' then
         begin
            //showmessagefmt('ID Value Inititally :- %d',[k]);
            Stream2[k] := TMemoryStream.Create;
            Stream2[k] := UniTable1.CreateBlobStream(TBlobField(UniTable1.FieldByName('image')), bmRead);
         end;

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

Re: How to check whether there is an image in Blob field of Table

Post by MaximG » Mon 18 Jul 2016 09:38

You can use the IsNull method in order to check whether the field contains any data:

Code: Select all

UniTable1.FieldByName('image').IsNull

Post Reply