TLiteQuery and TParam for blob field

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
PaulT2
Posts: 29
Joined: Wed 15 Aug 2007 19:31

TLiteQuery and TParam for blob field

Post by PaulT2 » Mon 06 Aug 2012 19:45

Your new DAC came along just as we were about to buy an alternative, but as we already use SDAC and PgDAC we'd much prefer to keep everything in one place. I have a work around for this problem, but is it a bug in TDAParam, or something I'm missing ?

I've always used TField / TParam variable shortcuts wherever possible so as to save multiple FieldByName / ParamByName lookups when dealing with multiple records. I'd prefer to keep doing that, but at the moment, the only to get the blob field populated seems to be via the ParamByName method for each record I want to create.

Code: Select all

procedure TClientData.CreatePart(const aFileName,aName:string ; const aId:integer);
var pId       : TParam;
    pName     : TParam;
    pPicture  : TParam;
    Stream    : TFileStream;
begin
     Stream := TFileStream.Create(aFileName,fmOpenRead);
     LiteQuery.SQL.Clear;
     LiteQuery.SQL.Add('insert into Part (Id,Name,Picture) values (:Id,:Name,:Picture)');
     pId      := LiteQuery.ParamByName('Id');
     pName    := LiteQuery.ParamByName('Name');
     pPicture := LiteQuery.ParamByName('Picture');
     pId.AsInteger   := aId;
     pName.AsString  := aName;

     // This works
//     LiteQuery.ParamByName('Picture').LoadFromStream(Stream,ftBlob);

     // This gives an access violation in TDAParam.GetIsNull
     pPicture.LoadFromStream(Stream,ftBlob);

     LiteQuery.Execute;
     Stream.Free;
end;

ZEuS
Devart Team
Posts: 240
Joined: Thu 05 Apr 2012 07:32

Re: TLiteQuery and TParam for blob field

Post by ZEuS » Tue 07 Aug 2012 08:18

To avoid the error in your example, you should either declare the pPicture variable as TDAParam or use TDAParam(pPicture).LoadFromStream to set the variable value.

PaulT2
Posts: 29
Joined: Wed 15 Aug 2007 19:31

Re: TLiteQuery and TParam for blob field

Post by PaulT2 » Tue 07 Aug 2012 09:36

Thank you. That's working fine now. Looking like a great addition to the DAC family and very timely for us. We'll be ordering shortly.

Post Reply