From: Ilia Alshanetsky Date: Thu, 20 May 2004 18:00:24 +0000 (+0000) Subject: Last insert id (oids) support. X-Git-Tag: RELEASE_0_1~61 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f8d045619a064899f666d132aee6a6b49495d37d;p=php Last insert id (oids) support. --- diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index 67db6fd64e..0036eccb9f 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -117,6 +117,7 @@ static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM pdo_pgsql_error(dbh, qs); return 0; } + H->pgoid = PQoidValue(res); } return 1; @@ -134,6 +135,16 @@ static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquote return 1; } +static long pdo_pgsql_last_insert_id(pdo_dbh_t *dbh TSRMLS_DC) +{ + pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data; + + if (H->pgoid == InvalidOid) { + return -1; + } + + return (long) H->pgoid; +} static struct pdo_dbh_methods pgsql_methods = { pgsql_handle_closer, @@ -144,7 +155,7 @@ static struct pdo_dbh_methods pgsql_methods = { NULL, NULL, NULL, - NULL, + pdo_pgsql_last_insert_id, pdo_pgsql_fetch_error_func }; @@ -185,6 +196,7 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ } H->attached = 1; + H->pgoid = -1; dbh->methods = &pgsql_methods; dbh->alloc_own_columns = 1; diff --git a/ext/pdo_pgsql/php_pdo_pgsql_int.h b/ext/pdo_pgsql/php_pdo_pgsql_int.h index 7d0be93586..27d84277b9 100644 --- a/ext/pdo_pgsql/php_pdo_pgsql_int.h +++ b/ext/pdo_pgsql/php_pdo_pgsql_int.h @@ -38,6 +38,7 @@ typedef struct { unsigned attached:1; unsigned _reserved:31; pdo_pgsql_error_info einfo; + Oid pgoid; } pdo_pgsql_db_handle; typedef struct {