[PATCH] PDO::setDefaultFetchMode() methode

From: Date: Wed, 19 Oct 2005 12:34:28 +0000
Subject: [PATCH] PDO::setDefaultFetchMode() methode
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-3122@lists.php.net to get a copy of this message
Hi! I created a patch against 5.1 branch of PDO, which implements a setDefaultFetchMode() methode in PDO class. This methode can be used to set the FetchMode for PDOStatements once in the script/application, so you can avoid to set a FetchMode for each PDO::query() call, each statement or each PDOStatement::fetch() in your application, if you are not happy with PDO::FETCH_BOTH (I'm not), which is hardcoded today. e.g. if you want to use PDO::FETCH_OBJ, you have to pass the PDO class constant to every PDO::query() call in your application, or use PDOStatement::setFetchMode(PDO::FETCH_OBJ) on every statement. I think the PDO API will benefit from setDefaultFetchMode(), because it belongs behind the database abstraction API and makes it possible to write code on a consistent abstraction level (IMHO). The attatched patch is not complete yet, it only works with simple FetchModes, without extra parameters. I'm posting now, because I'd like to know how the chances are, to get something like that into PDO. If there is no chance, I don't want to put too much time into it to finish it (I'm not an experienced C programmer, so it takes some time...). I'd really appreciate it if a default FetchMode could make it into PDO class, which has also been requested on php and pecl bug-tracker: http://bugs.php.net/bug.php?id=34909 http://pecl.php.net/bugs/bug.php?id=4732 For an experienced C/PDO programmer it is not very difficult I think, PDO::setDefaultFetchMode() could be based on pdo_stmt_setup_fetch_mode() and PHP_METHOD(PDOStatement, setFetchMode): http://cvs.php.net/co.php/php-src/ext/pdo/pdo_stmt.c?r=1.128#1648 I had to strip most of the code to get it work, but I think you don't need to change too much, you only have to know WHAT to change and HOW to change it, and that's where I failed ;-) The second issue is to copy the data definition from "_pdo_stmt_t" struct to "_pdo_dbh_t" struct: http://cvs.php.net/co.php/php-src/ext/pdo/php_pdo_driver.h?r=1.69#603 Than you only have to set the "default_fetch_type" in the PDO constructor and pass it to "_pdo_stmt_t" when created. What do you think about it? Any comments appreciated! best regards Andreas

« previous php.pecl.dev (#3122) next »