andrey          Wed Jul 23 14:06:31 2008 UTC

  Added files:                 
    /php-src/ext/mysqli/tests   bug44897.phpt 

  Modified files:              
    /php-src/ext/mysqlnd        mysqlnd_ps.c 
  Log:
  Fixed bug#44897 - failed to prepare statement
  After a PS "CALL()" we have at least one result set. If the SP does also 
some, then
  we need to clean the wire more fool-proof.
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqlnd/mysqlnd_ps.c?r1=1.18&r2=1.19&diff_format=u
Index: php-src/ext/mysqlnd/mysqlnd_ps.c
diff -u php-src/ext/mysqlnd/mysqlnd_ps.c:1.18 
php-src/ext/mysqlnd/mysqlnd_ps.c:1.19
--- php-src/ext/mysqlnd/mysqlnd_ps.c:1.18       Tue Jul 15 13:12:27 2008
+++ php-src/ext/mysqlnd/mysqlnd_ps.c    Wed Jul 23 14:06:31 2008
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: mysqlnd_ps.c,v 1.18 2008/07/15 13:12:27 andrey Exp $ */
+/* $Id: mysqlnd_ps.c,v 1.19 2008/07/23 14:06:31 andrey Exp $ */
 #include "php.h"
 #include "mysqlnd.h"
 #include "mysqlnd_wireprotocol.h"
@@ -1985,7 +1985,7 @@
        zend_uchar cmd_buf[STMT_ID_LENGTH /* statement id */];
        enum_mysqlnd_collected_stats stat = STAT_LAST;
 
-       DBG_ENTER("mysqlnd_stmt::close");
+       DBG_ENTER("mysqlnd_stmt::net_close");
        DBG_INF_FMT("stmt=%lu", stmt->stmt_id);
 
        SET_EMPTY_ERROR(stmt->error_info);
@@ -1996,17 +1996,20 @@
          We have to call the appropriate use_result() or store_result() and
          clean.
        */
-       if (stmt->state == MYSQLND_STMT_WAITING_USE_OR_STORE) {
-               DBG_INF("fetching result set header");
-               stmt->default_rset_handler(stmt TSRMLS_CC);
-               stmt->state = MYSQLND_STMT_USER_FETCHING;
-       }
+       do {
+               DBG_INF_FMT("stmt->state=%d", stmt->state);
+               if (stmt->state == MYSQLND_STMT_WAITING_USE_OR_STORE) {
+                       DBG_INF("fetching result set header");
+                       stmt->default_rset_handler(stmt TSRMLS_CC);
+                       stmt->state = MYSQLND_STMT_USER_FETCHING;
+               }
 
-       /* unbuffered set not fetched to the end ? Clean the line */
-       if (stmt->result) {
-               DBG_INF("skipping result");
-               stmt->result->m.skip_result(stmt->result TSRMLS_CC);
-       }
+               /* unbuffered set not fetched to the end ? Clean the line */
+               if (stmt->result) {
+                       DBG_INF("skipping result");
+                       stmt->result->m.skip_result(stmt->result TSRMLS_CC);
+               }
+       } while (mysqlnd_stmt_more_results(stmt) && 
mysqlnd_stmt_next_result(stmt));
        /*
          After this point we are allowed to free the result set,
          as we have cleaned the line

http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/bug44897.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/bug44897.phpt
+++ php-src/ext/mysqli/tests/bug44897.phpt
--TEST--
Bug #44879 (    failed to prepare statement)
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnectfailure.inc');
require_once('connect.inc');
if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
        die(sprintf('skip Cannot connect to MySQL, [%d] %s.', 
mysqli_connect_errno(), mysqli_connect_error()));
}
if (mysqli_get_server_version($link) <= 50000) {
        die(sprintf('skip Needs MySQL 5.0+, found version %d.', 
mysqli_get_server_version($link)));
}
?>
--FILE--
<?php
        require_once("connect.inc");
        require_once("table.inc");

        if (!$link->query('DROP PROCEDURE IF EXISTS p'))
                printf("[001] [%d] %s\n", $link->errno, $link->error);

        if (!$link->query('CREATE PROCEDURE p(IN new_id INT, IN new_label 
CHAR(1)) BEGIN INSERT INTO test(id, label) VALUES (new_id, new_label); SELECT 
new_label; END;'))
                printf("[002] [%d] %s\n", $link->errno, $link->error);

        $new_id = 100;
        $new_label = 'z';

        if (!$stmt = $link->prepare('CALL p(?, ?)'))
                printf("[003] [%d] %s\n", $link->errno, $link->error);

        if (!$stmt->bind_param('is', $new_id, $new_label) || !$stmt->execute())
                printf("[004] [%d] %s\n", $stmt->errno, $stmt->error);

        $out_new_label = null;
        if (!$stmt->bind_result($out_new_label) || !$stmt->fetch())
                printf("[005] [%d] %s\n", $stmt->errno, $stmt->error);

        if ($out_new_label != $new_label)
                printf("[006] IN value and returned value differ. Expecting 
%s/%s got %s/%s\n",
                        $new_label, gettype($new_label), $out_new_label, 
gettype($out_new_label));

        $stmt->close();

        $stmt2 = $link->prepare('SELECT label FROM test WHERE id = ?');
        if (!is_object($stmt2)) {

                printf("[007] Failed to create new statement object\n");

        } else {

                if (!$stmt2->bind_param("i", $new_id) || !$stmt2->execute())
                        printf("[008] [%d] %s\n", $stmt2->errno, $stmt2->error);

                $out_new_label = null;
                if (!$stmt2->bind_result($out_new_label) || !$stmt2->fetch())
                        printf("[009] [%d] %s\n", $stmt2->errno, $stmt2->error);

                if ($out_new_label != $new_label)
                        printf("[010] IN value and returned value differ. 
Expecting %s/%s got %s/%s\n",
                                $new_label, gettype($new_label), 
$out_new_label, gettype($out_new_label));

        }

        $link->close();

        print "done!";
?>
--EXPECTF--
done!



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

Reply via email to