Commit 4efcf470 authored by Alvaro Herrera's avatar Alvaro Herrera

Add 'Portal Close' message to pipelined PQsendQuery()

Commit acb7e4eb added a new implementation for PQsendQuery so that
it works in pipeline mode (by using extended query protocol), but it
behaves differently from the 'Q' message (in simple query protocol) used
by regular implementation: the new one doesn't close the unnamed portal.
Change the new code to have identical behavior to the old.
Reported-by: default avatarYura Sokolov <y.sokolov@postgrespro.ru>
Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/202106072107.d4i55hdscxqj@alvherre.pgsql
parent 1632ea43
...@@ -1329,7 +1329,8 @@ PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery) ...@@ -1329,7 +1329,8 @@ PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery)
{ {
/* /*
* In pipeline mode we cannot use the simple protocol, so we send * In pipeline mode we cannot use the simple protocol, so we send
* Parse, Bind, Describe Portal, Execute. * Parse, Bind, Describe Portal, Execute, Close Portal (with the
* unnamed portal).
*/ */
if (pqPutMsgStart('P', conn) < 0 || if (pqPutMsgStart('P', conn) < 0 ||
pqPuts("", conn) < 0 || pqPuts("", conn) < 0 ||
...@@ -1355,6 +1356,11 @@ PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery) ...@@ -1355,6 +1356,11 @@ PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery)
pqPutInt(0, 4, conn) < 0 || pqPutInt(0, 4, conn) < 0 ||
pqPutMsgEnd(conn) < 0) pqPutMsgEnd(conn) < 0)
goto sendFailed; goto sendFailed;
if (pqPutMsgStart('C', conn) < 0 ||
pqPutc('P', conn) < 0 ||
pqPuts("", conn) < 0 ||
pqPutMsgEnd(conn) < 0)
goto sendFailed;
entry->queryclass = PGQUERY_EXTENDED; entry->queryclass = PGQUERY_EXTENDED;
entry->query = strdup(query); entry->query = strdup(query);
......
...@@ -38,6 +38,7 @@ F 26 Parse "" "SELECT 1; SELECT 2" 0 ...@@ -38,6 +38,7 @@ F 26 Parse "" "SELECT 1; SELECT 2" 0
F 12 Bind "" "" 0 0 0 F 12 Bind "" "" 0 0 0
F 6 Describe P "" F 6 Describe P ""
F 9 Execute "" 0 F 9 Execute "" 0
F 6 Close P ""
F 4 Sync F 4 Sync
B NN ErrorResponse S "ERROR" V "ERROR" C "42601" M "cannot insert multiple commands into a prepared statement" F "SSSS" L "SSSS" R "SSSS" \x00 B NN ErrorResponse S "ERROR" V "ERROR" C "42601" M "cannot insert multiple commands into a prepared statement" F "SSSS" L "SSSS" R "SSSS" \x00
B 5 ReadyForQuery I B 5 ReadyForQuery I
...@@ -45,6 +46,7 @@ F 54 Parse "" "SELECT 1.0/g FROM generate_series(3, -1, -1) g" 0 ...@@ -45,6 +46,7 @@ F 54 Parse "" "SELECT 1.0/g FROM generate_series(3, -1, -1) g" 0
F 12 Bind "" "" 0 0 0 F 12 Bind "" "" 0 0 0
F 6 Describe P "" F 6 Describe P ""
F 9 Execute "" 0 F 9 Execute "" 0
F 6 Close P ""
F 4 Sync F 4 Sync
B 4 ParseComplete B 4 ParseComplete
B 4 BindComplete B 4 BindComplete
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment