Обсуждение: Postgresql + lo

Поиск
Список
Период
Сортировка

Postgresql + lo

От
Florian Baumert
Дата:
Hi there,

I have a major problem with postgresql 6.5. In my database, I've
created the lo-type, as explained in the FAQ. I have a table which
uses this type. If i want to acces it with (eg) perl     use Pg; $conn = Pg::connectdb("dbname=test");$lobj_fd =
$conn->lo_open(33025,PGRES_INV_WRITE|PGRES_INV_READ); print $lobj_fd;
 
The xinv33025 exists and the oid 33025 was created by a call to lo_create.

What happens is that it writes a -1 to the screen and a database-error "ERROR: lo_lseek: invalid large obj descriptor
(0)"
The same happens, if I use php3 (compiled against postgresql) and the
ODBC-driver for windoes (06.40.0006). If i compile and start
examples/test/lotest.c (hope, it's the right name) in the
posrgresql-src directory, it works!!!

If I comment out the call to lo_lseek in lo_open, it works further,
but then I get problems in lo_close (same error as above, only in
lo_close).

What happens here?

Thanx in advance
     Florian

                     \\|||//                     |     |                     (.) (.)
===================oOO==(_)==OOo=========================
! Florian Baumert                                       !
? Birkenweg 2                                           ?
! D-61267 Neu-Anspach                                   ?
! Tel.:06081-9 63 63 7                                  !
? ===================================================== ?
! baumert@plt.de                             www.plt.de !
=========================================================






Re: [INTERFACES] Postgresql + lo

От
Tom Lane
Дата:
Florian Baumert <baumert@plt.de> writes:
> What happens is that it writes a -1 to the screen and a database-error "ERROR: lo_lseek: invalid large obj descriptor
(0)"

This needs to go into the FAQ, I think, 'cause you're about the third
person to ask the same question in the past couple weeks.

You need to wrap a transaction ("begin" ... "commit") around any use
of a large object handle, ie any lo_open ... lo_close sequence.

This requirement has always been in the LO docs, but Postgres 6.5 is the
first release that enforces the rule (by closing all open LO handles at
end of statement, if not within a transaction).  In prior versions,
you could sometimes get away with not using a transaction, but it
was NOT reliable.
        regards, tom lane


Re: [INTERFACES] Postgresql + lo

От
Tom Lane
Дата:
Florian Baumert <baumert@plt.de> writes:
> What happens is that it writes a -1 to the screen and a database-error
> "ERROR: lo_lseek: invalid large obj descriptor (0)"

You need "begin transaction"/"end transaction" around the use of the
LO handle (ie, surrounding lo_open ... lo_close).

The documentation has always stated that lo_open must be wrapped in
a transaction, but Postgres versions before 6.5 didn't enforce that
rule.  (Instead, they'd just fail occasionally if you broke it :-(.)

6.5 enforces the rule by auto-closing LO handles at transaction
commit --- which will be instantly upon completion of the lo_open
command, if you are not inside a transaction; so the first attempt
to do anything with the handle will draw "invalid large obj
descriptor".

This is definitely getting to be a FAQ...
        regards, tom lane


Re: [INTERFACES] Postgresql + lo

От
"Jeremy Bettis"
Дата:
I ran into this same problem. I think some of the source of the confusion is
that the perl5 interface documentation do not mention any such restriction.
--
Jeremy Bettis
jeremy@hksys.com


> You need "begin transaction"/"end transaction" around the use of the
> LO handle (ie, surrounding lo_open ... lo_close).
>
> The documentation has always stated that lo_open must be wrapped in
> a transaction, but Postgres versions before 6.5 didn't enforce that
> rule.  (Instead, they'd just fail occasionally if you broke it :-(.)