]> granicus.if.org Git - php/commitdiff
- Add FETCH_PROPSLATE: fetch props after calling ctor
authorMarcus Boerger <helly@php.net>
Fri, 24 Feb 2006 15:56:03 +0000 (15:56 +0000)
committerMarcus Boerger <helly@php.net>
Fri, 24 Feb 2006 15:56:03 +0000 (15:56 +0000)
# Fixes bug #36428

ext/pdo/pdo_dbh.c
ext/pdo/pdo_stmt.c
ext/pdo/php_pdo_driver.h
ext/pdo/tests/bug_36428.phpt [new file with mode: 0755]

index 5b2c2529df5fd2ef67a930334f270e0d39d5bd64..e9ff63e48a87e9fba878de65d23737d8f4969820 100755 (executable)
@@ -1238,6 +1238,7 @@ void pdo_dbh_init(TSRMLS_D)
 #if PHP_MAJOR_VERSION > 5 || PHP_MINOR_VERSION >= 1
        REGISTER_PDO_CLASS_CONST_LONG("FETCH_SERIALIZE",(long)PDO_FETCH_SERIALIZE);
 #endif
+       REGISTER_PDO_CLASS_CONST_LONG("FETCH_PROPSLATE",(long)PDO_FETCH_PROPSLATE);
        REGISTER_PDO_CLASS_CONST_LONG("FETCH_NAMED",(long)PDO_FETCH_NAMED);
 
        REGISTER_PDO_CLASS_CONST_LONG("ATTR_AUTOCOMMIT",        (long)PDO_ATTR_AUTOCOMMIT);
index 0b00b43885bb3301bf3adde1acd5d7d5795d9354..9a122d294c4af9140a45085d378f1a39eafcde48 100755 (executable)
@@ -838,6 +838,18 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value,
                                                        return 0;
                                                }
                                        }
+                                       if (ce->constructor && (flags & PDO_FETCH_PROPSLATE)) {
+                                               stmt->fetch.cls.fci.object_pp = &return_value;
+                                               stmt->fetch.cls.fcc.object_pp = &return_value;
+                                               if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc TSRMLS_CC) == FAILURE) {
+                                                       pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor" TSRMLS_CC);
+                                                       return 0;
+                                               } else {
+                                                       if (stmt->fetch.cls.retval_ptr) {
+                                                               zval_ptr_dtor(&stmt->fetch.cls.retval_ptr);
+                                                       }
+                                               }
+                                       }
                                }
                                break;
                        
@@ -1000,7 +1012,7 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value,
                
                switch (how) {
                        case PDO_FETCH_CLASS:
-                               if (ce->constructor) {
+                               if (ce->constructor && !(flags & PDO_FETCH_PROPSLATE)) {
                                        stmt->fetch.cls.fci.object_pp = &return_value;
                                        stmt->fetch.cls.fcc.object_pp = &return_value;
                                        if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc TSRMLS_CC) == FAILURE) {
index 66b04dd44b1b115de7802cfb79652d1c0bdb2577..889a355bd6d405005e6dd8c88532b4c2423a064e 100755 (executable)
@@ -98,6 +98,7 @@ enum pdo_fetch_type {
 #define PDO_FETCH_UNIQUE    0x00030000  /* fetch into groups assuming first col is unique */
 #define PDO_FETCH_CLASSTYPE 0x00040000  /* fetch class gets its class name from 1st column */
 #define PDO_FETCH_SERIALIZE 0x00080000  /* fetch class instances by calling serialize */
+#define PDO_FETCH_PROPSLATE 0x00100000  /* fetch props after calling ctor */
 
 /* fetch orientation for scrollable cursors */
 enum pdo_fetch_orientation {
diff --git a/ext/pdo/tests/bug_36428.phpt b/ext/pdo/tests/bug_36428.phpt
new file mode 100755 (executable)
index 0000000..1aea012
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+PDO Common: PHP Bug #36428: Incorrect error message for PDO::fetchAll
+--SKIPIF--
+<?php # vim:ft=php
+if (!extension_loaded('pdo')) die('skip');
+if (!extension_loaded('simplexml')) die('skip SimpleXML not loaded');
+$dir = getenv('REDIR_TEST_DIR');
+if (false == $dir) die('skip no driver');
+require_once $dir . 'pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/'); 
+require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
+
+$db = PDOTest::factory();
+$db->exec("CREATE TABLE test (a VARCHAR(10))");
+$db->exec("INSERT INTO test (a) VALUES ('xyz')");
+$res = $db->query("SELECT a FROM test");
+var_dump($res->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPSLATE, 'SimpleXMLElement', array('<root/>')));
+
+?>
+===DONE===
+--EXPECTF--
+array(1) {
+  [0]=>
+  object(SimpleXMLElement)#%d (1) {
+    ["a"]=>
+    string(3) "xyz"
+  }
+}
+===DONE===