Patch bug72759.patch for PDO PgSQL Bug #72759
Patch version 2016-08-10 21:55 UTC
Return to Bug #72759 |
Download this patch
Patch Revisions:
Developer: ab@php.net
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
index df99912..4639aa8 100644
--- a/ext/pdo_pgsql/pgsql_driver.c
+++ b/ext/pdo_pgsql/pgsql_driver.c
@@ -363,8 +363,15 @@ static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t *
char *id = NULL;
PGresult *res;
ExecStatusType status;
+ zend_bool savepoint = 0;
if (name == NULL) {
+ savepoint = pgsql_handle_in_transaction(dbh);
+
+ if (savepoint) {
+ /* The savepoint is overwritten every time. */
+ (void)PQexec(H->server, "SAVEPOINT php_lastid_savepoint");
+ }
res = PQexec(H->server, "SELECT LASTVAL()");
} else {
const char *q[1];
@@ -378,10 +385,17 @@ static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t *
id = estrdup((char *)PQgetvalue(res, 0, 0));
*len = PQgetlength(res, 0, 0);
} else {
+ if (savepoint) {
+ (void)PQexec(H->server, "ROLLBACK TO SAVEPOINT php_lastid_savepoint");
+ }
pdo_pgsql_error(dbh, status, pdo_pgsql_sqlstate(res));
*len = spprintf(&id, 0, ZEND_LONG_FMT, (zend_long) H->pgoid);
}
+ if (savepoint) {
+ (void)PQexec(H->server, "RELEASE SAVEPOINT php_lastid_savepoint");
+ }
+
if (res) {
PQclear(res);
}
|