johannes                                 Mon, 16 May 2011 15:37:39 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=311088

Log:
- Fix Bug #53782 (foreach throws irrelevant exception)

Bug: http://bugs.php.net/53782 (Re-Opened) foreach throws irrelevant exception
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/pdo_mysql/mysql_statement.c
    A   php/php-src/branches/PHP_5_3/ext/pdo_mysql/tests/bug53782.phpt
    U   php/php-src/branches/PHP_5_4/ext/pdo_mysql/mysql_statement.c
    A   php/php-src/branches/PHP_5_4/ext/pdo_mysql/tests/bug53782.phpt
    U   php/php-src/trunk/ext/pdo_mysql/mysql_statement.c
    A   php/php-src/trunk/ext/pdo_mysql/tests/bug53782.phpt

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2011-05-16 15:36:12 UTC (rev 311087)
+++ php/php-src/branches/PHP_5_3/NEWS   2011-05-16 15:37:39 UTC (rev 311088)
@@ -85,6 +85,7 @@

 - PDO MySQL driver:
   . Fixed bug #54644 (wrong pathes in php_pdo_mysql_int.h). (Tony, Johannes)
+  . Fixed bug #53782 (foreach throws irrelevant exception). (Johannes, Andrey)
   . Implemented FR #48587 (MySQL PDO driver doesn't support SSL connections).
     (Rob)


Modified: php/php-src/branches/PHP_5_3/ext/pdo_mysql/mysql_statement.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/pdo_mysql/mysql_statement.c        
2011-05-16 15:36:12 UTC (rev 311087)
+++ php/php-src/branches/PHP_5_3/ext/pdo_mysql/mysql_statement.c        
2011-05-16 15:37:39 UTC (rev 311088)
@@ -656,7 +656,11 @@
 #endif /* PDO_USE_MYSQLND */

        if ((S->current_data = mysql_fetch_row(S->result)) == NULL) {
-               if (mysql_errno(S->H->server)) {
+#if PDO_USE_MYSQLND
+               if (S->result->unbuf && !S->result->unbuf->eof_reached && 
mysql_errno(S->H->server)) {
+#else
+               if (!S->result->eof && mysql_errno(S->H->server)) {
+#endif
                        pdo_mysql_error_stmt(stmt);
                }
                PDO_DBG_RETURN(0);

Added: php/php-src/branches/PHP_5_3/ext/pdo_mysql/tests/bug53782.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/pdo_mysql/tests/bug53782.phpt              
                (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/pdo_mysql/tests/bug53782.phpt      
2011-05-16 15:37:39 UTC (rev 311088)
@@ -0,0 +1,40 @@
+--TEST--
+PDO MySQL Bug #53782 (foreach throws irrelevant exception)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not 
loaded');
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+$conn = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+
+$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+$res = $conn->query('SELECT 0');
+
+try {
+    $conn->query('ERROR');
+} catch (PDOException $e) {
+    echo "Caught: ".$e->getMessage()."\n";
+}
+
+foreach ($res as $k => $v) {
+    echo "Value: $v[0]\n";
+}
+
+echo "DONE";
+?>
+--CLEAN--
+<?php
+require dirname(__FILE__) . '/mysql_pdo_test.inc';
+MySQLPDOTest::dropTestTable();
+?>
+--EXPECTF--
+Caught: SQLSTATE[42000]: %s
+Value: 0
+DONE


Property changes on: 
php/php-src/branches/PHP_5_3/ext/pdo_mysql/tests/bug53782.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Modified: php/php-src/branches/PHP_5_4/ext/pdo_mysql/mysql_statement.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/pdo_mysql/mysql_statement.c        
2011-05-16 15:36:12 UTC (rev 311087)
+++ php/php-src/branches/PHP_5_4/ext/pdo_mysql/mysql_statement.c        
2011-05-16 15:37:39 UTC (rev 311088)
@@ -640,7 +640,11 @@
 #endif /* PDO_USE_MYSQLND */

        if ((S->current_data = mysql_fetch_row(S->result)) == NULL) {
-               if (mysql_errno(S->H->server)) {
+#if PDO_USE_MYSQLND
+               if (S->result->unbuf && !S->result->unbuf->eof_reached && 
mysql_errno(S->H->server)) {
+#else
+               if (!S->result->eof && mysql_errno(S->H->server)) {
+#endif
                        pdo_mysql_error_stmt(stmt);
                }
                PDO_DBG_RETURN(0);

Added: php/php-src/branches/PHP_5_4/ext/pdo_mysql/tests/bug53782.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/ext/pdo_mysql/tests/bug53782.phpt              
                (rev 0)
+++ php/php-src/branches/PHP_5_4/ext/pdo_mysql/tests/bug53782.phpt      
2011-05-16 15:37:39 UTC (rev 311088)
@@ -0,0 +1,40 @@
+--TEST--
+PDO MySQL Bug #53782 (foreach throws irrelevant exception)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not 
loaded');
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+$conn = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+
+$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+$res = $conn->query('SELECT 0');
+
+try {
+    $conn->query('ERROR');
+} catch (PDOException $e) {
+    echo "Caught: ".$e->getMessage()."\n";
+}
+
+foreach ($res as $k => $v) {
+    echo "Value: $v[0]\n";
+}
+
+echo "DONE";
+?>
+--CLEAN--
+<?php
+require dirname(__FILE__) . '/mysql_pdo_test.inc';
+MySQLPDOTest::dropTestTable();
+?>
+--EXPECTF--
+Caught: SQLSTATE[42000]: %s
+Value: 0
+DONE


Property changes on: 
php/php-src/branches/PHP_5_4/ext/pdo_mysql/tests/bug53782.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Modified: php/php-src/trunk/ext/pdo_mysql/mysql_statement.c
===================================================================
--- php/php-src/trunk/ext/pdo_mysql/mysql_statement.c   2011-05-16 15:36:12 UTC 
(rev 311087)
+++ php/php-src/trunk/ext/pdo_mysql/mysql_statement.c   2011-05-16 15:37:39 UTC 
(rev 311088)
@@ -640,7 +640,11 @@
 #endif /* PDO_USE_MYSQLND */

        if ((S->current_data = mysql_fetch_row(S->result)) == NULL) {
-               if (mysql_errno(S->H->server)) {
+#if PDO_USE_MYSQLND
+               if (S->result->unbuf && !S->result->unbuf->eof_reached && 
mysql_errno(S->H->server)) {
+#else
+               if (!S->result->eof && mysql_errno(S->H->server)) {
+#endif
                        pdo_mysql_error_stmt(stmt);
                }
                PDO_DBG_RETURN(0);

Added: php/php-src/trunk/ext/pdo_mysql/tests/bug53782.phpt
===================================================================
--- php/php-src/trunk/ext/pdo_mysql/tests/bug53782.phpt                         
(rev 0)
+++ php/php-src/trunk/ext/pdo_mysql/tests/bug53782.phpt 2011-05-16 15:37:39 UTC 
(rev 311088)
@@ -0,0 +1,40 @@
+--TEST--
+PDO MySQL Bug #53782 (foreach throws irrelevant exception)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not 
loaded');
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+$conn = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+
+$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+$res = $conn->query('SELECT 0');
+
+try {
+    $conn->query('ERROR');
+} catch (PDOException $e) {
+    echo "Caught: ".$e->getMessage()."\n";
+}
+
+foreach ($res as $k => $v) {
+    echo "Value: $v[0]\n";
+}
+
+echo "DONE";
+?>
+--CLEAN--
+<?php
+require dirname(__FILE__) . '/mysql_pdo_test.inc';
+MySQLPDOTest::dropTestTable();
+?>
+--EXPECTF--
+Caught: SQLSTATE[42000]: %s
+Value: 0
+DONE


Property changes on: php/php-src/trunk/ext/pdo_mysql/tests/bug53782.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to