cvs: php-src(PHP_5_3) /ext/pdo pdo_stmt.c /ext/pdo_mysql/tests bug46292.phpt

From: Date: Tue, 14 Oct 2008 17:36:02 +0000
Subject: cvs: php-src(PHP_5_3) /ext/pdo pdo_stmt.c /ext/pdo_mysql/tests bug46292.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-53510@lists.php.net to get a copy of this message
felipe Tue Oct 14 17:36:02 2008 UTC Added files: (Branch: PHP_5_3) /php-src/ext/pdo_mysql/tests bug46292.phpt Modified files: /php-src/ext/pdo pdo_stmt.c Log: - MFH: Fixed bug #46292 (PDO::setFetchMode() shouldn't requires the 2nd arg when using FETCH_CLASSTYPE) http://cvs.php.net/viewvc.cgi/php-src/ext/pdo/pdo_stmt.c?r1=1.118.2.38.2.24.2.27&r2=1.118.2.38.2.24.2.28&diff_format=u Index: php-src/ext/pdo/pdo_stmt.c diff -u php-src/ext/pdo/pdo_stmt.c:1.118.2.38.2.24.2.27 php-src/ext/pdo/pdo_stmt.c:1.118.2.38.2.24.2.28 --- php-src/ext/pdo/pdo_stmt.c:1.118.2.38.2.24.2.27 Sun Oct 12 13:46:10 2008 +++ php-src/ext/pdo/pdo_stmt.c Tue Oct 14 17:36:02 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pdo_stmt.c,v 1.118.2.38.2.24.2.27 2008/10/12 13:46:10 felipe Exp $ */ +/* $Id: pdo_stmt.c,v 1.118.2.38.2.24.2.28 2008/10/14 17:36:02 felipe Exp $ */ /* The PDO Statement Handle Class */ @@ -1941,7 +1941,7 @@ int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, int skip) { long mode = PDO_FETCH_BOTH; - int argc = ZEND_NUM_ARGS() - skip; + int flags, argc = ZEND_NUM_ARGS() - skip; zval ***args; zend_class_entry **cep; @@ -1974,6 +1974,7 @@ convert_to_long_ex(args[skip]); mode = Z_LVAL_PP(args[skip]); + flags = mode & PDO_FETCH_FLAGS; if (!pdo_stmt_verify_mode(stmt, mode, 0 TSRMLS_CC)) { efree(args); @@ -2001,21 +2002,30 @@ break; case PDO_FETCH_CLASS: - if (argc < 2 || argc > 3) { - goto fail_out; - } - convert_to_string_ex(args[skip+1]); - - if (FAILURE == zend_lookup_class(Z_STRVAL_PP(args[skip+1]), - Z_STRLEN_PP(args[skip+1]), &cep TSRMLS_CC)) { - goto fail_out; - } + /* Gets its class name from 1st column */ + if ((flags & PDO_FETCH_CLASSTYPE) == PDO_FETCH_CLASSTYPE) { + if (argc != 1) { + goto fail_out; + } + stmt->fetch.cls.ce = NULL; + } else { + if (argc < 2 || argc > 3) { + goto fail_out; + } + convert_to_string_ex(args[skip+1]); - if (!cep || !*cep) { - goto fail_out; + if (FAILURE == zend_lookup_class(Z_STRVAL_PP(args[skip+1]), + Z_STRLEN_PP(args[skip+1]), &cep TSRMLS_CC)) { + goto fail_out; + } + + if (!cep || !*cep) { + goto fail_out; + } + + stmt->fetch.cls.ce = *cep; } - - stmt->fetch.cls.ce = *cep; + stmt->fetch.cls.ctor_args = NULL; #ifdef ilia_0 /* we'll only need this when we have persistent statements, if ever */ if (stmt->dbh->is_persistent) { http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_mysql/tests/bug46292.phpt?view=markup&rev=1.1 Index: php-src/ext/pdo_mysql/tests/bug46292.phpt +++ php-src/ext/pdo_mysql/tests/bug46292.phpt --TEST-- Bug #46292 (PDO::setFetchMode() shouldn't requires the 2nd arg when using FETCH_CLASSTYPE) --FILE-- <?php require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); $pdoDb = MySQLPDOTest::factory(); class myclass implements Serializable { public function __construct() { printf("%s()\n", __METHOD__); } public function serialize() { printf("%s()\n", __METHOD__); return "any data from serialize()"; } public function unserialize($dat) { printf("%s(%s)\n", __METHOD__, var_export($dat, true)); return $dat; } } class myclass2 extends myclass { } $pdoDb->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $pdoDb->query('DROP TABLE IF EXISTS testz'); $pdoDb->query('CREATE TABLE testz (name VARCHAR(20) NOT NULL, value INT)'); $pdoDb->query("INSERT INTO testz VALUES ('myclass', 1), ('myclass2', 2), ('myclass', NULL), ('myclass3', NULL)"); $stmt = $pdoDb->prepare("SELECT * FROM testz"); var_dump($stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_GROUP)); $stmt->execute(); var_dump($stmt->fetch()); var_dump($stmt->fetch()); var_dump($stmt->fetchAll()); $pdoDb->query('DROP TABLE IF EXISTS testz'); ?> --EXPECTF-- bool(true) myclass::__construct() object(myclass)#3 (1) { ["value"]=> string(1) "1" } myclass::__construct() object(myclass2)#3 (1) { ["value"]=> string(1) "2" } myclass::__construct() array(2) { [0]=> object(myclass)#3 (1) { ["value"]=> NULL } [1]=> object(stdClass)#4 (1) { ["value"]=> NULL } }

« previous php.cvs (#53510) next »