Recent

Author Topic: [SOLVED]Firebird Blobs  (Read 7041 times)

braximo

  • Jr. Member
  • **
  • Posts: 79
[SOLVED]Firebird Blobs
« on: May 04, 2011, 03:12:51 am »
Good Day Developers!

I am having a hard time reading/writing images(files) to my firebird databases blob. I am currently using lazarus 09.30 and firebird 2.1.3.

I used to do this with vb6 but i am having a hard time doing it with lazarus.
 
Any ideas?
« Last Edit: May 06, 2011, 11:59:04 am by braximo »
Ubuntu 16.04 Lazarus 1.6

fredycc

  • Sr. Member
  • ****
  • Posts: 264
Re: Firebird Blobs
« Reply #1 on: May 04, 2011, 04:41:20 am »
Hi braximo, check this piece of code for reading blob, I hope will be useful:

Quote
var
  SQLQuery1 : TSQLQuery;
  Trx1 : TSQLTransaction;
  SQLQuery1PHOTO: TBlobField;
  m: TStream;

begin
    /*Create Components*/
    Trx1 := TSQLTransaction.Create(nil);
    Trx1.DataBase := IBConnection1;
    SQLQuery1 := TSQLQuery.Create(nil);
   
    /*prepare param in runtime*/
    SQLQuery1PHOTO := TBlobField.Create(nil);
    SQLQuery1PHOTO.DataSet := SQLQuery1;
    SQLQuery1PHOTO.FieldName := 'PHOTO';
    SQLQuery1PHOTO.Size := 8;

    /*Assign transaction*/
    SQLQuery1.Transaction := Trx1;

   /*Add query*/   
    SQLQuery1.SQL.Add(Format('Select PHOTO from employee where emp_no = %0:s',[Edit1.Text]));

    /*Active Query*/
    SQLQuery1.Active := True;
   
   /*Validate Blob */
    if SQLQuery1PHOTO.IsNull then
       Image1.Picture:= nil
    else
    begin
     /*Display picture*/
     Image1.Picture.Graphic:= TJpegImage.Create;
     m:= SQLQuery1.CreateBlobStream(SQLQuery1PHOTO, bmRead);
     Image1.Picture.Graphic.LoadFromStream(m);
     SQLQuery1PHOTO.Free;
     m.Free;

    end;
    /*Commit transaction*/
    Trx1.Commit;

    /*Free variables*/
    SQLQuery1.Free;
    Trx1.Free; 

braximo

  • Jr. Member
  • **
  • Posts: 79
Re: Firebird Blobs
« Reply #2 on: May 04, 2011, 05:04:00 am »
Thanks for the reply!

Any idea about this: "identifier not found "TBlobField"
Ubuntu 16.04 Lazarus 1.6

braximo

  • Jr. Member
  • **
  • Posts: 79
Re: Firebird Blobs
« Reply #3 on: May 04, 2011, 06:08:05 am »
Sorry about the identifier problem, I forgot to place DB in my uses.
Try to study the code. If you have any other solutions, please help.
Ubuntu 16.04 Lazarus 1.6

braximo

  • Jr. Member
  • **
  • Posts: 79
Re: Firebird Blobs
« Reply #4 on: May 05, 2011, 04:43:37 am »
Could anyone teach me how to write files in blob fields?

thanks!
Ubuntu 16.04 Lazarus 1.6

braximo

  • Jr. Member
  • **
  • Posts: 79
Re: Firebird Blobs
« Reply #5 on: May 06, 2011, 11:23:35 am »
Forget It Guys, I found the solution.

Thanks anyway.
Ubuntu 16.04 Lazarus 1.6

 

TinyPortal © 2005-2018