List:Commits« Previous MessageNext Message »
From:uwendel Date:July 19 2007 9:18am
Subject:PHP mysqlnd svn commit: r796 - trunk/tests/ext/mysqli
View as plain text  
Author: uwendel
Date: 2007-07-19 11:18:09 +0200 (Thu, 19 Jul 2007)
New Revision: 796

Added:
   trunk/tests/ext/mysqli/mysqli_result_references.phpt
   trunk/tests/ext/mysqli/mysqli_result_references_mysqlnd.phpt
Log:
Playing a bit with references and checking refcount.


Added: trunk/tests/ext/mysqli/mysqli_result_references.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_result_references.phpt	2007-07-19 08:04:21 UTC (rev 795)
+++ trunk/tests/ext/mysqli/mysqli_result_references.phpt	2007-07-19 09:18:09 UTC (rev 796)
@@ -0,0 +1,199 @@
+--TEST--
+References to result sets
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifemb.inc'); ?>
+--FILE--
+<?php
+	require_once('connect.inc');
+	require_once('table.inc');
+
+	$references = array();
+
+	if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2")) ||
+			!($res = mysqli_store_result($link)))
+		printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+
+	$idx = 0;
+	while ($row = mysqli_fetch_assoc($res)) {
+		/* mysqlnd: force seperation - create copies */
+		$references[$idx] = array(
+			'id' 		=> &$row['id'],
+			'label'	=> $row['label'] . '');
+		$references[$idx++]['id'] += 0;
+	}
+
+	mysqli_close($link);
+
+	mysqli_data_seek($res, 0);
+	while ($row = mysqli_fetch_assoc($res)) {
+		/* mysqlnd: force seperation - create copies */
+		$references[$idx] = array(
+			'id' 		=> &$row['id'],
+			'label'	=> $row['label'] . '');
+		$references[$idx++]['id'] += 0;
+	}
+
+	mysqli_free_result($res);
+
+	if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))
+		printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***,
dbname=%s, port=%s, socket=%s\n",
+			$host, $user, $db, $port, $socket);
+
+	if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2")) ||
+			!($res = mysqli_use_result($link)))
+		printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+
+	while ($row = mysqli_fetch_assoc($res)) {
+		/* mysqlnd: force seperation - create copies*/
+		$references[$idx] = array(
+			'id' 		=> &$row['id'],
+			'label'	=> $row['label'] . '');
+		$references[$idx]['id2'] = &$references[$idx]['id'];
+		$references[$idx]['id'] += 1;
+		$references[$idx++]['id2'] += 1;
+	}
+
+	$references[$idx++] = &$res;
+	mysqli_free_result($res);
+	debug_zval_dump($references);
+
+	if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 1")) ||
+			!($res = mysqli_use_result($link)))
+		printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+
+	$tmp = array();
+	while ($row = mysqli_fetch_assoc($res)) {
+		$tmp[] = $row;
+	}
+	$tmp = unserialize(serialize($tmp));
+	debug_zval_dump($tmp);
+	mysqli_free_result($res);
+
+	mysqli_close($link);
+	print "done!";
+?>
+--EXPECTF--
+array(7) refcount(2){
+  [0]=>
+  array(2) refcount(1){
+    ["id"]=>
+    long(1) refcount(1)
+    ["label"]=>
+    string(1) "a" refcount(1)
+  }
+  [1]=>
+  array(2) refcount(1){
+    ["id"]=>
+    long(2) refcount(1)
+    ["label"]=>
+    string(1) "b" refcount(1)
+  }
+  [2]=>
+  array(2) refcount(1){
+    ["id"]=>
+    long(1) refcount(1)
+    ["label"]=>
+    string(1) "a" refcount(1)
+  }
+  [3]=>
+  array(2) refcount(1){
+    ["id"]=>
+    long(2) refcount(1)
+    ["label"]=>
+    string(1) "b" refcount(1)
+  }
+  [4]=>
+  array(3) refcount(1){
+    ["id"]=>
+    &long(3) refcount(2)
+    ["label"]=>
+    string(1) "a" refcount(1)
+    ["id2"]=>
+    &long(3) refcount(2)
+  }
+  [5]=>
+  array(3) refcount(1){
+    ["id"]=>
+    &long(4) refcount(2)
+    ["label"]=>
+    string(1) "b" refcount(1)
+    ["id2"]=>
+    &long(4) refcount(2)
+  }
+  [6]=>
+  &object(mysqli_result)#2 (0) refcount(2){
+  }
+}
+array(1) refcount(2){
+  [0]=>
+  array(2) refcount(1){
+    ["id"]=>
+    string(1) "1" refcount(1)
+    ["label"]=>
+    string(1) "a" refcount(1)
+  }
+}
+done!
+--UEXPECTF--
+array(7) refcount(2){
+  [0]=>
+  array(2) refcount(1){
+    [u"id" { 0069 0064 }]=>
+    long(1) refcount(1)
+    [u"label" { 006c 0061 0062 0065 006c }]=>
+    unicode(1) "a" { 0061 } refcount(1)
+  }
+  [1]=>
+  array(2) refcount(1){
+    [u"id" { 0069 0064 }]=>
+    long(2) refcount(1)
+    [u"label" { 006c 0061 0062 0065 006c }]=>
+    unicode(1) "b" { 0062 } refcount(1)
+  }
+  [2]=>
+  array(2) refcount(1){
+    [u"id" { 0069 0064 }]=>
+    long(1) refcount(1)
+    [u"label" { 006c 0061 0062 0065 006c }]=>
+    unicode(1) "a" { 0061 } refcount(1)
+  }
+  [3]=>
+  array(2) refcount(1){
+    [u"id" { 0069 0064 }]=>
+    long(2) refcount(1)
+    [u"label" { 006c 0061 0062 0065 006c }]=>
+    unicode(1) "b" { 0062 } refcount(1)
+  }
+  [4]=>
+  array(3) refcount(1){
+    [u"id" { 0069 0064 }]=>
+    &long(3) refcount(2)
+    [u"label" { 006c 0061 0062 0065 006c }]=>
+    unicode(1) "a" { 0061 } refcount(1)
+    [u"id2" { 0069 0064 0032 }]=>
+    &long(3) refcount(2)
+  }
+  [5]=>
+  array(3) refcount(1){
+    [u"id" { 0069 0064 }]=>
+    &long(4) refcount(2)
+    [u"label" { 006c 0061 0062 0065 006c }]=>
+    unicode(1) "b" { 0062 } refcount(1)
+    [u"id2" { 0069 0064 0032 }]=>
+    &long(4) refcount(2)
+  }
+  [6]=>
+  &object(mysqli_result)#2 (0) refcount(2){
+  }
+}
+array(1) refcount(2){
+  [0]=>
+  array(2) refcount(1){
+    [u"id" { 0069 0064 }]=>
+    unicode(1) "1" { 0031 } refcount(1)
+    [u"label" { 006c 0061 0062 0065 006c }]=>
+    unicode(1) "a" { 0061 } refcount(1)
+  }
+}
+done!
\ No newline at end of file

Added: trunk/tests/ext/mysqli/mysqli_result_references_mysqlnd.phpt
===================================================================
--- trunk/tests/ext/mysqli/mysqli_result_references_mysqlnd.phpt	2007-07-19 08:04:21 UTC
(rev 795)
+++ trunk/tests/ext/mysqli/mysqli_result_references_mysqlnd.phpt	2007-07-19 09:18:09 UTC
(rev 796)
@@ -0,0 +1,137 @@
+--TEST--
+References to result sets - mysqlnd (no copies but references)
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifemb.inc');
+require_once('connect.inc');
+if (!$IS_MYSQLND)
+	die("skip Test for mysqlnd only");
+?>
+<?php require_once('skipifemb.inc'); ?>
+--FILE--
+<?php
+	require_once('connect.inc');
+	require_once('table.inc');
+
+	$references = array();
+
+	if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 1")) ||
+			!($res = mysqli_store_result($link)))
+		printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+
+	$idx = 0;
+	while ($row = mysqli_fetch_assoc($res)) {
+		/* will overwrite itself */
+		$references[$idx]['row_ref'] 		= &$row;
+		$references[$idx]['row_copy'] 	= $row;
+		$references[$idx]['id_ref'] 		= &$row['id'];
+		$references[$idx++]['id_copy']	= $row['id'];
+	}
+	mysqli_free_result($res);
+
+	if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2")) ||
+			!($res = mysqli_use_result($link)))
+		printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+
+	$rows = array();
+	for ($i = 0; $i < 2; $i++) {
+		$rows[$i] = mysqli_fetch_assoc($res);
+		$references[$idx]['row_ref'] 		= &$rows[$i];
+		$references[$idx]['row_copy'] 	= $rows[$i];
+		$references[$idx]['id_ref'] 		= &$rows[$i]['id'];
+		$references[$idx]['id_copy']		= $rows[$i]['id'];
+		/* enforce seperation */
+		$references[$idx]['id_copy_mod']= $rows[$i]['id'] + 0;
+	}
+	mysqli_free_result($res);
+
+	debug_zval_dump($references);
+	print "done!";
+?>
+--EXPECTF--
+array(2) refcount(2){
+  [0]=>
+  array(4) refcount(1){
+    ["row_ref"]=>
+    &NULL refcount(2)
+    ["row_copy"]=>
+    array(2) refcount(1){
+      ["id"]=>
+      string(1) "1" refcount(2)
+      ["label"]=>
+      string(1) "a" refcount(2)
+    }
+    ["id_ref"]=>
+    string(1) "1" refcount(1)
+    ["id_copy"]=>
+    string(1) "1" refcount(1)
+  }
+  [1]=>
+  array(5) refcount(1){
+    ["row_ref"]=>
+    &array(2) refcount(2){
+      ["id"]=>
+      &string(1) "2" refcount(2)
+      ["label"]=>
+      string(1) "b" refcount(3)
+    }
+    ["row_copy"]=>
+    array(2) refcount(1){
+      ["id"]=>
+      string(1) "2" refcount(2)
+      ["label"]=>
+      string(1) "b" refcount(3)
+    }
+    ["id_ref"]=>
+    &string(1) "2" refcount(2)
+    ["id_copy"]=>
+    string(1) "2" refcount(1)
+    ["id_copy_mod"]=>
+    long(2) refcount(1)
+  }
+}
+done!
+--UEXPECTF--
+array(2) refcount(2){
+  [0]=>
+  array(4) refcount(1){
+    [u"row_ref" { 0072 006f 0077 005f 0072 0065 0066 }]=>
+    &NULL refcount(2)
+    [u"row_copy" { 0072 006f 0077 005f 0063 006f 0070 0079 }]=>
+    array(2) refcount(1){
+      [u"id" { 0069 0064 }]=>
+      unicode(1) "1" { 0031 } refcount(2)
+      [u"label" { 006c 0061 0062 0065 006c }]=>
+      unicode(1) "a" { 0061 } refcount(2)
+    }
+    [u"id_ref" { 0069 0064 005f 0072 0065 0066 }]=>
+    unicode(1) "1" { 0031 } refcount(1)
+    [u"id_copy" { 0069 0064 005f 0063 006f 0070 0079 }]=>
+    unicode(1) "1" { 0031 } refcount(1)
+  }
+  [1]=>
+  array(5) refcount(1){
+    [u"row_ref" { 0072 006f 0077 005f 0072 0065 0066 }]=>
+    &array(2) refcount(2){
+      [u"id" { 0069 0064 }]=>
+      &unicode(1) "2" { 0032 } refcount(2)
+      [u"label" { 006c 0061 0062 0065 006c }]=>
+      unicode(1) "b" { 0062 } refcount(3)
+    }
+    [u"row_copy" { 0072 006f 0077 005f 0063 006f 0070 0079 }]=>
+    array(2) refcount(1){
+      [u"id" { 0069 0064 }]=>
+      unicode(1) "2" { 0032 } refcount(2)
+      [u"label" { 006c 0061 0062 0065 006c }]=>
+      unicode(1) "b" { 0062 } refcount(3)
+    }
+    [u"id_ref" { 0069 0064 005f 0072 0065 0066 }]=>
+    &unicode(1) "2" { 0032 } refcount(2)
+    [u"id_copy" { 0069 0064 005f 0063 006f 0070 0079 }]=>
+    unicode(1) "2" { 0032 } refcount(1)
+    [u"id_copy_mod" { 0069 0064 005f 0063 006f 0070 0079 005f 006d 006f 0064 }]=>
+    long(2) refcount(1)
+  }
+}
+done!
\ No newline at end of file

Thread
PHP mysqlnd svn commit: r796 - trunk/tests/ext/mysqliuwendel19 Jul