From: Tom Lane <tgl@sss.pgh.pa.us>
To: klaxian@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15170: PQtransactionStatus returns ACTIVE after Empty Commit
Date: Tue, 24 Apr 2018 19:10:22 -0400
Message-ID: <16961.1524611422@sss.pgh.pa.us> (raw)
In-Reply-To: <152458855796.19803.13664386145754757782@wrigleys.postgresql.org>
References: <152458855796.19803.13664386145754757782@wrigleys.postgresql.org>
=?utf-8?q?PG_Bug_reporting_form?= <noreply@postgresql.org> writes:
> PQtransactionStatus() incorrectly returns PQTRANS_ACTIVE after committing an
> empty transaction block (ie. BEGIN and COMMIT without any other queries).
I do not see that here; for instance, the attached test program prints
Initial PQtransactionStatus: 0
PQtransactionStatus after BEGIN: 2
PQtransactionStatus after COMMIT: 0
PQtransactionStatus after BEGIN; COMMIT: 0
which is what I'd expect (0 is PQTRANS_IDLE, 2 is PQTRANS_INTRANS).
I'd only expect PQTRANS_ACTIVE if libpq thinks a query is still "in
flight", ie the server hasn't returned a command-complete message.
I speculate that either you or PHP have not waited for the commit
response to come back ... but without a concrete example to look at,
it's hard to say more.
regards, tom lane
Attachments:trans-status-test.c (text/x-c, 1.6K) download
#include <stdio.h>
#include <stdlib.h>
#include "libpq-fe.h"
static void
exit_nicely(PGconn *conn)
{
PQfinish(conn);
exit(1);
}
int
main(int argc, char **argv)
{
const char *conninfo;
PGconn *conn;
PGresult *res;
if (argc > 1)
conninfo = argv[1];
else
conninfo = "dbname = postgres user = postgres";
/* Make a connection to the database */
conn = PQconnectdb(conninfo);
/* Check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
{
fprintf(stderr, "Connection to database failed: %s",
PQerrorMessage(conn));
exit_nicely(conn);
}
printf("Initial PQtransactionStatus: %d\n",
PQtransactionStatus(conn));
res = PQexec(conn, "BEGIN");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "BEGIN failed: %s", PQerrorMessage(conn));
PQclear(res);
exit_nicely(conn);
}
PQclear(res);
printf("PQtransactionStatus after BEGIN: %d\n",
PQtransactionStatus(conn));
res = PQexec(conn, "COMMIT");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "COMMIT failed: %s", PQerrorMessage(conn));
PQclear(res);
exit_nicely(conn);
}
PQclear(res);
printf("PQtransactionStatus after COMMIT: %d\n",
PQtransactionStatus(conn));
res = PQexec(conn, "BEGIN; COMMIT");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "BEGIN; COMMIT failed: %s", PQerrorMessage(conn));
PQclear(res);
exit_nicely(conn);
}
PQclear(res);
printf("PQtransactionStatus after BEGIN; COMMIT: %d\n",
PQtransactionStatus(conn));
/* close the connection to the database and cleanup */
PQfinish(conn);
return 0;
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, klaxian@gmail.com
Subject: Re: BUG #15170: PQtransactionStatus returns ACTIVE after Empty Commit
In-Reply-To: <16961.1524611422@sss.pgh.pa.us>
References: <152458855796.19803.13664386145754757782@wrigleys.postgresql.org> <16961.1524611422@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox