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

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Kaus Media
Posts: 13
Joined: Tue 12 Sep 2006 10:02

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

Post by Kaus Media » Tue 12 Sep 2006 10:12

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.

Kaus Media
Posts: 13
Joined: Tue 12 Sep 2006 10:02

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

Post by Kaus Media » Tue 12 Sep 2006 11:27

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;

Kaus Media
Posts: 13
Joined: Tue 12 Sep 2006 10:02

Ooops...

Post by Kaus Media » Tue 12 Sep 2006 12:27

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?

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Wed 13 Sep 2006 11:58

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.

Kaus Media
Posts: 13
Joined: Tue 12 Sep 2006 10:02

Thanks

Post by Kaus Media » Wed 13 Sep 2006 12:55

Great! It works...

Many, many thanks!

Post Reply