Subject Re: [firebird-support] saving to a blob field
Author Helen Borrie
At 10:34 AM 29/05/2005 +1000, you wrote:
>Hi all,
>
>Using D5, FIBPlus and FireBird 1.5
>
>Could someone please show me how to save a rtf memo to a database record
>using streams. Never doe it before and its giving me heaps of grief
>
> // SQL - SELECT PRINTING FROM VEN_PROFILE_MEMOS WHERE DETECTID = :IDNo

You don't do a SELECT in order to perform an update operation!

Try one or other of these statements, depending on whether you are updating
an existing blob or creating a new record:

UPDATE VEN_PROFILE_MEMOS
SET PRINTING = :printing)
WHERE DETECTID = :IDNo

INSERT INTO VEN_PROFILE_MEMOS (PRINTING, IDNo)
VALUES (:printing, :IDNo)

Alternatively, write an executable stored procedure that takes the blob and
the unique ID as input and takes care of the decision about whether to
insert or update. Then, your SQL would be along these lines:

EXECUTE PROCEDURE UPDATE_VPM (:printing, :IDNo);
....
var
stm: TMemoryStream;
stm2: TBlobStream;
begin
....
try
stm := TMemoryStream.Create;
stm2 := TBlobStream.Create;
MainForm.Ven_RT_Memo.Lines.SaveToStream(stm);
try
with SaveProfileMemoStrem do
begin
if not Transaction.InTransaction then
StartTransaction;
If not Prepared then Prepare;
stm2 := CreateBlobStream(Params[1], bmWrite);
stm2.CopyFrom(stm1, stm1.Size);
Params[1].asInteger := IDNo; // get this from somewhere
try
Result := 0;
ExecQuery;
Transaction.Commit;
except
begin
Result := Err_Code_Minus_2202;
Transaction.Rollback;
end;
end;
finally
stm2.Free;
stm.Free;
end;
.....
end;

There's a wild assumption here that your "SaveProfileMemoStrem"
object (whatever it is) actually does have a Transaction property that you
can refer to. I don't use FIBPlus so I don't know whether it's a valid
reference or not. (IBO's statement classes, which I do use, have the
IB_Transaction property...)

Now, it's well possible that FIBPlus has re-jmplemented the VCL's
blobstreams, as they are pretty klutzy. IBO has its own refined types,
mechanisms and options for this kind of task and I'd be very surprised if
FIBPlus didn't also.

May I remind you that this forum is neither a Delphi nor an FIBPlus
forum. If you are using FIBPlus and you are struggling with it, you should
join its user list. One of the gurus in that list will be able to put you
right in the frame.

^heLen