]> granicus.if.org Git - php/commitdiff
Revise $dbh->exec().
authorWez Furlong <wez@php.net>
Wed, 19 May 2004 13:55:41 +0000 (13:55 +0000)
committerWez Furlong <wez@php.net>
Wed, 19 May 2004 13:55:41 +0000 (13:55 +0000)
The driver doer() method should populate dbh->affected_rows if it can determine its value.

ext/pdo/pdo_dbh.c
ext/pdo/php_pdo_driver.h

index 01d1c3baf7845d74cf83fec9ba6c6b703c3f4cbf..83eaf8d621c4b24785320efbfec434305af450fd 100755 (executable)
@@ -262,10 +262,8 @@ fail:
 static PHP_METHOD(PDO, exec)
 {
        pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
-       pdo_stmt_t *stmt;
        char *statement;
        long statement_len;
-       int rows;
 
        if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &statement, &statement_len)) {
                RETURN_FALSE;
@@ -275,16 +273,25 @@ static PHP_METHOD(PDO, exec)
                RETURN_FALSE;
        }
 
-       rows = dbh->methods->doer(dbh, statement, statement_len TSRMLS_CC);
+       RETURN_BOOL(dbh->methods->doer(dbh, statement, statement_len TSRMLS_CC));
+}
+/* }}} */
 
-       if (rows >= 0) {
-               RETURN_LONG(rows);
+/* {{{ proto int PDO::affectedRows()
+   Returns the number of rows that we affected by the last call to PDO::exec().  Not always meaningful. */
+static PHP_METHOD(PDO, affectedRows)
+{
+       pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+       if (ZEND_NUM_ARGS()) {
+               RETURN_FALSE;
        }
 
-       RETURN_FALSE;
+       RETURN_LONG(dbh->affected_rows);
 }
 /* }}} */
 
+
 function_entry pdo_dbh_functions[] = {
        PHP_ME(PDO, prepare,            NULL,                                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, beginTransaction,NULL,                                      ZEND_ACC_PUBLIC)
@@ -292,6 +299,7 @@ function_entry pdo_dbh_functions[] = {
        PHP_ME(PDO, rollBack,           NULL,                                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, setAttribute,       NULL,                                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, exec,                       NULL,                                   ZEND_ACC_PUBLIC)
+       PHP_ME(PDO, affectedRows,       NULL,                                   ZEND_ACC_PUBLIC)
 
        {NULL, NULL, NULL}
 };
index 59a445b46e5f271da6a5cd244c351764c3a512fb..e7af5fa8ebceea43d60049b4b15b002774bc9f3c 100755 (executable)
@@ -216,6 +216,10 @@ struct _pdo_dbh_t {
        const char *data_source;
        unsigned long data_source_len;
 
+       /* the number of rows affected by last $dbh->exec().  Not always
+        * meaningful */
+       int affected_rows;
+
 #if 0
        /* persistent hash key associated with this handle */
        const char *persistent_id;