Re: PQconsumeInput() usage in PQgetCopyData()

Lists: pgsql-novice
From: Volkan YAZICI <volkan(dot)yazici(at)gmail(dot)com>
To: PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: PQconsumeInput() usage in PQgetCopyData()
Date: 2005-06-06 08:45:58
Message-ID: 7104a7370506060145364590e5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

Hi,

[Excuse me, if here's the wrong list to ask this question.]

From PQgetCopyData() documentation, it says that:

«When async is true (not zero), PQgetCopyData will not block waiting for
input; it will return zero if the COPY is still in progress but no complete
row is available. (In this case wait for read-ready before trying again; it
does not matter whether you call PQconsumeInput.)»

But in my opinion, a PQconsumeInput() call would matter in here. When
I look at pqGetCopyData3() in src/interfaces/libpq/fe-protocol3.c from
CVS:

974 nodata:
975 /* Don't block if async read requested */
976 if (async)
977 return 0;
978 /* Need to load more data */
979 if (pqWait(TRUE, FALSE, conn) ||
980 pqReadData(conn) < 0)
981 return -2;

If there's no data in sync. mode, pqGetCopyData3() is calling
pqReadData() - just like PQconsumeInput() does. Thus, in my opinion,
user should call PQconsumeInput() in the program flow while using
PQgetCopyData() in async. mode.

Moreover, when I look at pqWait further:

[src/interfaces/libpq/fe-misc.c]
pqWait() -> pqWaitTimed() -> pqSocketCheck():

/*
* Checks a socket, using poll or select, for data to be read, written,
* or both.
* ...
*/
static int
pqSocketCheck(...

To summarize, despite documentation, (as I understand) user should
call PQconsumeInput() while using PQgetCopyData() in async. mode too.
Any comments will be appreciated.

Regards.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Volkan YAZICI <volkan(dot)yazici(at)gmail(dot)com>
Cc: PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: PQconsumeInput() usage in PQgetCopyData()
Date: 2005-06-06 14:28:22
Message-ID: 25796.1118068102@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

Volkan YAZICI <volkan(dot)yazici(at)gmail(dot)com> writes:
> If there's no data in sync. mode, pqGetCopyData3() is calling
> pqReadData() - just like PQconsumeInput() does. Thus, in my opinion,
> user should call PQconsumeInput() in the program flow while using
> PQgetCopyData() in async. mode.

Yeah, I think you are right --- this is an error in the documentation.
It should read more like

When async is true (not zero), PQgetCopyData will not block waiting for
input; it will return zero if the COPY is still in progress but no
complete row is available. (In this case wait for read-ready and then
call PQconsumeInput before calling PQgetCopyData again.)

Will fix. Thanks for pointing it out.

regards, tom lane