Subject Re: [IBO] No way to append to BLOBs using CreateBlobStream
Author mjmyllym
Hi,

This below issue is still unresolved. Seems like a bug in IBO because it is so easy to reproduce. I can send the project and example database for analysis?

This is crucial for my project and so far it is the only (but showstopping) obstacle in taking the otherwise-so-wonderful IBO into use.

Thank you for help in advance.

Regards,
Marko



--- In IBObjects@yahoogroups.com, "mjmyllym" <marko.myllymaki@...> wrote:
>
> Jason,
>
> Thanks, but yes I did try bsmReadWrite. Using bsmWrite in the example code was a typo because I tried that too.
>
> bsmReadWrite results in the exact same behavior: stream of size 0.
>
> Then, even more, running the same routine twice and trying to .Post the changes in the middle part (where I try to rewrite the beginning of the stream with the buffer) I now get an error "Record was not located to update."
>
> See below for latest code.
>
> Any new ideas?
>
> Marko
>
>
> procedure TForm1.Button5Click(Sender: TObject);
> var
> Buff : array of byte;
> F : TField;
> St : TIB_BlobStream;
> I : integer;
> begin
> SetLength (Buff, 10);
> for I := 0 to 10 do Buff [I] := I;
>
> IB_Query1.SQL.Text := 'select * from curvey where rown = 2';
> IB_Query1.Open;
> St := TIB_BlobStream (IB_Query1.CreateBlobStream (IB_Query1.FieldByName ('datax'), bsmRead));
> ShowMessage (IntToStr (St.Size)); // => Result in "0" on the first round, "10" on the second
> St.Free;
>
> IB_Query1.Close;
> IB_QUery1.RequestLive := true;
> IB_Query1.Open;
> IB_Query1.Edit;
>
> St := TIB_BlobStream.CreateForColumn (IB_Query1.FieldByName ('datax'), bsmReadWrite);
>
> ShowMessage (IntToStr (St.Size)); // => Result in "0"
> St.Seek (0, soFromBeginning);
> St.WriteBuffer (Buff [0], 10);
> ShowMessage (IntToStr (St.Size)); // => Results in "10"
> IB_Query1.Post; // Error here on 2nd round
> St.Free;
>
> IB_Query1.Close;
> IB_QUery1.RequestLive := true;
> IB_Query1.Open;
> IB_Query1.Edit;
>
> St := TIB_BlobStream (IB_Query1.CreateBlobStream (IB_Query1.FieldByName ('datax'), bsmReadWrite));
> ShowMessage (IntToStr (St.Size)); // => Results in "0"
> St.Seek (0, soFromEnd);
> ShowMessage (IntToStr (St.Position)); // => Results in "0" even though there is data
>
> St.WriteBuffer (Buff [0], 10);
> IB_Query1.Post;
> St.Free;
> end;
>
>
>
>
>
> --- In IBObjects@yahoogroups.com, "IBO Support List" <supportlist@> wrote:
> >
> > bmWrite clears out previous information.
> >
> > Did you try bmReadWrite?
> >
> > Jason
> >
> > -----Original Message-----
> > From: IBObjects@yahoogroups.com [mailto:IBObjects@yahoogroups.com] On Behalf
> > Of mjmyllym
> > Sent: 07 November 2012 08:32 AM
> > To: IBObjects@yahoogroups.com
> > Subject: [IBO] No way to append to BLOBs using CreateBlobStream
> >
> > Hello,
> >
> > I have a critical problem in appending data to binary BLOBs using
> > CreateBlobStream.
> >
> > I am using IBO4_9_14_b52, Delphi 6. Tried both Firebird 2.1 and 2.0;
> > different BLOB types etc.
> >
> > The thing is I can read from a BLOB and write to a BLOB but cannot append.
> > Opening a BLOB with existing data with CreateBlobStream in
> > bsmWrite/bsmReadWrite mdoe always results in a stream of size 0! So I cannot
> > seek the stream and append to the end. If I look at the query's data in
> > string format I can see the existing data but not in Stream format.
> >
> > Very simple database:
> >
> > create table curves (
> > rown integer,
> > datax blob sub_type 0,
> > primary key (rown));
> >
> > Then, I have a form with TIBODatabase, IBOQuery or IB_Query (neither works),
> > and a simple test that first reads from a BLOB (ok), then writes a simple
> > array of byte data to a BLOB (ok) and finally tries to append to it =>
> > fails.
> >
> > procedure TForm1.Button5Click(Sender: TObject);
> > var
> > Buff : array of byte;
> > F : TField;
> > St : TIB_BlobStream;
> > I : integer;
> > begin
> > SetLength (Buff, 10);
> > for I := 0 to 10 do Buff [I] := I;
> >
> > // First read from the BLOB, might be empty
> > IB_Query1.SQL.Text := 'select * from curves where rown = 1';
> > IB_Query1.Open;
> > St := TIB_BlobStream (IB_Query1.CreateBlobStream (IB_Query1.FieldByName
> > ('datax'), bsmRead));
> > ShowMessage (IntToStr (St.Size)); // => Result in "0" on the first
> > round, "10" on the second
> > St.Free;
> >
> > // Then write to:
> > IB_Query1.Close;
> > IB_QUery1.RequestLive := true;
> > IB_Query1.Open;
> > IB_Query1.Edit;
> >
> > St := TIB_BlobStream (IB_Query1.CreateBlobStream (IB_Query1.FieldByName
> > ('datax'), bsmReadWrite));
> > ShowMessage (IntToStr (St.Size)); // => Result in "0"
> >
> > St.WriteBuffer (Buff [0], 10);
> > ShowMessage (IntToStr (St.Size)); // => Results in "10", as it
> > should
> > IB_Query1.Post;
> > St.Free;
> >
> > // Now let's try to append:
> > IB_Query1.Close;
> > IB_QUery1.RequestLive := true;
> > IB_Query1.Open;
> > IB_Query1.Edit;
> >
> > St := TIB_BlobStream (IB_Query1.CreateBlobStream (IB_Query1.FieldByName
> > ('datax'), bsmWrite));
> > ShowMessage (IntToStr (St.Size)); // => Results in "0".. like there
> > is no data!
> >
> > St.WriteBuffer (Buff [0], 10);
> > IB_Query1.Post;
> > St.Free;
> > end;
> >
> >
> > Frustrating.
> >
> > I CAN append to the blob if I use e.g.
> >
> > St := TMemoryStream.Create;
> > TBlobField (F).SaveToStream (St);
> > ...
> > St.WriteBuffer (Data, Length);
> > TBlobField (F).LoadFromStream (St);
> >
> > but this is very ineffective because I need to write to the BLOBs all the
> > time, i.e. several times a minute. Also this results in a huge database
> > bloating.
> >
> > Thank you in advance for help.
> >
> > Best regards,
> > Marko Myllymaki
> >
> >
> >
> >
> > ------------------------------------
> >
> > ___________________________________________________________________________
> > IB Objects - direct, complete, custom connectivity to Firebird or InterBase
> > without the need for BDE, ODBC or any other layer.
> > ___________________________________________________________________________
> > http://www.ibobjects.com - your IBO community resource for Tech Info papers,
> > keyword-searchable FAQ, community code contributions and more !
> > Yahoo! Groups Links
> >
>