List:Commits« Previous MessageNext Message »
From:uwendel Date:April 23 2008 12:29pm
Subject:PHP mysqlnd svn commit: r1510 - trunk/tests/ext/pdo_mysql
View as plain text  
Author: uwendel
Date: 2008-04-23 12:29:49 +0200 (Wed, 23 Apr 2008)
New Revision: 1510

Modified:
   trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_closecursor.phpt
Log:
Adding test for buffered queries


Modified: trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_closecursor.phpt
===================================================================
--- trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_closecursor.phpt	2008-04-23 09:35:30 UTC (rev
1509)
+++ trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_closecursor.phpt	2008-04-23 10:29:49 UTC (rev
1510)
@@ -13,14 +13,8 @@
 	$db = MySQLPDOTest::factory();
 	MySQLPDOTest::createTestTable($db);
 
-	printf("Testing emulated PS...\n");
-	try {
-		$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
-		if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
-			printf("[002] Unable to turn on emulated prepared statements\n");
+	function pdo_mysql_stmt_closecursor($db) {
 
-		printf("Trying to get 2014 Cannot execute queries while other unbuffered queries are
active...\n");
-
 		// This one should fail. I let it fail to prove that closeCursor() makes a difference.
 		// If no error messages gets printed do not know if proper usage of closeCursor() makes
any
 		// difference or not. That's why we need to cause an error here.
@@ -32,16 +26,59 @@
 
 		// This is proper usage of closeCursor(). It shall prevent any further error messages.
 		$stmt1 = $db->query('SELECT id, label FROM test ORDER BY id ASC');
-		$row = $stmt1->fetch(PDO::FETCH_ASSOC);
+		// fetch only the first rows and let closeCursor() clean up
+		$row1 = $stmt1->fetch(PDO::FETCH_ASSOC);
 		$stmt1->closeCursor();
 
 		$stmt2 = $db->prepare('UPDATE test SET label = ? WHERE id = ?');
 		$stmt2->bindValue(1, "z");
 
-		$stmt2->bindValue(2, $row['id']);
+		$stmt2->bindValue(2, $row1['id']);
 		$stmt2->execute();
+		$stmt2->closeCursor();
+
 		$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
+		// check if changing the fetch mode from unbuffered to buffered will
+		// cause any harm to a statement created prior to the change
+		$stmt1->execute();
+		$row2 = $stmt1->fetch(PDO::FETCH_ASSOC);
+		$stmt1->closeCursor();
+		if (!isset($row2['label']) || ('z' !== $row2['label']))
+			printf("Expecting array(id => 1, label => z) got %s\n", var_export($row2,
true));
+		unset($stmt1);
 
+		$stmt1 = $db->query('SELECT id, label FROM test ORDER BY id ASC');
+		// should work
+		$stmt2 = $db->query('SELECT id, label FROM test ORDER BY id ASC');
+		$stmt1->closeCursor();
+
+		$stmt1 = $db->query('SELECT id, label FROM test ORDER BY id ASC');
+		// fetch only the first rows and let closeCursor() clean up
+		$row3 = $stmt1->fetch(PDO::FETCH_ASSOC);
+		$stmt1->closeCursor();
+		assert($row3 == $row2);
+
+		$stmt2 = $db->prepare('UPDATE test SET label = ? WHERE id = ?');
+		$stmt2->bindValue(1, "a");
+		$stmt2->bindValue(2, $row1['id']);
+		$stmt2->execute();
+		$stmt2->closeCursor();
+
+		$stmt1->execute();
+		$row4 = $stmt1->fetch(PDO::FETCH_ASSOC);
+		$stmt1->closeCursor();
+		assert($row4 == $row1);
+	}
+
+	printf("Testing emulated PS...\n");
+	try {
+		$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
+		if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
+			printf("[002] Unable to turn on emulated prepared statements\n");
+
+		printf("Trying to get 2014 Cannot execute queries while other unbuffered queries are
active...\n");
+		pdo_mysql_stmt_closecursor($db);
+
 	} catch (PDOException $e) {
 		printf("[001] %s [%s] %s\n",
 			$e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
@@ -53,28 +90,8 @@
 		if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
 			printf("[002] Unable to turn off emulated prepared statements\n");
 
-		// This one should fail. I let it fail to prove that closeCursor() makes a difference.
-		// If no error messages gets printed do not know if proper usage of closeCursor() makes
any
-		// difference or not. That's why we need to cause an error here.
-		$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
-		$stmt1 = $db->query('SELECT id, label FROM test ORDER BY id ASC');
-		$row = $stmt1->fetch(PDO::FETCH_ASSOC);
-		// query() shall fail!
-		$stmt2 = $db->query('SELECT id, label FROM test ORDER BY id ASC');
-		$stmt1->closeCursor();
+		pdo_mysql_stmt_closecursor($db);
 
-		// This is proper usage of closeCursor(). It shall prevent any further error messages.
-		$stmt1 = $db->query('SELECT id, label FROM test ORDER BY id ASC');
-		$row = $stmt1->fetch(PDO::FETCH_ASSOC);
-		$stmt1->closeCursor();
-
-		$stmt2 = $db->prepare('UPDATE test SET label = ? WHERE id = ?');
-		$stmt2->bindValue(1, "z");
-
-		$stmt2->bindValue(2, $row['id']);
-		$stmt2->execute();
-		$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
-
 	} catch (PDOException $e) {
 		printf("[001] %s [%s] %s\n",
 			$e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));

Thread
PHP mysqlnd svn commit: r1510 - trunk/tests/ext/pdo_mysqluwendel23 Apr