]> granicus.if.org Git - php/commitdiff
exec() now returns row count
authorGeorge Schlossnagle <gschlossnagle@php.net>
Wed, 19 May 2004 19:27:53 +0000 (19:27 +0000)
committerGeorge Schlossnagle <gschlossnagle@php.net>
Wed, 19 May 2004 19:27:53 +0000 (19:27 +0000)
ext/pdo/pdo.c
ext/pdo/pdo_dbh.c
ext/pdo/php_pdo_driver.h

index b8c9ab4fb93ee90cf87d2a810601c6e485bbb962..65d5c29c669e18773b49ab5db296f397c7192d4e 100755 (executable)
@@ -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 */
index b53637ef1685ff8d6e2ae933cf39f64881944be8..caa0d8c428df3570f7ee54eaa76666b0eb9ab0d1 100755 (executable)
@@ -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}
index 2629aa739faa95ba44a0f5eae1a42e908bf4cefc..a0604362158a7545f40dd6193dd9dbc65f06f3e4 100755 (executable)
@@ -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;
 };