-----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-----
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;
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to