send Describe Portal message in PQsendPrepare
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi.
What is the reason why PQsendPrepare function does not send a
Describe Portal message?
Just as a proof of concept, I wrote a very simple patch, attached, and
it *seems* to work.
Sending a Describe Portal message, make it possible for PQsendPrepare
function to *return* a PGresult with more useful informations, instead
of just the result status.
Thanks Manlio Perillo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAlEZT8IACgkQscQJ24LbaUT0VwCcCGKGD6CYrb53B/z+1SdB8vX5
cWkAnjOkSxCVFRo32qzIegY1UhddxBcI
=D+Qj
-----END PGP SIGNATURE-----
Attachments:
prepare-describe.patchtext/x-diff; name=prepare-describe.patchDownload
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 77124ef..f9cee86 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -1265,6 +1265,13 @@ PQsendPrepare(PGconn *conn,
if (pqPutMsgEnd(conn) < 0)
goto sendFailed;
+ /* construct the Describe Portal message */
+ if (pqPutMsgStart('D', false, conn) < 0 ||
+ pqPutc('S', conn) < 0 ||
+ pqPuts(stmtName, conn) < 0 ||
+ pqPutMsgEnd(conn) < 0)
+ goto sendFailed;
+
/* construct the Sync message */
if (pqPutMsgStart('S', false, conn) < 0 ||
pqPutMsgEnd(conn) < 0)
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c
index c605bcd..cca9f90 100644
--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -231,19 +231,6 @@ pqParseInput3(PGconn *conn)
conn->asyncStatus = PGASYNC_READY;
break;
case '1': /* Parse Complete */
- /* If we're doing PQprepare, we're done; else ignore */
- if (conn->queryclass == PGQUERY_PREPARE)
- {
- if (conn->result == NULL)
- {
- conn->result = PQmakeEmptyPGresult(conn,
- PGRES_COMMAND_OK);
- if (!conn->result)
- return;
- }
- conn->asyncStatus = PGASYNC_READY;
- }
- break;
case '2': /* Bind Complete */
case '3': /* Close Complete */
/* Nothing to do for these message types */
@@ -266,7 +253,8 @@ pqParseInput3(PGconn *conn)
break;
case 'T': /* Row Description */
if (conn->result == NULL ||
- conn->queryclass == PGQUERY_DESCRIBE)
+ conn->queryclass == PGQUERY_DESCRIBE ||
+ conn->queryclass == PGQUERY_PREPARE)
{
/* First 'T' in a query sequence */
if (getRowDescriptions(conn, msgLength))
@@ -299,7 +287,8 @@ pqParseInput3(PGconn *conn)
* instead of TUPLES_OK. Otherwise we can just ignore
* this message.
*/
- if (conn->queryclass == PGQUERY_DESCRIBE)
+ if (conn->queryclass == PGQUERY_DESCRIBE ||
+ conn->queryclass == PGQUERY_PREPARE)
{
if (conn->result == NULL)
{
@@ -455,7 +444,8 @@ getRowDescriptions(PGconn *conn, int msgLength)
* PGresult created by getParamDescriptions, and we should fill data into
* that. Otherwise, create a new, empty PGresult.
*/
- if (conn->queryclass == PGQUERY_DESCRIBE)
+ if (conn->queryclass == PGQUERY_DESCRIBE ||
+ conn->queryclass == PGQUERY_PREPARE)
{
if (conn->result)
result = conn->result;
@@ -562,7 +552,8 @@ getRowDescriptions(PGconn *conn, int msgLength)
* If we're doing a Describe, we're done, and ready to pass the result
* back to the client.
*/
- if (conn->queryclass == PGQUERY_DESCRIBE)
+ if (conn->queryclass == PGQUERY_DESCRIBE ||
+ conn->queryclass == PGQUERY_PREPARE)
{
conn->asyncStatus = PGASYNC_READY;
return 0;
Manlio Perillo <manlio.perillo@gmail.com> writes:
What is the reason why PQsendPrepare function does not send a
Describe Portal message?
That would add a round trip, no?
Sending a Describe Portal message, make it possible for PQsendPrepare
function to *return* a PGresult with more useful informations, instead
of just the result status.
That's *definitely* wrong, because the entire point of the PQsend
functions is they don't wait for a server response.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Il 11/02/2013 22:39, Tom Lane ha scritto:
Manlio Perillo <manlio.perillo@gmail.com> writes:
What is the reason why PQsendPrepare function does not send a
Describe Portal message?That would add a round trip, no?
Well, no.
An extra round trip is required with current implementation, since I
need to call PQsendPrepare, wait for server response, call
PQsendDescribePrepared, wait for server response.
Sending a Describe Portal message, make it possible for PQsendPrepare
function to *return* a PGresult with more useful informations, instead
of just the result status.That's *definitely* wrong, because the entire point of the PQsend
functions is they don't wait for a server response.
The PQsendQueryParams sends the following protocol messages:
* Parse
* Bind
* Describe Portal
* Execute
* Sync
and of course does not wait for each response, since this is done in the
state machine.
I noted that PQsendQueryParams sends a Describe Portal message, and I
found it strange that the same is not done by PQsendPrepare.
I wrote the patch to check if this was done due to some technical
reason, but this seems to not be the case.
regards, tom lane
Regards Manlio Perillo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAlEaLvkACgkQscQJ24LbaUSBgACgjASGXyTl+rpHWGAGk5nm7Fnj
T68Anin9iEfbLw75ObHJxU6yfIazEZDS
=ZmPu
-----END PGP SIGNATURE-----
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers