Reputation: 23
I am writing a REST Data Snap server and have to save a TStream to a VarBinary(384) field. I try to CreateBlobStream on the field but get exception errors when I attempt this.
How do one save to a VarBinary field using DBExpress?
with cdsInsertIssueActionTemplateDetail do
begin
Active := True;
Insert();
T11 := TMemoryStream.Create;
DM.CopyStreamToMemoryStream(Template11, T11);
BlobField := TBlobField(FieldByName('FingerTemplate'));
BS := CreateBlobStream(BlobField, bmWrite); //Exception occurs here
BS.CopyFrom(T11, T11.Size);
T11.Free;
BS.Free;
Post();
Active := False;
end;
Upvotes: 1
Views: 801
Reputation: 23
I finally managed to get it to work by making FingerTemplate a parameter in the TSQLQuery as follows:
INSERT INTO [dbo].[tblIssueActionTemplateDetail]([ActionUID],[FingerTemplate] ,[FingerTemplateIndex] ,[FingerIndex] , [IsDuress],[AddedOnDateTime] ,[LastModifiedDateTime]) VALUES (:ActionUID, :FingerTemplate, :FingertemplateIndex, :FingerIndex,0, :DateTime, :DateTime)
An made the Parameter's DataType of ftBlob
begin
T21 := TMemoryStream.Create;
Template21.Position;
DM.CopyStreamToMemoryStream(Template21, T21);
BlobField := TBlobField(FieldByName('FingerTemplate'));
Params.ParamByName('FingerTemplate').SetBlobData(Template21, Template21.Size);
T21.Free;
end;
Upvotes: 0