Page 1 of 1

TLiteQuery and TParam for blob field

Posted: Mon 06 Aug 2012 19:45
by PaulT2
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;

Re: TLiteQuery and TParam for blob field

Posted: Tue 07 Aug 2012 08:18
by ZEuS
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.

Re: TLiteQuery and TParam for blob field

Posted: Tue 07 Aug 2012 09:36
by PaulT2
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.