Thread: lo_import invalid large object descriptor

lo_import invalid large object descriptor

From
Markus Mehrwald
Date:
Hello,

I tried to insert an image in my database with lo_import. The error I
get is "invalid large object descriptor: 0". If I try to create an oid I
get a valid one but with lo_import it seems not to work. The connection
is ok as well.
The folloing code produces the output after the code.

if (PQstatus(connDB) == CONNECTION_OK)
    std::cout << "CONNECTION_OK" << std::endl;
Oid oid = lo_creat(connDB, INV_READ | INV_WRITE);
std::cout << oid << std::endl;
std::cout << PQerrorMessage(connDB) << std::endl;
std::cout << lo_import(connDB, "/tmp/image.vtk") << std::endl;
std::cout << PQerrorMessage(connDB) << std::endl;


Output:
CONNECTION_OK
25211

0
FEHLER:  ungültiger Large-Object-Deskriptor: 0

Here is the version string of my db:
PostgreSQL 8.3.3 on x86_64-redhat-linux-gnu, compiled by GCC gcc (GCC)
4.3.0 20080428 (Red Hat 4.3.0-8)

Can anyone tell me please what is wrong?

Thank you,
Markus

Re: lo_import invalid large object descriptor

From
Tom Lane
Date:
Markus Mehrwald <mehrwald@ira.uka.de> writes:
> I tried to insert an image in my database with lo_import. The error I
> get is "invalid large object descriptor: 0".

lo_import has to be called within a transaction block (BEGIN/COMMIT).
The documentation is not very clear about that :-(

(Actually, rather than fix the documentation we probably ought to fix
the code --- there's enough infrastructure in libpq now that it could
tell whether it needs to start its own transaction or not.)

            regards, tom lane