andrey          Thu Mar 20 15:34:09 2008 UTC

  Modified files:              
    /php-src/ext/mysqli mysqli_api.c 
    /php-src/ext/mysqli/tests   
                                
mysqli_stmt_bind_param_check_param_no_change.phpt 
    /php-src/ext/mysqlnd        mysqlnd_ps_codec.c 
  Log:
  Small fix and a test case to prove it
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/mysqli_api.c?r1=1.162&r2=1.163&diff_format=u
Index: php-src/ext/mysqli/mysqli_api.c
diff -u php-src/ext/mysqli/mysqli_api.c:1.162 
php-src/ext/mysqli/mysqli_api.c:1.163
--- php-src/ext/mysqli/mysqli_api.c:1.162       Thu Mar 20 13:58:46 2008
+++ php-src/ext/mysqli/mysqli_api.c     Thu Mar 20 15:34:09 2008
@@ -17,7 +17,7 @@
   |          Ulf Wendel <[EMAIL PROTECTED]>                                    
 |
   +----------------------------------------------------------------------+
 
-  $Id: mysqli_api.c,v 1.162 2008/03/20 13:58:46 andrey Exp $ 
+  $Id: mysqli_api.c,v 1.163 2008/03/20 15:34:09 andrey Exp $ 
 */
 
 #ifdef HAVE_CONFIG_H
@@ -749,8 +749,10 @@
                                switch (stmt->stmt->params[i].buffer_type) {
                                        case MYSQL_TYPE_VAR_STRING:
                                                if (UG(unicode) && 
Z_TYPE_P(the_var) == IS_UNICODE) {
-                                                       
php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
-                                                       the_var = copies[i];
+                                                       if (the_var == 
stmt->param.vars[i]) { 
+                                                               
php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
+                                                               the_var = 
copies[i];
+                                                       }
                                                        
zval_unicode_to_string_ex(the_var, UG(utf8_conv) TSRMLS_CC);
                                                } else {
                                                        if (the_var == 
stmt->param.vars[i] && Z_TYPE_P(stmt->param.vars[i]) != IS_STRING) {
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_stmt_bind_param_check_param_no_change.phpt?r1=1.1&r2=1.2&diff_format=u
Index: 
php-src/ext/mysqli/tests/mysqli_stmt_bind_param_check_param_no_change.phpt
diff -u /dev/null 
php-src/ext/mysqli/tests/mysqli_stmt_bind_param_check_param_no_change.phpt:1.2
--- /dev/null   Thu Mar 20 15:34:09 2008
+++ php-src/ext/mysqli/tests/mysqli_stmt_bind_param_check_param_no_change.phpt  
Thu Mar 20 15:34:09 2008
@@ -0,0 +1,148 @@
+--TEST--
+mysqli_stmt_bind_param() - checking whether the parameters are modified 
(bug#44390)
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifemb.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+       include "connect.inc";
+       require('table.inc');
+
+       class foo {
+         // @var $bar string
+         public $bar;
+       }
+
+       $foo = new foo;
+       $foo->bar = "фубар";
+
+       echo "Test 1: \n";
+       $stmt = $link->prepare("SELECT ? FOO");
+       var_dump($foo); // here you can see the bar member var beeing a string
+       $stmt->bind_param("s", $foo->bar);
+       var_dump($foo); // this will show $foo->bar beeing a reference string
+       $stmt->bind_result($one);
+       $stmt->execute();
+       $stmt->fetch();
+       $stmt->free_result();
+       echo("$one\n\n");
+
+       // it is getting worse. Binding the same var twice with different 
+       // types you can get unexpected results (e.g. binary trash for the
+       // string and misc data for the integer. See next 2 tests.
+
+       echo "Test 2: \n";
+       $stmt = $link->prepare("SELECT ? FOO, ? BAR");
+       var_dump($foo);
+       $stmt->bind_param("si", $foo->bar, $foo->bar);
+       echo "---\n";
+       var_dump($foo);
+       echo "---\n";
+       $stmt->execute();
+       var_dump($foo);
+       echo "---\n";
+       $stmt->bind_result($one, $two);
+       $stmt->fetch();
+       $stmt->free_result();
+       echo("$one - $two\n\n");
+
+
+       echo "Test 3: \n";
+       $stmt = $link->prepare("SELECT ? FOO, ? BAR");
+       var_dump($foo);
+       $stmt->bind_param("is", $foo->bar, $foo->bar);
+       var_dump($foo);
+       $stmt->bind_result($one, $two);
+       $stmt->execute();
+       $stmt->fetch();
+       $stmt->free_result();
+       echo("$one - $two\n\n");
+       echo "done!\n";
+?>
+--EXPECTF--
+Test 1: 
+object(foo)#3 (1) {
+  ["bar"]=>
+  string(10) "фубар"
+}
+object(foo)#3 (1) {
+  ["bar"]=>
+  &string(10) "фубар"
+}
+фубар
+
+Test 2: 
+object(foo)#3 (1) {
+  ["bar"]=>
+  string(10) "фубар"
+}
+---
+object(foo)#3 (1) {
+  ["bar"]=>
+  &string(10) "фубар"
+}
+---
+object(foo)#3 (1) {
+  ["bar"]=>
+  &string(10) "фубар"
+}
+---
+фубар - 0
+
+Test 3: 
+object(foo)#3 (1) {
+  ["bar"]=>
+  string(10) "фубар"
+}
+object(foo)#3 (1) {
+  ["bar"]=>
+  &string(10) "фубар"
+}
+0 - фубар
+
+done!
+--UEXPECTF--
+Test 1: 
+object(foo)#3 (1) {
+  [u"bar"]=>
+  unicode(5) "фубар"
+}
+object(foo)#3 (1) {
+  [u"bar"]=>
+  &unicode(5) "фубар"
+}
+фубар
+
+Test 2: 
+object(foo)#3 (1) {
+  [u"bar"]=>
+  unicode(5) "фубар"
+}
+---
+object(foo)#3 (1) {
+  [u"bar"]=>
+  &unicode(5) "фубар"
+}
+---
+object(foo)#3 (1) {
+  [u"bar"]=>
+  &unicode(5) "фубар"
+}
+---
+фубар - 0
+
+Test 3: 
+object(foo)#3 (1) {
+  [u"bar"]=>
+  unicode(5) "фубар"
+}
+object(foo)#3 (1) {
+  [u"bar"]=>
+  &unicode(5) "фубар"
+}
+0 - фубар
+
+done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqlnd/mysqlnd_ps_codec.c?r1=1.7&r2=1.8&diff_format=u
Index: php-src/ext/mysqlnd/mysqlnd_ps_codec.c
diff -u php-src/ext/mysqlnd/mysqlnd_ps_codec.c:1.7 
php-src/ext/mysqlnd/mysqlnd_ps_codec.c:1.8
--- php-src/ext/mysqlnd/mysqlnd_ps_codec.c:1.7  Thu Mar 20 13:25:49 2008
+++ php-src/ext/mysqlnd/mysqlnd_ps_codec.c      Thu Mar 20 15:34:09 2008
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: mysqlnd_ps_codec.c,v 1.7 2008/03/20 13:25:49 andrey Exp $ */
+/* $Id: mysqlnd_ps_codec.c,v 1.8 2008/03/20 15:34:09 andrey Exp $ */
 #include "php.h"
 #include "mysqlnd.h"
 #include "mysqlnd_wireprotocol.h"
@@ -828,14 +828,7 @@
                                                *p = 
php_mysqlnd_net_store_length(*p, 0);
                                        }
                                        break;
-                               case MYSQL_TYPE_VAR_STRING:
-                                       /*
-                                         If the user uses refs, it could be 
that the type has
-                                         has changed and we need to convert, 
again. Which is noop,
-                                         if the type hasn't changed.
-                                       */
-                                       
convert_to_string_ex(&stmt->param_bind[i].zv);
-                                       {
+                               case MYSQL_TYPE_VAR_STRING:{
                                                unsigned int len = 
Z_STRLEN_P(data);
                                                /* to is after p. The latter 
hasn't been moved */
                                                *p = 
php_mysqlnd_net_store_length(*p, len);



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

Reply via email to