Thread: Load Image File From PostgreSQL DB

Load Image File From PostgreSQL DB

From
"dbalinglung"
Date:
Dear Expert,
 
 
I'm sorry for my newbie question, I have a dificulty to load image file from field OID type on PostgreSQL with Borland Delphi 7.
 
I would like to showing image file with TDBImage component to Delphi Form, but the image file can't display, any sugestion for me about how can i do to show the image file with Borland Delphi 7 and PostgreSQL 8.2.x. The image file saving on PostgreSQL 8.2.X table with OID Field Type.
 
 
Many thanks and Regards,
 
 
Alam Surya
 

Re: Load Image File From PostgreSQL DB

From
Julius Tuskenis
Date:
Hi, dbalinglung.

You are probably confusing types oid and lo or bytea. There's no way you
could put a image into oid column. I'm using bytea type without problems.
Also check "bytea as lo" checkbox in ODBC dialog (if you use ODBC). Also
TDBImage is no good if you want to use jpg files. I found an alternative
- EDBImage.

Hope that helps. Good luck.

Julius Tuskenis



dbalinglung rašė:
> Dear Expert,
>
>
> I'm sorry for my newbie question, I have a dificulty to load image
> file from field OID type on PostgreSQL with Borland Delphi 7.
>
> I would like to showing image file with TDBImage component to Delphi
> Form, but the image file can't display, any sugestion for me about how
> can i do to show the image file with Borland Delphi 7 and PostgreSQL
> 8.2.x. The image file saving on PostgreSQL 8.2.X table with OID Field
> Type.
>
>
> Many thanks and Regards,
>
>
> *Alam Surya*
>

Re: Load Image File From PostgreSQL DB

From
"dbalinglung"
Date:

Hi2 Julius,
 
Thanks for your reply, present i using oid data type for store image file, and good working without problem too if i open and showing with PHP, but i'm verry dificulty to showing the image file using delphi 7.
 
also i'm not using third party like ODBC but i'm directly connected to PostgreSQL Database using Zeos Component.
 
Any sugestion for me bro ?
 
many thanks and regards,
 
 
dbalinglung
 
 
>----- Original Message -----
>From: "Julius Tuskenis" <julius.tuskenis@gmail.com>
>Sent: Tuesday, December 30, 2008 2:46 PM
>Subject: Re: [GENERAL] Load Image File From PostgreSQL DB
>
> Hi, dbalinglung.
>
> You are probably confusing types oid and lo or bytea. There's no way you
> could put a image into oid column. I'm using bytea type without problems.
> Also check "bytea as lo" checkbox in ODBC dialog (if you use ODBC). Also
> TDBImage is no good if you want to use jpg files. I found an alternative
> - EDBImage.
>
> Hope that helps. Good luck.
>
> Julius Tuskenis
>
>

Re: Load Image File From PostgreSQL DB

From
"dbalinglung"
Date:

Ok, I'll try your sugestion, many thanks bro.
 
Regards,
 
 
dbalinglung
 
 
>----- Original Message -----
>From: "Julius Tuskenis" <julius.tuskenis@gmail.com>
>To: "dbalinglung" <alamsurya@centrin.net.id>
>Sent: Tuesday, December 30, 2008 5:39 PM
>Subject: Re: [GENERAL] Load Image File From PostgreSQL DB
>
>I seriously doubt you could store an image in oid typed column, because
> "The oid type is currently implemented as an unsigned four-byte
> integer." (from postgresql 8.2 manual). I too use Zeos with no problems
> using bytea type.
>
> Julius Tuskenis
>
>

Re: Load Image File From PostgreSQL DB

From
"Albe Laurenz"
Date:
dbalinglung wrote:
>> I seriously doubt you could store an image in oid typed column, because 
>> "The oid type is currently implemented as an unsigned four-byte 
>> integer." (from postgresql 8.2 manual). I too use Zeos with no problems 
>> using bytea type.
>
> Ok, I'll try your sugestion, many thanks bro.

Large Objects (http://www.postgresql.org/docs/current/static/largeobjects.html)
use OID columns, and they work fine for storing binary data like images.

But bytea will work just as fine.

Yours,
Laurenz Albe

Re: Load Image File From PostgreSQL DB

From
Julius Tuskenis
Date:
Hello, Albe

In the article you provided it is said that "The return value is the OID
that was assigned to the new large object..." (function Oid
lo_creat(PGconn *conn, int mode);). That means that not the large object
is stored in OID field - its just the reference to it.
Any way I find it much easier to get a relatively small blob in a result
set and not directly using lo_read function, because in delphi zeos
components does work with  libpq, so theres no need to bypass them?

Julius Tuskenis



Albe Laurenz rašė:
> dbalinglung wrote:
>
>>> I seriously doubt you could store an image in oid typed column, because
>>> "The oid type is currently implemented as an unsigned four-byte
>>> integer." (from postgresql 8.2 manual). I too use Zeos with no problems
>>> using bytea type.
>>>
>> Ok, I'll try your sugestion, many thanks bro.
>>
>
> Large Objects (http://www.postgresql.org/docs/current/static/largeobjects.html)
> use OID columns, and they work fine for storing binary data like images.
>
> But bytea will work just as fine.
>
> Yours,
> Laurenz Albe
>
>

Re: Load Image File From PostgreSQL DB

From
"Albe Laurenz"
Date:
Please don't top post.

Julius Tuskenis wrote:
>> Large Objects (http://www.postgresql.org/docs/current/static/largeobjects.html)
>> use OID columns, and they work fine for storing binary data like images.
>
> In the article you provided it is said that "The return value is the OID 
> that was assigned to the new large object..." (function Oid 
> lo_creat(PGconn *conn, int mode);). That means that not the large object 
> is stored in OID field - its just the reference to it.

Yes, that's true.
You'll have to use the large object API to access the data.
All I wanted to point out is that while you cannot store binary data
*IN* an OID column, you can very well do so *USING* an OID column.

> Any way I find it much easier to get a relatively small blob in a result 
> set and not directly using lo_read function, because in delphi zeos 
> components does work with  libpq, so theres no need to bypass them?

Yes, it is easier, and probably in most cases better, to use bytea.
I think that large objects are preferrable ony if
a) you need to store more than 1GB or
b) you need the operations that only large objects provide, like
   reading out only part of the binary data.

I don't quite understand what you wrote about lo_read and libpq,
because libpq provides lo_open.

Yours,
Laurenz Albe

Re: Load Image File From PostgreSQL DB

From
Julius Tuskenis
Date:
Albe Laurenz rašė:
> I don't quite understand what you wrote about lo_read and libpq,
> because libpq provides lo_open.
All I wanted to say, is that it's the components that "talks" to libpq,
so there's not a nice way of programming to violate the route "your code
-> component code -> libpq". So the programmer should choose if he (she)
wants to use libpq directly or via components as mixed way would require
knowledge of how components operate. As I don't (and don't want to) I
use only components.

Julius Tuskenis