Thread: Unable to open large object.

Unable to open large object.

From
Yuichi Tanaka
Date:
Hi, all.
Sorry if you have received same mail in pgsql-bugs mailing list.

I wrote C code with libpq using PQsendQuery and lo_open.
In some situation, I cannot open large object.

The situation is following:
1. Open some large object file (using lo_open).
   -> succeed
2. Send query asynchronously (using PQsendQuery).
   -> succeed
3. Get query result (using PQgetResult).
   -> succeed
4. Open another large object file (using pg_lo_open).
   -> fail

As a result, second large object lo_open (No.4) returns false.

But if I execute PQgetResult twice, I can open both large objects.
1. Open some large object file (using lo_open).
   -> succeed.
2. Send query asynchronously (using PQsendQuery).
   -> succeed.
3. Get query result (using PQgetResult).
   -> succeed.
4. Get query result (using PQgetResult).
   -> Returns NULL.
5. Open another large object file (using pg_lo_open).
   -> succeed.

Do I always have to call PQgetResult until this function returns NULL pointer?

----
Yuichi Tanaka (yuichi_tanaka@cybozu.co.jp)

Re: Unable to open large object.

From
Tom Lane
Date:
Yuichi Tanaka <yuichi_tanaka@cybozu.co.jp> writes:
> Do I always have to call PQgetResult until this function returns NULL pointer?

Yes.  Failing to do that is an erroneous use of PQsendQuery, and it has
nothing particularly to do with large objects.  Once you've done
PQsendQuery, you *must* repeat PQgetResult until you get NULL before
any other command can be issued on that connection.

            regards, tom lane

Re: Unable to open large object.

From
Yuichi Tanaka
Date:
> you *must* repeat PQgetResult until you get NULL before
> any other command can be issued on that connection.
Hmm, I understand the behaviour.

Thank you for your reply!

Tom Lane wrote:
> Yuichi Tanaka <yuichi_tanaka@cybozu.co.jp> writes:
> > Do I always have to call PQgetResult until this function returns NULL pointer?
>
> Yes.  Failing to do that is an erroneous use of PQsendQuery, and it has
> nothing particularly to do with large objects.  Once you've done
> PQsendQuery, you *must* repeat PQgetResult until you get NULL before
> any other command can be issued on that connection.
>
>             regards, tom lane
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice

----
Yuichi Tanaka (yuichi_tanaka@cybozu.co.jp)