Skip to content

Commit d7be0d5

Browse files
committed
savepoint unsupported
1 parent 296ad2b commit d7be0d5

1 file changed

Lines changed: 7 additions & 31 deletions

File tree

ext/pdo_pgsql/pgsql_statement.c

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -81,40 +81,16 @@ static int pgsql_stmt_dtor(pdo_stmt_t *stmt)
8181
char *q = NULL;
8282
PGTransactionStatusType tstatus = PQtransactionStatus(H->server);
8383

84-
switch (tstatus) {
85-
case PQTRANS_ACTIVE:
86-
case PQTRANS_INERROR:
87-
case PQTRANS_UNKNOWN:
88-
res = NULL;
89-
break;
90-
case PQTRANS_INTRANS:
91-
spprintf(&q, 0,
92-
"SAVEPOINT pdo_pgsql_deallocate_%s;"
93-
"DEALLOCATE %s;"
94-
"RELEASE SAVEPOINT pdo_pgsql_deallocate_%s",
95-
S->stmt_name,
96-
S->stmt_name,
97-
S->stmt_name);
98-
res = PQexec(H->server, q);
99-
efree(q);
100-
if (res && PQresultStatus(res) != PGRES_COMMAND_OK) {
101-
spprintf(&q, 0,
102-
"ROLLBACK TO SAVEPOINT pdo_pgsql_deallocate_%s;"
103-
"RELEASE SAVEPOINT pdo_pgsql_deallocate_%s",
104-
S->stmt_name,
105-
S->stmt_name);
106-
PGresult *rollres;
107-
PQclear(res);
108-
rollres = PQexec(H->server, q);
109-
res = rollres;
110-
efree(q);
111-
}
112-
break;
113-
default:
84+
if (tstatus == PQTRANS_IDLE) {
11485
spprintf(&q, 0, "DEALLOCATE %s", S->stmt_name);
11586
res = PQexec(H->server, q);
11687
efree(q);
117-
break;
88+
} else {
89+
/* Inside a transaction, already aborted, or connection is unusable:
90+
* skip DEALLOCATE. On servers that reject it (e.g. Aurora DSQL) it
91+
* would poison the transaction (GH-21869); on any server the server
92+
* frees the prepared statement when the transaction ends. */
93+
res = NULL;
11894
}
11995
#else
12096
res = PQclosePrepared(H->server, S->stmt_name);

0 commit comments

Comments
 (0)