TLiteQuery and TParam for blob field
Posted: 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.
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;