]> granicus.if.org Git - php/commitdiff
Last insert id (oids) support.
authorIlia Alshanetsky <iliaa@php.net>
Thu, 20 May 2004 18:00:24 +0000 (18:00 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 20 May 2004 18:00:24 +0000 (18:00 +0000)
ext/pdo_pgsql/pgsql_driver.c
ext/pdo_pgsql/php_pdo_pgsql_int.h

index 67db6fd64e6ed7645430f2baa2f46895048c6948..0036eccb9f59570ae4f9f15a0b9219ab2c003d94 100644 (file)
@@ -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;
index 7d0be93586fd76416deb59e24b82afc15d6a77d1..27d84277b9799a766347a8d4dfa4b0313d66b514 100644 (file)
@@ -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 {