]> granicus.if.org Git - php/commitdiff
- Add PDO::setDEfaultFetchMode() (Pierre)
authorMarcus Boerger <helly@php.net>
Sat, 18 Mar 2006 23:10:40 +0000 (23:10 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 18 Mar 2006 23:10:40 +0000 (23:10 +0000)
ext/pdo/pdo_dbh.c
ext/pdo/php_pdo_driver.h

index a710a187532a552d2fbe27a41098b2a2e5203b81..be6b4c1f2ce439a1499b21d0f810933280e40744 100755 (executable)
@@ -391,6 +391,22 @@ static PHP_METHOD(PDO, dbh_constructor)
 }
 /* }}} */
 
+/* {{{ proto object PDO::setDefaultFetchMode(PDOStatement::setFetchMode())
+   Set the default fetch mode for this connection */
+static PHP_METHOD(PDO, setDefaultFetchMode)
+{
+       pdo_dbh_t *dbh = zend_object_store_get_object(getThis() TSRMLS_CC);
+       long mode;
+
+       if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &mode)) {
+               RETURN_FALSE;
+       }
+
+       PDO_CONSTRUCT_CHECK;
+       dbh->default_fetch_type = mode;
+}
+/* }}} */
+
 static zval *pdo_stmt_instantiate(pdo_dbh_t *dbh, zval *object, zend_class_entry *dbstmt_ce, zval *ctor_args TSRMLS_DC) /* {{{ */
 {
        if (ctor_args) {
@@ -964,7 +980,13 @@ static PHP_METHOD(PDO, query)
        /* unconditionally keep this for later reference */
        stmt->query_string = estrndup(statement, statement_len);
        stmt->query_stringlen = statement_len;
-       stmt->default_fetch_type = PDO_FETCH_BOTH;
+
+       if (ZEND_NUM_ARGS() == 1 && dbh->default_fetch_type) {
+               stmt->default_fetch_type = dbh->default_fetch_type;
+       } else {
+               stmt->default_fetch_type = PDO_FETCH_BOTH;
+       }
+
        stmt->active_query_string = stmt->query_string;
        stmt->active_query_stringlen = statement_len;
        stmt->dbh = dbh;
@@ -1071,8 +1093,9 @@ static PHP_METHOD(PDO, getAvailableDrivers)
 
 zend_function_entry pdo_dbh_functions[] = {
        ZEND_MALIAS(PDO, __construct, dbh_constructor,  NULL,                   ZEND_ACC_PUBLIC)
-       PHP_ME(PDO, prepare,            NULL,                                   ZEND_ACC_PUBLIC)
-       PHP_ME(PDO, beginTransaction,NULL,                                      ZEND_ACC_PUBLIC)
+       PHP_ME(PDO, prepare,                            NULL,                   ZEND_ACC_PUBLIC)
+       PHP_ME(PDO, setDefaultFetchMode,        NULL,                   ZEND_ACC_PUBLIC)
+       PHP_ME(PDO, beginTransaction,           NULL,                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, commit,                     NULL,                                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, rollBack,           NULL,                                   ZEND_ACC_PUBLIC)
        PHP_ME(PDO, setAttribute,       NULL,                                   ZEND_ACC_PUBLIC)
index fd9f10fe2e566025c3fd8fb4348836ff2d700517..943d8bea0101c8e97e9e5e425872140d56213ccd 100755 (executable)
@@ -477,6 +477,9 @@ struct _pdo_dbh_t {
 
        enum pdo_case_conversion native_case, desired_case;
 
+       /* defaults for fetches */
+       enum pdo_fetch_type default_fetch_type;
+
        /* persistent hash key associated with this handle */
        const char *persistent_id;
        int persistent_id_len;