diff options
| author | Anatol Belski <ab@php.net> | 2016-08-14 20:04:49 +0200 |
|---|---|---|
| committer | Anatol Belski <ab@php.net> | 2016-08-14 20:04:49 +0200 |
| commit | 245eaf51875567f6e6b446a3fda3fac5502e77f7 (patch) | |
| tree | 5a6a1d399203c00fa4d76b4fba5d853ac02db445 /ext/pdo_pgsql/pgsql_driver.c | |
| parent | 436d50a82192cbef4431fe9a70c641f49aec55a8 (diff) | |
| parent | 977cbc2fff1a3ec9d29a2c0904fae01bfd64c6c2 (diff) | |
| download | php-git-245eaf51875567f6e6b446a3fda3fac5502e77f7.tar.gz | |
Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
Fixed bug #72759 Regression in pgo_pgsql
Diffstat (limited to 'ext/pdo_pgsql/pgsql_driver.c')
| -rw-r--r-- | ext/pdo_pgsql/pgsql_driver.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index df99912e4c..5a26b1db04 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); } |
