From: George Schlossnagle Date: Wed, 19 May 2004 19:27:53 +0000 (+0000) Subject: exec() now returns row count X-Git-Tag: RELEASE_0_1~96 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=129997216b6fe0498503a1ce04995da459cd2b29;p=php exec() now returns row count --- diff --git a/ext/pdo/pdo.c b/ext/pdo/pdo.c index b8c9ab4fb9..65d5c29c66 100755 --- a/ext/pdo/pdo.c +++ b/ext/pdo/pdo.c @@ -88,9 +88,10 @@ static void php_pdo_init_globals(zend_pdo_globals *pdo_globals) PDO_API int php_pdo_register_driver(pdo_driver_t *driver) { - if (driver->api_version != PDO_DRIVER_API) + if (driver->api_version != PDO_DRIVER_API) { + zend_error(E_ERROR, "failed api version check"); return FAILURE; - + } if (!zend_hash_exists(&module_registry, "pdo", sizeof("pdo"))) { zend_error(E_ERROR, "You MUST load PDO before loading any PDO drivers"); return FAILURE; /* NOTREACHED */ diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index b53637ef16..caa0d8c428 100755 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -257,13 +257,14 @@ fail: } /* }}} */ -/* {{{ proto bool PDO::exec(string query) - Execute a query that does not return a row set */ +/* {{{ proto long PDO::exec(string query) + Execute a query that does not return a row set, returning the number of affected rows */ static PHP_METHOD(PDO, exec) { pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC); char *statement; long statement_len; + long ret; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &statement, &statement_len)) { RETURN_FALSE; @@ -272,29 +273,17 @@ static PHP_METHOD(PDO, exec) if (!statement_len) { RETURN_FALSE; } - - RETURN_BOOL(dbh->methods->doer(dbh, statement, statement_len TSRMLS_CC)); -} -/* }}} */ - -/* {{{ 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()) { + ret = dbh->methods->doer(dbh, statement, statement_len TSRMLS_CC); + if(ret == -1) { RETURN_FALSE; } - - if (!dbh->methods->affected) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "This driver affected rows retrieval."); - } else { - RETURN_LONG(dbh->methods->affected(dbh TSRMLS_CC)); + else { + RETURN_LONG(ret); } } /* }}} */ + /* {{{ proto int PDO::lastInsertId() Returns the number id of rows that we affected by the last call to PDO::exec(). Not always meaningful. */ static PHP_METHOD(PDO, lastInsertId) @@ -320,7 +309,6 @@ 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) PHP_ME(PDO, lastInsertId, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index 2629aa739f..a060436215 100755 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -114,7 +114,7 @@ typedef int (*pdo_dbh_close_func)(pdo_dbh_t *dbh TSRMLS_DC); typedef int (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, const char *sql, long sql_len, pdo_stmt_t *stmt, long options, zval *driver_options TSRMLS_DC); /* execute a statement (that does not return a result set) */ -typedef int (*pdo_dbh_do_func)(pdo_dbh_t *dbh, const char *sql, long sql_len TSRMLS_DC); +typedef long (*pdo_dbh_do_func)(pdo_dbh_t *dbh, const char *sql, long sql_len TSRMLS_DC); /* quote a string */ typedef int (*pdo_dbh_quote_func)(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen TSRMLS_DC); @@ -125,9 +125,6 @@ typedef int (*pdo_dbh_txn_func)(pdo_dbh_t *dbh TSRMLS_DC); /* setting and getting of attributes */ typedef int (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC); -/* return affected rows */ -typedef long (*pdo_dbh_affected_func)(pdo_dbh_t *dbh TSRMLS_DC); - /* return last insert id */ typedef long (*pdo_dbh_last_id_func)(pdo_dbh_t *dbh TSRMLS_DC); @@ -140,7 +137,6 @@ struct pdo_dbh_methods { pdo_dbh_txn_func commit; pdo_dbh_txn_func rollback; pdo_dbh_set_attr_func set_attribute; - pdo_dbh_affected_func affected; pdo_dbh_last_id_func last_id; };