wez             Sat Feb 26 12:27:51 2005 EDT

  Modified files:              
    /php-src/ext/pdo    pdo.c pdo_dbh.c php_pdo_driver.h 
    /php-src/ext/pdo_mysql      mysql_driver.c 
    /php-src/ext/pdo_pgsql      pgsql_driver.c 
    /php-src/ext/pdo_sqlite     sqlite_driver.c 
  Log:
  Alan: moved your fields away, but reserved you a pointer.
  
  Changed PDO::lastInsertId() to have following proto:
  
        string PDO::lastInsertId([string name])
  
  this allows arbitrary unique identitifers to be returned from the driver.
  
  The optional name parameter is for databases that require additional 
contextual
  information to be able to return the correct identifier.  None currently use
  it, but pgsql will be on the list of drivers that do.
  
  
  
http://cvs.php.net/diff.php/php-src/ext/pdo/pdo.c?r1=1.38&r2=1.39&ty=u
Index: php-src/ext/pdo/pdo.c
diff -u php-src/ext/pdo/pdo.c:1.38 php-src/ext/pdo/pdo.c:1.39
--- php-src/ext/pdo/pdo.c:1.38  Tue Feb 22 19:52:14 2005
+++ php-src/ext/pdo/pdo.c       Sat Feb 26 12:27:51 2005
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pdo.c,v 1.38 2005/02/23 00:52:14 helly Exp $ */
+/* $Id: pdo.c,v 1.39 2005/02/26 17:27:51 wez Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -203,7 +203,47 @@
 
        return n_matches;
 }
-       
+
+static const char digit_vec[] = "0123456789";
+PDO_API char *php_pdo_int64_to_str(pdo_int64_t i64 TSRMLS_DC)
+{
+       char buffer[65];
+       char outbuf[65] = "";
+       register char *p;
+       long long_val;
+       char *dst = outbuf;
+
+       if (i64 < 0) {
+               i64 = -i64;
+               *dst++ = '-';
+       }
+
+       if (i64 == 0) {
+               *dst++ = '0';
+               *dst++ = '\0';
+               return estrdup(outbuf);
+       }
+
+       p = &buffer[sizeof(buffer)-1];
+       *p = '\0';
+
+       while ((pdo_uint64_t)i64 > (pdo_uint64_t)LONG_MAX) {
+               pdo_uint64_t quo = (pdo_uint64_t)i64 / (unsigned int)10;
+               unsigned int rem = (unsigned int)(i64 - quo*10U);
+               *--p = digit_vec[rem];
+               i64 = (pdo_int64_t)quo;
+       }
+       long_val = (long)i64;
+       while (long_val != 0) {
+               long quo = long_val / 10;
+               *--p = digit_vec[(unsigned int)(long_val - quo * 10)];
+               long_val = quo;
+       }
+       while ((*dst++ = *p++) != 0)
+               ;
+       *dst = '\0';
+       return estrdup(outbuf);
+}
 
 /* {{{ PHP_MINIT_FUNCTION */
 PHP_MINIT_FUNCTION(pdo)
http://cvs.php.net/diff.php/php-src/ext/pdo/pdo_dbh.c?r1=1.63&r2=1.64&ty=u
Index: php-src/ext/pdo/pdo_dbh.c
diff -u php-src/ext/pdo/pdo_dbh.c:1.63 php-src/ext/pdo/pdo_dbh.c:1.64
--- php-src/ext/pdo/pdo_dbh.c:1.63      Wed Feb 23 18:28:30 2005
+++ php-src/ext/pdo/pdo_dbh.c   Sat Feb 26 12:27:51 2005
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pdo_dbh.c,v 1.63 2005/02/23 23:28:30 helly Exp $ */
+/* $Id: pdo_dbh.c,v 1.64 2005/02/26 17:27:51 wez Exp $ */
 
 /* The PDO Database Handle Class */
 
@@ -752,13 +752,15 @@
 /* }}} */
 
 
-/* {{{ proto int PDO::lastInsertId()
-   Returns the number id of rows that we affected by the last call to 
PDO::exec().  Not always meaningful. */
+/* {{{ proto string PDO::lastInsertId([string seqname])
+   Returns the id of the last row that we affected on this connection.  Some 
databases require a sequence or table name to be passed in.  Not always 
meaningful. */
 static PHP_METHOD(PDO, lastInsertId)
 {
        pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
+       char *name = NULL;
+       int namelen;
 
-       if (ZEND_NUM_ARGS()) {
+       if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", 
&name, &namelen)) {
                RETURN_FALSE;
        }
 
@@ -767,7 +769,13 @@
                pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not 
support lastInsertId()" TSRMLS_CC);
                RETURN_FALSE;
        } else {
-               RETURN_LONG(dbh->methods->last_id(dbh TSRMLS_CC));
+               Z_STRVAL_P(return_value) = dbh->methods->last_id(dbh, name, 
&Z_STRLEN_P(return_value) TSRMLS_CC);
+               if (!Z_STRVAL_P(return_value)) {
+                       PDO_HANDLE_DBH_ERR();
+                       RETURN_FALSE;
+               } else {
+                       Z_TYPE_P(return_value) = IS_STRING;
+               }
        }
 }
 /* }}} */
http://cvs.php.net/diff.php/php-src/ext/pdo/php_pdo_driver.h?r1=1.53&r2=1.54&ty=u
Index: php-src/ext/pdo/php_pdo_driver.h
diff -u php-src/ext/pdo/php_pdo_driver.h:1.53 
php-src/ext/pdo/php_pdo_driver.h:1.54
--- php-src/ext/pdo/php_pdo_driver.h:1.53       Tue Feb 22 15:25:55 2005
+++ php-src/ext/pdo/php_pdo_driver.h    Sat Feb 26 12:27:51 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_pdo_driver.h,v 1.53 2005/02/22 20:25:55 helly Exp $ */
+/* $Id: php_pdo_driver.h,v 1.54 2005/02/26 17:27:51 wez Exp $ */
 
 #ifndef PHP_PDO_DRIVER_H
 #define PHP_PDO_DRIVER_H
@@ -28,6 +28,15 @@
 typedef struct _pdo_stmt_t     pdo_stmt_t;
 struct pdo_bound_param_data;
 
+#ifdef PHP_WIN32
+typedef __int64 pdo_int64_t;
+typedef unsigned __int64 pdo_uint64_t;
+#else
+typedef long long int pdo_int64_t;
+typedef unsigned long long int pdo_uint64_t;
+#endif
+PDO_API char *php_pdo_int64_to_str(pdo_int64_t i64 TSRMLS_DC);
+
 #ifndef TRUE
 # define TRUE 1
 #endif
@@ -35,7 +44,7 @@
 # define FALSE 0
 #endif
 
-#define PDO_DRIVER_API 20050222
+#define PDO_DRIVER_API 20050226
 
 enum pdo_param_type {
        PDO_PARAM_NULL,
@@ -231,8 +240,9 @@
 /* setting of attributes */
 typedef int (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, long attr, zval *val 
TSRMLS_DC);
 
-/* return last insert id */
-typedef long (*pdo_dbh_last_id_func)(pdo_dbh_t *dbh TSRMLS_DC);
+/* return last insert id.  NULL indicates error condition, otherwise, the 
return value
+ * MUST be an emalloc'd NULL terminated string. */
+typedef char *(*pdo_dbh_last_id_func)(pdo_dbh_t *dbh, const char *name, 
unsigned int *len TSRMLS_DC);
 
 /* fetch error information.  if stmt is not null, fetch information pertaining
  * to the statement, otherwise fetch global error information.  The driver
@@ -460,10 +470,8 @@
        enum pdo_param_type param_type;
        unsigned long precision;
 
-       /* don't touch the following fields unless your name is dbdo */
-       char *native_type_name;
-       int abstract_type;
-       int abstract_flags;
+       /* don't touch this unless your name is dbdo */
+       void *dbdo_stuff;
 };
 
 /* describes a bound parameter */
http://cvs.php.net/diff.php/php-src/ext/pdo_mysql/mysql_driver.c?r1=1.38&r2=1.39&ty=u
Index: php-src/ext/pdo_mysql/mysql_driver.c
diff -u php-src/ext/pdo_mysql/mysql_driver.c:1.38 
php-src/ext/pdo_mysql/mysql_driver.c:1.39
--- php-src/ext/pdo_mysql/mysql_driver.c:1.38   Mon Feb 21 11:10:03 2005
+++ php-src/ext/pdo_mysql/mysql_driver.c        Sat Feb 26 12:27:51 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: mysql_driver.c,v 1.38 2005/02/21 16:10:03 hholzgra Exp $ */
+/* $Id: mysql_driver.c,v 1.39 2005/02/26 17:27:51 wez Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -160,11 +160,13 @@
        }
 }
 
-static long pdo_mysql_last_insert_id(pdo_dbh_t *dbh TSRMLS_DC)
+static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, 
unsigned int *len, TSRMLS_DC)
 {
        pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
+       char *id = NULL;
 
-       return (long) mysql_insert_id(H->server);
+       *len = spprintf(&id, 0, "%ld", mysql_insert_id(H->server));
+       return id;
 }
 
 static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int 
unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype  
TSRMLS_DC)
http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/pgsql_driver.c?r1=1.36&r2=1.37&ty=u
Index: php-src/ext/pdo_pgsql/pgsql_driver.c
diff -u php-src/ext/pdo_pgsql/pgsql_driver.c:1.36 
php-src/ext/pdo_pgsql/pgsql_driver.c:1.37
--- php-src/ext/pdo_pgsql/pgsql_driver.c:1.36   Sun Feb 20 14:26:27 2005
+++ php-src/ext/pdo_pgsql/pgsql_driver.c        Sat Feb 26 12:27:51 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pgsql_driver.c,v 1.36 2005/02/20 19:26:27 helly Exp $ */
+/* $Id: pgsql_driver.c,v 1.37 2005/02/26 17:27:51 wez Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -197,15 +197,19 @@
        return 1;
 }
 
-static long pdo_pgsql_last_insert_id(pdo_dbh_t *dbh TSRMLS_DC)
+static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, 
unsigned int *len TSRMLS_DC)
 {
        pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
+       char *id = NULL;
        
        if (H->pgoid == InvalidOid) {
-               return -1;
+               return NULL;
        }
 
-       return (long) H->pgoid;
+       /* TODO: if name != NULL, pull out last value for that sequence/column 
*/
+
+       *len = spprintf(&id, 0, "%ld", H->pgoid);
+       return id;
 }
 
 static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, long attr, zval 
*return_value TSRMLS_DC)
http://cvs.php.net/diff.php/php-src/ext/pdo_sqlite/sqlite_driver.c?r1=1.14&r2=1.15&ty=u
Index: php-src/ext/pdo_sqlite/sqlite_driver.c
diff -u php-src/ext/pdo_sqlite/sqlite_driver.c:1.14 
php-src/ext/pdo_sqlite/sqlite_driver.c:1.15
--- php-src/ext/pdo_sqlite/sqlite_driver.c:1.14 Wed Feb  9 11:33:00 2005
+++ php-src/ext/pdo_sqlite/sqlite_driver.c      Sat Feb 26 12:27:51 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: sqlite_driver.c,v 1.14 2005/02/09 16:33:00 iliaa Exp $ */
+/* $Id: sqlite_driver.c,v 1.15 2005/02/26 17:27:51 wez Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -156,11 +156,14 @@
        }
 }
 
-static long pdo_sqlite_last_insert_id(pdo_dbh_t *dbh TSRMLS_DC)
+static char *pdo_sqlite_last_insert_id(pdo_dbh_t *dbh, const char *name, 
unsigned int *len TSRMLS_DC)
 {
        pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
-
-       return (long) sqlite3_last_insert_rowid(H->db);
+       char *id;
+       
+       id = php_pdo_int64_to_str(sqlite3_last_insert_rowid(H->db) TSRMLS_CC);
+       *len = strlen(id);
+       return id;
 }
 
 /* NB: doesn't handle binary strings... use prepared stmts for that */

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to