Subject | Re: [IBO] INSERT BLOB |
---|---|
Author | Helen Borrie |
Post date | 2004-01-07T00:49:03Z |
Ronan,
At 08:48 PM 6/01/2004 +0100, you wrote:
don't need to burden yourself with the shortcomings of the VCL TBlobfield
and params. Use a TIB_DSQL for this operation. Make its SQL property to
be a parameterised call to your SP:
EXECUTE PROCEDURE SP_ADD_PROJECT(:param1, :param2, :blobparam, ...)
Write a method that writes any blob sub_type 0 column, using the superior
internal methods of TIB_BlobStream. Once you have the blob moving via the
stream, the rest just falls into place. Here's such a method (test for
existence of the file *before* passing it to the procedure and make sure
the owning statement is prepared before passing the tib_Column reference):
procedure MyDM.StreamThisBlob(aFileName: string; aColumn: TIB_ColumnBlob);
var
Instream: TFileStream;
begin
Instream := TFileStream.Create(aFileName, fmOpenRead);
try
if Instream.Assigned then
aColumn.Assign(TStream(Instream)); // not certain you need this casting
finally
Instream.Free;
end;
end;
.......................................
Invocation code:
...
var
a1: string;
begin
...
with MyDM.ib_dsql1 do
begin
if not Prepared then Prepare;
<assign your non-blob parameters>;
a1 := 'c:\a.gif';
if FileExists(a1) then
try
StreamThisBlob(a1, ParamByName('BlobParam'));
except
<call code to handle the exception>
end;
...
if not ParamByName('BlobParam').Assigned then
ParamByName('BlobParam').Clear; //ensures empty blob is null
...
<do any other assignments>
Execute;
end;
...
end;
The parameter assignment logic is only a suggestion, as I don't know what
you actually want to do if the file is missing or something goes wrong with
the blob-streaming (e.g. someone has the file open) or whatever.
Helen
At 08:48 PM 6/01/2004 +0100, you wrote:
>Hello,To begin with, for an executable stored procedure (which this MUST be) you
>
>I am using a TIBOStoredProc to INSERT a blob into a table (Firebird 1.5 R7).
>An AV is thrown see code extract.
>
>procedure TDataModule2.waADD_PROJECTExecute(Sender: TObject);
>var
> a1: string;
>begin
> with IBO_SP_ADD_PROJECT, pWebApp do begin
don't need to burden yourself with the shortcomings of the VCL TBlobfield
and params. Use a TIB_DSQL for this operation. Make its SQL property to
be a parameterised call to your SP:
EXECUTE PROCEDURE SP_ADD_PROJECT(:param1, :param2, :blobparam, ...)
Write a method that writes any blob sub_type 0 column, using the superior
internal methods of TIB_BlobStream. Once you have the blob moving via the
stream, the rest just falls into place. Here's such a method (test for
existence of the file *before* passing it to the procedure and make sure
the owning statement is prepared before passing the tib_Column reference):
procedure MyDM.StreamThisBlob(aFileName: string; aColumn: TIB_ColumnBlob);
var
Instream: TFileStream;
begin
Instream := TFileStream.Create(aFileName, fmOpenRead);
try
if Instream.Assigned then
aColumn.Assign(TStream(Instream)); // not certain you need this casting
finally
Instream.Free;
end;
end;
.......................................
Invocation code:
...
var
a1: string;
begin
...
with MyDM.ib_dsql1 do
begin
if not Prepared then Prepare;
<assign your non-blob parameters>;
a1 := 'c:\a.gif';
if FileExists(a1) then
try
StreamThisBlob(a1, ParamByName('BlobParam'));
except
<call code to handle the exception>
end;
...
if not ParamByName('BlobParam').Assigned then
ParamByName('BlobParam').Clear; //ensures empty blob is null
...
<do any other assignments>
Execute;
end;
...
end;
The parameter assignment logic is only a suggestion, as I don't know what
you actually want to do if the file is missing or something goes wrong with
the blob-streaming (e.g. someone has the file open) or whatever.
Helen