List:Commits« Previous MessageNext Message »
From:uwendel Date:April 17 2008 3:28pm
Subject:PHP mysqlnd svn commit: r1490 - trunk/tests/ext/pdo_mysql
View as plain text  
Author: uwendel
Date: 2008-04-17 17:28:09 +0200 (Thu, 17 Apr 2008)
New Revision: 1490

Added:
   trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_variable_columncount.phpt
Log:
This will crash both mysqlnd and libmysql sooner or later.
libmysql showed different reactions when writing this test.
Starting from packets out of order, random crashes and now an assertion failing.



Added: trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_variable_columncount.phpt
===================================================================
--- trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_variable_columncount.phpt	                   
    (rev 0)
+++ trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_variable_columncount.phpt	2008-04-17 15:28:09
UTC (rev 1490)
@@ -0,0 +1,107 @@
+--TEST--
+MySQL Prepared Statements and different column counts
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('mysql_pdo_test.inc');
+MySQLPDOTest::skip();
+$db = MySQLPDOTest::factory();
+
+$row = $db->query('SELECT VERSION() as _version')->fetch(PDO::FETCH_ASSOC);
+$matches = array();
+if (!preg_match('/^(\d+)\.(\d+)\.(\d+)/ismU', $row['_version'], $matches))
+	die(sprintf("skip Cannot determine MySQL Server version\n"));
+
+$version = $matches[0] * 10000 + $matches[1] * 100 + $matches[2];
+if ($version < 50000)
+	die(sprintf("skip Need MySQL Server 5.0.0+, found %s.%s.%s (%d)\n",
+		$matches[0], $matches[1], $matches[2], $version);
+?>
+--FILE--
+<?php
+	require_once('mysql_pdo_test.inc');
+	$db = MySQLPDOTest::factory();
+
+	try {
+
+		// What will happen if a PS returns a differen number of result set column upon each
execution?
+		$db->exec('DROP PROCEDURE IF EXISTS p');
+		$db->exec('CREATE PROCEDURE p() BEGIN IF RAND() > 0.5 THEN SELECT 1 AS "one";
ELSE SELECT 1 AS "one", 2 AS "two"; END IF; END;');
+
+		// Emulates PS first
+		$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
+		$column_count = $last_column_count = null;
+		$stmt = $db->query('CALL p()');
+		do {
+			$row = $stmt->fetch(PDO::FETCH_ASSOC);
+			if (empty($row)) {
+				printf("[002] Results seem wrong, %s\n",
+					var_export($stmt->errorInfo(), true));
+				break;
+			}
+
+			if (!isset($row['one']) || ($row['one'] != 1)) {
+				printf("[003] Expecting array('one' => 1), got %s\n", var_export($row, true));
+				break;
+			}
+
+			if ((count($row) == 2) &&
+					(!isset($row['two']) || ($row['two'] != 2))) {
+				printf("[004] Expecting array('one' => 1, 'two' => 2), got %s\n",
var_export($row, true));
+				break;
+			}
+
+			if ($last_column_count == NULL) {
+				$last_column_count = $column_count = count($row);
+				continue;
+			}
+			$column_count = count($row);
+
+		} while ($last_column_count == $column_count);
+
+		// Native PS
+		$db = MySQLPDOTest::factory();
+		$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
+		$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1);
+		$column_count = $last_column_count = null;
+		$stmt = $db->prepare('CALL p()');
+		do {
+			$stmt->execute();
+			do {
+				$row = $stmt->fetch(PDO::FETCH_ASSOC);
+			} while ($stmt->nextRowSet());
+
+			if (empty($row)) {
+				printf("[005] Results seem wrong, %s\n",
+					var_export($stmt->errorInfo(), true));
+				break;
+			}
+
+			if (!isset($row['one']) || ($row['one'] != 1)) {
+				printf("[006] Expecting array('one' => 1), got %s\n", var_export($row, true));
+				break;
+			}
+
+			if ((count($row) == 2) &&
+					(!isset($row['two']) || ($row['two'] != 2))) {
+				printf("[007] Expecting array('one' => 1, 'two' => 2), got %s\n",
var_export($row, true));
+				break;
+			}
+
+			if ($last_column_count == NULL) {
+				$last_column_count = $column_count = count($row);
+				continue;
+			}
+			$column_count = count($row);
+
+		} while ($last_column_count == $column_count);
+
+
+	} catch (PDOException $e) {
+		printf("[001] %s [%s] %s\n",
+			$e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
+	}
+
+	print "done!";
+--EXPECTF--
+done!
\ No newline at end of file

Thread
PHP mysqlnd svn commit: r1490 - trunk/tests/ext/pdo_mysqluwendel17 Apr