Recent

Author Topic: Can't write an image into BLOB MySql, Zeos  (Read 9759 times)

syalyshev

  • New Member
  • *
  • Posts: 29
Can't write an image into BLOB MySql, Zeos
« on: May 09, 2012, 02:09:12 am »
Windows. I want to write Print Screen into Blob-field of Mysql table. The Stream is filled with Clipboard from Print Screen.
The following code works (compiled correctly) but no record to MySql table is added.
...
if (ZTable.State <> dsEdit) and (ZTable.State <> dsInsert) then ZTable.Edit;
Stream.Position := 0;
TBlobField(ZTable.FieldByName('image_inform')).LoadFromStream(Stream);
...
Maybe ZTable parameters are wrong? Please help!
« Last Edit: May 09, 2012, 02:11:06 am by syalyshev »

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Can't write an image into BLOB MySql, Zeos
« Reply #1 on: May 09, 2012, 09:54:27 am »
Your code works fine with zeos 7.0.0-dev and fpc 2.7.1. Here is my test:
Code: [Select]
var
  fs:TFileStream;
begin
  fs:=TFileStream.Create('b:\test.jpg',fmOpenRead);
  ZTable1.Open;
  ZTable1.Insert;
  TBlobField(ZTable1.FieldByName('filedata')).LoadFromStream(fs);
  TBlobField(ZTable1.FieldByName('bindata')).LoadFromStream(fs);
  ZTable1.Post;
  fs.Free;
end;

How did you define the blob field in the database? 'filedata' is defined in my test table as LongText and binary data doesn't get stored correctly. 'bindata' is a LongBlob and data is stored correctly.
Quote
but no record to MySql table is added.
No record at all or a record with an empty blob field?


syalyshev

  • New Member
  • *
  • Posts: 29
Re: Can't write an image into BLOB MySql, Zeos
« Reply #2 on: May 11, 2012, 08:08:57 am »
Thanks for your reply!
I simply can't realize your recommendations having no fpc 2.7.1 and zeos 7.0.0. Could you give me an idea where to get them?

syalyshev

  • New Member
  • *
  • Posts: 29
Re: Can't write an image into BLOB MySql, Zeos
« Reply #3 on: May 11, 2012, 08:19:08 am »
Thanks for your reply!
I simply can't realize your recommendations having no fpc 2.7.1 and zeos 7.0.0. Could you give me an idea where to get them?
Quote
How did you define the blob field in the database? 'filedata' is defined in my test table as LongText and binary data doesn't get stored correctly. 'bindata' is a LongBlob and data is stored correctly.
My blob field is defined as LongBlob. My MySql table has two fields only 'idx' and 'image_inform'. No record added after '... LoadFromStream(stream);' statement.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Can't write an image into BLOB MySql, Zeos
« Reply #4 on: May 11, 2012, 08:29:45 am »
Get it using SVN?

Found this older wiki page http://wiki.lazarus.freepascal.org/Zeos_tutorial (I'm sure updates are welcome, I don't use Zeos myself) and http://wiki.lazarus.freepascal.org/ZeosDBO

Forum search on "zeos 7.0 svn" gives hits such as
http://lazarus.freepascal.org/index.php/topic,16615.msg90663.html#msg90663
... which describes downloading an archive if you don't use subversion...

Good luck.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Can't write an image into BLOB MySql, Zeos
« Reply #5 on: May 11, 2012, 10:32:10 am »
I simply can't realize your recommendations having no fpc 2.7.1 and zeos 7.0.0. Could you give me an idea where to get them?
It wasn't a recommendation but a simple reminder of my environment and a subtle reminder to you that specifying the used environment is necessary when asking for help ;)
When using zeos, fpc 2.6.0 is good enough. I wouldn't upgrade to 2.7.1.
See BigChimps reply for getting Zeos.

My blob field is defined as LongBlob. My MySql table has two fields only 'idx' and 'image_inform'. No record added after '... LoadFromStream(stream);' statement.
I hope you didn't forget the ZTable1.Post and, in case Ztable1.CachedUpdates is true, a Ztable1.ApplyUpdates .

syalyshev

  • New Member
  • *
  • Posts: 29
Re: Can't write an image into BLOB MySql, Zeos
« Reply #6 on: June 17, 2012, 02:02:24 pm »
Hello, dear ludob!
I'm very grateful for your replies.
Now I have Lazarus-1.1-37668-fpc-2.7.1-20120617-win32.exe on my mashine and tried to install the last version of ZEOSDBO. Unfortunately I failed to install zeos package. Could you kindly send your zeosdbo package working with fpc-2.7.1 to me: syalyshev@mail.ru?

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Can't write an image into BLOB MySql, Zeos
« Reply #7 on: June 17, 2012, 09:21:52 pm »
I'm using the version from the official svn repository. A tarball can be downloaded from http://zeoslib.svn.sourceforge.net/viewvc/zeoslib/trunk/?view=tar

syalyshev

  • New Member
  • *
  • Posts: 29
Re: Can't write an image into BLOB MySql, Zeos
« Reply #8 on: June 19, 2012, 11:59:52 am »
Quote
I'm using the version from the official svn repository.
Me too, but it can't be installed... >:D
Thanks anyway!

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Can't write an image into BLOB MySql, Zeos
« Reply #9 on: June 19, 2012, 12:17:45 pm »
Quote
Me too, but it can't be installed...
Where does it fail? What is the message?

syalyshev

  • New Member
  • *
  • Posts: 29
Re: Can't write an image into BLOB MySql, Zeos
« Reply #10 on: June 19, 2012, 04:24:53 pm »
Surprize!!! Everything installed!!! Though I don't understand how... Maybe because I've just refreshed zeoslib svn.
Now i'll make another attempt to write the blob...
Thanks a lot once more!!!

 

TinyPortal © 2005-2018