Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdb1b931

Browse files
committed
libpq: Reset singlerow flag correctly in pipeline mode
When a query whose results were requested in single-row mode is the lastin the queue by the time those results are being read, the single-rowflag was not being reset, because we were returning early frompqPipelineProcessQueue. Move that stanza up so that the flag is alwaysreset at the end of sending that query's results.Add a test for the situation.Backpatch to 14.Author: Denis Laxalde <denis.laxalde@dalibo.com>Discussion:https://postgr.es/m/01af18c5-dacc-a8c8-07ee-aecc7650c3e8@dalibo.com
1 parentf13b208 commitdb1b931

File tree

3 files changed

+70
-7
lines changed

3 files changed

+70
-7
lines changed

‎src/interfaces/libpq/fe-exec.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,6 +3096,12 @@ pqPipelineProcessQueue(PGconn *conn)
30963096
break;
30973097
}
30983098

3099+
/*
3100+
* Reset single-row processing mode. (Client has to set it up for each
3101+
* query, if desired.)
3102+
*/
3103+
conn->singleRowMode= false;
3104+
30993105
/*
31003106
* If there are no further commands to process in the queue, get us in
31013107
* "real idle" mode now.
@@ -3115,12 +3121,6 @@ pqPipelineProcessQueue(PGconn *conn)
31153121
/* Initialize async result-accumulation state */
31163122
pqClearAsyncResult(conn);
31173123

3118-
/*
3119-
* Reset single-row processing mode. (Client has to set it up for each
3120-
* query, if desired.)
3121-
*/
3122-
conn->singleRowMode= false;
3123-
31243124
if (conn->pipelineStatus==PQ_PIPELINE_ABORTED&&
31253125
conn->cmd_queue_head->queryclass!=PGQUERY_SYNC)
31263126
{

‎src/test/modules/libpq_pipeline/libpq_pipeline.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,11 +1153,11 @@ test_singlerowmode(PGconn *conn)
11531153
inti;
11541154
boolpipeline_ended= false;
11551155

1156-
/* 1 pipeline, 3 queries in it */
11571156
if (PQenterPipelineMode(conn)!=1)
11581157
pg_fatal("failed to enter pipeline mode: %s",
11591158
PQerrorMessage(conn));
11601159

1160+
/* One series of three commands, using single-row mode for the first two. */
11611161
for (i=0;i<3;i++)
11621162
{
11631163
char*param[1];
@@ -1249,6 +1249,49 @@ test_singlerowmode(PGconn *conn)
12491249
pg_fatal("didn't get expected terminating TUPLES_OK");
12501250
}
12511251

1252+
/*
1253+
* Now issue one command, get its results in with single-row mode, then
1254+
* issue another command, and get its results in normal mode; make sure
1255+
* the single-row mode flag is reset as expected.
1256+
*/
1257+
if (PQsendQueryParams(conn,"SELECT generate_series(0, 0)",
1258+
0,NULL,NULL,NULL,NULL,0)!=1)
1259+
pg_fatal("failed to send query: %s",
1260+
PQerrorMessage(conn));
1261+
if (PQsendFlushRequest(conn)!=1)
1262+
pg_fatal("failed to send flush request");
1263+
if (PQsetSingleRowMode(conn)!=1)
1264+
pg_fatal("PQsetSingleRowMode() failed");
1265+
res=PQgetResult(conn);
1266+
if (res==NULL)
1267+
pg_fatal("unexpected NULL");
1268+
if (PQresultStatus(res)!=PGRES_SINGLE_TUPLE)
1269+
pg_fatal("Expected PGRES_SINGLE_TUPLE, got %s",
1270+
PQresStatus(PQresultStatus(res)));
1271+
res=PQgetResult(conn);
1272+
if (res==NULL)
1273+
pg_fatal("unexpected NULL");
1274+
if (PQresultStatus(res)!=PGRES_TUPLES_OK)
1275+
pg_fatal("Expected PGRES_TUPLES_OK, got %s",
1276+
PQresStatus(PQresultStatus(res)));
1277+
if (PQgetResult(conn)!=NULL)
1278+
pg_fatal("expected NULL result");
1279+
1280+
if (PQsendQueryParams(conn,"SELECT 1",
1281+
0,NULL,NULL,NULL,NULL,0)!=1)
1282+
pg_fatal("failed to send query: %s",
1283+
PQerrorMessage(conn));
1284+
if (PQsendFlushRequest(conn)!=1)
1285+
pg_fatal("failed to send flush request");
1286+
res=PQgetResult(conn);
1287+
if (res==NULL)
1288+
pg_fatal("unexpected NULL");
1289+
if (PQresultStatus(res)!=PGRES_TUPLES_OK)
1290+
pg_fatal("Expected PGRES_TUPLES_OK, got %s",
1291+
PQresStatus(PQresultStatus(res)));
1292+
if (PQgetResult(conn)!=NULL)
1293+
pg_fatal("expected NULL result");
1294+
12521295
if (PQexitPipelineMode(conn)!=1)
12531296
pg_fatal("failed to end pipeline mode: %s",PQerrorMessage(conn));
12541297

‎src/test/modules/libpq_pipeline/traces/singlerow.trace

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,24 @@ B12DataRow 1 2 '45'
3636
B12DataRow 1 2 '46'
3737
B13CommandComplete "SELECT 5"
3838
B5ReadyForQuery I
39+
F36Parse "" "SELECT generate_series(0, 0)" 0
40+
F14Bind "" "" 0 0 1 0
41+
F6Describe P ""
42+
F9Execute "" 0
43+
F4Flush
44+
B4ParseComplete
45+
B4BindComplete
46+
B40RowDescription 1 "generate_series" NNNN 0 NNNN 4 -1 0
47+
B11DataRow 1 1 '0'
48+
B13CommandComplete "SELECT 1"
49+
F16Parse "" "SELECT 1" 0
50+
F14Bind "" "" 0 0 1 0
51+
F6Describe P ""
52+
F9Execute "" 0
53+
F4Flush
54+
B4ParseComplete
55+
B4BindComplete
56+
B33RowDescription 1 "?column?" NNNN 0 NNNN 4 -1 0
57+
B11DataRow 1 1 '1'
58+
B13CommandComplete "SELECT 1"
3959
F4Terminate

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp