Home > Archive > PostgreSQL Newbies > June 2005 > PQconsumeInput() usage in PQgetCopyData()









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author PQconsumeInput() usage in PQgetCopyData()
Volkan YAZICI

2005-06-06, 3:23 am

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.

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql
.org

Tom Lane

2005-06-06, 9:23 am

Volkan YAZICI <volkan.yazici@gmail.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

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql
.org

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com