Recent

Author Topic: DBImage: how to use?  (Read 23848 times)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
DBImage: how to use?
« on: January 10, 2014, 12:59:17 pm »
Going by the Delphi and Lazarus edit: help, dbimage should be really easy to use: set datasource, set the field name to the field containing your image blob and it should display images stored there (and at least in Delphi, allow you to copy/paste image data).

I've modified a tutorial db (which had a dbgrid, navigator control etc): added dbimage control, did the above. Had to modify Firebird employee.fdb sample db to add a PHOTO field (blob) = please find it included in the zip.

However, I don't see any indication of an image (my db has mostly empty data).
What am I doing wrong?

Zip with source and database:
Edit: updated, see below.

Thanks.
« Last Edit: January 10, 2014, 03:14:29 pm by BigChimp »
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

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: DBImage: how to use?
« Reply #1 on: January 10, 2014, 02:07:30 pm »
Never tried it with Lazarus, but Delphi suffered from the fact that DBImage could only handle bmp files.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: DBImage: how to use?
« Reply #2 on: January 10, 2014, 02:15:37 pm »
It should work, teh code is there and is called when the current record is changed the only thing I see is that the stream lacks the image description so the LoadPicture method does not know how to handle the blob and it simple ignores it.

I remember a debate earlier this year of why the current implementation was incompatibilite with the rest of the world and a bug report with a patch was introduced to remove the extra bytes at the start. I guess this is the after effect. I still am against removing them.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage: how to use?
« Reply #3 on: January 10, 2014, 02:33:27 pm »
Thanks for the response, taazz!

That patch *added* support for Delphi style/custom image handling (see OnDBImageWrite, IIRC). It didn't change default behaviour. By default, IIUC, dbimage should still write the file extension etc.
see
http://wiki.lazarus.freepascal.org/Lazarus_1.2.0_release_notes#TDBImage


What should happen though with NULL values for the PHOTO field (i.e. empty blobs) Shouldn't I see some square/image placeholder where I can paste my picture?

Also, I don't really understand this part:
Quote from: taazz
the only thing I see is that the stream lacks the image description so the LoadPicture method does not know how to handle the blob and it simple ignores it.
... should I add some code somewhere? Isn't dbimage supposed to do this for me (copy out file extension to the blob followed by the binary image)?
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

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: DBImage: how to use?
« Reply #4 on: January 10, 2014, 03:12:32 pm »
DBImage should save the blob as
4 bytes extension length (usualy 3 or 4) |extension (eg bmp or jpg)| the image unaltered.

Your blob stream has no bmp in front as it should or I couldn't see it from IBExpert light.
DBImage has no mouse capabilities you need to add code to do so your self and no it never shown a rectangle which you could click to load data from disk.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage: how to use?
« Reply #5 on: January 10, 2014, 03:14:14 pm »
Edit: posted before reading previous message...
Decided I was probably too optimistic about the copy/paste thing being possible, so added a button that puts a file into the dbimage picture and tries to save the result.

Get error message
An error occurred while applying the updates in a record
DBConnection : PrepareStatement
attempted update of read-only column
and indeed the image is not saved.

Don't tell me I have to manually deal with CreateBlobStream etc ;)
(Argh, I hate GUI controls... but you can't live without them ;) )

New zip:
http://ubuntuone.com/0KmpZX0xFF436381Ymib9w

Up to date source code repo without .fdb though:
https://bitbucket.org/reiniero/fpc_laz_patch_playground/src
sqldbtutorialimage
« Last Edit: January 10, 2014, 03:20:37 pm by BigChimp »
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

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage: how to use?
« Reply #6 on: January 10, 2014, 03:16:11 pm »
(Posted previous post before reading this one)
Your blob stream has no bmp in front as it should or I couldn't see it from IBExpert light.
Ah, now I know what you mean: you're talking about the existing blobs/images in my initial upload. Yes, those are regular jpg files, and it's no problem that they don't display etc.
I was testing with the records at the end where the blobs are empty/null.

Sorry about that.
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

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: DBImage: how to use?
« Reply #7 on: January 10, 2014, 03:57:56 pm »
do the following

1) drop a TOpenPictureDialog on your form.
2) doubleclick on the onclick of the DBImage1 and paste this code.
Code: [Select]
  if OpenPictureDialog1.Execute then begin
    DBImage1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
  end;
3)run your application
4) select any record you like and press the edit button on the dbnavigator.
5) click on your image and select any image you like.
6) press the post button on the dbnavigator.

change records in the grid and see if re visiting the specific record it shows the new image.
There is a small chance that you must use persistent fields namely after you create the fields in the designer select the photo field and change the blobtype to ftgraphic and try again. Are you sure that the subtype 0 on the firebird blob is for binary data and not for text? I ask because the default setting comes back as ftwidestring instead of ftgraphic and makes to want to check the subtype meaning again.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage: how to use?
« Reply #8 on: January 10, 2014, 04:06:31 pm »
Thanks.

Blob subtype 0 is binary data
http://www.firebirdfaq.org/faq165/

Tried your suggestion. Edit/post works, scrolling back & forth too (including showing the image), but when calling applyupdates I still get the update readonly field problem.

Updated repository with new code.
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

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: DBImage: how to use?
« Reply #9 on: January 10, 2014, 04:56:16 pm »
I guess the problem you have is that the applyupdate tries to update the blob qith an update sql command instead of using the blobostreams to post the data and that seems is not supported from firebird. Please keep in mind that this is speculation at this point and I haven't checked anything.

Late me say at this point that I hate the buffered editing implementation of sqlDB and it is the main reason that I am looking at ZEOS as an alternative.

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage: how to use?
« Reply #10 on: January 10, 2014, 04:59:40 pm »
Well yes, that would be my guess as well.
Very strange - one would expect GUI components to just work together. I suppose I can
- run applyupdates for everything except dbimage stuff
- manually commit dbimage stuff if it comes up
but then I'll be commiting 2 transactions instead of perhaps 1 which the user wants.
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

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: DBImage: how to use?
« Reply #11 on: January 10, 2014, 05:05:41 pm »
DBImage does not know or care about the underline dataset it uses the Tblobstream to read and write data and that's all it should know. if the dataset is buffered and keeps the data in the client side or it is directly connected to the database and send the data across the galaxy in to a small planet in an other solar system it is not its business to know. If the blob stream says "everything is fine" then it is fine as far as thedbimage is concerned and rightly so, do you imagine what it would happen if dbimage required to take in to account the underline database as well before committing anything?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage: how to use?
« Reply #12 on: January 10, 2014, 05:08:28 pm »
Well yes of course, but the datasource & tsqlquery should be handling the blobstream for me. And they don't (appear to be).

Edit: and yes, tsqlquery has weird issues with blobs - but the GUI controls/Lazarus part should abstract that away IMO.
You should just be able to slap together some controls and have a working solution... sort of the idea of RAD IMO.
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

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DBImage: how to use?
« Reply #13 on: January 10, 2014, 05:22:44 pm »
I suppose I won't escape diving into the source code sooner or later as I suspect more people must have wanted similar things as I.

Done for today though ;)
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

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: DBImage: how to use?
« Reply #14 on: January 10, 2014, 06:15:31 pm »
Well before runding I should make it a habit to check my facts first so should you. After a couple of minutes of debuging and playing around with persistent fields I can say that the blob update is not cause of your problems. The Full_Name field is since it is a computed field and not a physical one you must remove it from the update query. Do something along the lines of
Code: [Select]
procedure TForm1.SQLQuery1AfterOpen(DataSet : TDataSet);
begin
  dataset.FieldByName('FULL_NAME').ProviderFlags := [];
end;

and see how far that will get you.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018