Thread: Handling Blobs with libpq
What is the best approach to handle blobs with libpq ? I've read in documentation that there are 2 ways: 1- Bytea 2- Larges objects (lo_import) My main need is storing pictures (like Jpegs etc) or small blobs. Doc says that (2) is more appropriate but I need to work with blobs in memory, not from files. Thanks for your help. ------------------------------------------------------------------------ --- Stephane ------------------------------------------------------------------------ ---
Stéphane Pinel <spinel@noos.fr> writes: > What is the best approach to handle blobs with libpq ? > > I've read in documentation that there are 2 ways: > > 1- Bytea > 2- Larges objects (lo_import) > > My main need is storing pictures (like Jpegs etc) or small blobs. Doc > says that (2) is more > appropriate but I need to work with blobs in memory, not from files. You don't have to use lo_import()--you can write from memory to a large object using lo_write(), and read an LO (or part of one) into memory using lo_read(). See the documentation. -Doug
I'd be appreciative if someone could give or point me to a working example of storing/retrieving images via bytea. -- thanks, reid -----Original Message----- From: Doug McNaught [mailto:doug@mcnaught.org] Sent: Thursday, March 20, 2003 11:50 AM To: Stéphane Pinel Cc: PostgreSQL-general Subject: Re: [GENERAL] Handling Blobs with libpq Stéphane Pinel <spinel@noos.fr> writes: > What is the best approach to handle blobs with libpq ? > > I've read in documentation that there are 2 ways: > > 1- Bytea > 2- Larges objects (lo_import) > > My main need is storing pictures (like Jpegs etc) or small blobs. Doc > says that (2) is more appropriate but I need to work with blobs in > memory, not from files. You don't have to use lo_import()--you can write from memory to a large object using lo_write(), and read an LO (or partof one) into memory using lo_read(). See the documentation. -Doug ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.orgso that your message can get through to the mailing list cleanly
On Thursday 20 March 2003 17:03, Reid Thompson wrote: > I'd be appreciative if someone could give or point me to a working example > of storing/retrieving images via bytea. I don not understand the question, "bytea" is the data type that can hold any binary data, so the "picture" is just a way to interpret that data. If you are asking for sample how to read and write "bytea", there are attached files from postgres sql driver for QT library. It is not the original QT driver, because it does not know how to handle "bytea", and "blobs", and have some serious errors in code, so I made my own plugin. From the source you can see how "bytea" and "blobs" are read and written. Based on this sql plugin I wrote set of database objects, and one of those objects is "PgPicture". PgPicture simply takes "QByteArray" from driver, does some work on it and shows the picture on the screen. For postgres version 7.3 it is working fine, but in previous releases PQEscabeBytea had errors, and some pictures that I was using to test the library could not be saved.