From: Wez Furlong Date: Wed, 19 May 2004 13:55:41 +0000 (+0000) Subject: Revise $dbh->exec(). X-Git-Tag: RELEASE_0_1~111 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fd6b885a195e70c589505e1d91076246c0eb7780;p=php Revise $dbh->exec(). The driver doer() method should populate dbh->affected_rows if it can determine its value. --- diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 01d1c3baf7..83eaf8d621 100755 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -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} }; diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index 59a445b46e..e7af5fa8eb 100755 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -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;