Page 1 of 1

I need to append data to a blob... How do I?

Posted: Tue 12 Sep 2006 10:12
by Kaus Media
Hi there,

I have data coming in a memory stream with an event each time data is added to it. Actually, it is a fax reception.

I want to store data directly to a blob in my database (9i) and I have odac 5.80 installed.

I thought it should be working with this:

procedure TfrmCAPIConfigDetail.FaxStreamToFaxRecord;
Var intCurrentPos : Integer;
intCopyBytes : Integer;
blobSFF : TOraLob;
pBuffer : PByte;
begin
pBuffer := Nil; blobSFF := Nil;
try
FFaxPages := FProtocol.FaxRecvInfo.Pages;
If Assigned (FFaxRecord) then begin
FFaxRecord.Edit;
blobSFF := FFaxRecord.GetLob('FAX');
intCurrentPos := blobSFF.Size;
intCopyBytes := FFaxStream.Size-intCurrentPos;
pBuffer := FFaxStream.Memory; Inc(pBuffer, intCurrentPos);
blobSFF.Write(intCurrentPos, intCopyBytes, pBuffer);
// FFaxRecord.FieldByName('BLOB_SIZE').AsInteger := blobSFF.Size; <- This line is a test. Commented removed, the correct size of the Blob is saved to the DB!
FFaxRecord.Post;
end else SendMessage ('FAX RECORD CLOSED. UNABLE TO UPDATE');
except
On E: Exception do begin
SendMessage ('FAX TRANSFER DATA ERROR: '+E.Message);
FHandler.DisconnectLine($349B);
if Assigned(FfaxRecord) And (FFaxRecord.State=dsEdit) then FFaxRecord.Post;
end;
end;
end;

but it ain't... My Blob is empty! Do you know what am I doing wrong?

Thanks.

Tried something better, but it does not change anything...

Posted: Tue 12 Sep 2006 11:27
by Kaus Media
I've tried also this. But trouble is the same. Blob still empty in the database (But if I query its size [blobSFF.Size] in my software, then it is correct...)

pBuffer := FFaxStream.Memory; Inc(pBuffer, intCurrentPos);
blobSFF := FFaxRecord.GetLob('SFF');
intCurrentPos := blobSFF.Size;
intCopyBytes := FFaxStream.Size-intCurrentPos;
blobSFF.Write(intCurrentPos, intCopyBytes, pBuffer);
blobSFF.FreeLob;

Ooops...

Posted: Tue 12 Sep 2006 12:27
by Kaus Media
It was a bit upside down... I meant:

blobSFF := FFaxRecord.GetLob('SFF');
intCurrentPos := blobSFF.Size;
intCopyBytes := FFaxStream.Size-intCurrentPos;
pBuffer := FFaxStream.Memory; Inc(pBuffer, intCurrentPos);
blobSFF.Write(intCurrentPos, intCopyBytes, pBuffer);
blobSFF.FreeLob;

If I replace the line:
blobSFF.Write(intCurrentPos, intCopyBytes, pBuffer);
with:
var fsSFF: TFileStream;
...
fsSFF.Seek(0, soFromEnd); fsSFF.Write (pBuffer^, intCopyBytes);
...


then the fax is properly received to a file... So I guess i must be wrong with TOraBlob usage somewhere... But where?

Posted: Wed 13 Sep 2006 11:58
by Plash
The problem is that TSmartQuery doesn't detect that BLOB field is modified when posting record. Add line

Code: Select all

  TBlobField(FFaxRecord.FieldByName('FAX')).Modified := True;
before calling Post method.

Thanks

Posted: Wed 13 Sep 2006 12:55
by Kaus Media
Great! It works...

Many, many thanks!