List:Commits« Previous MessageNext Message »
From:uwendel Date:March 10 2008 5:04pm
Subject:PHP mysqlnd svn commit: r1341 - trunk/tests/ext/pdo_mysql
View as plain text  
Author: uwendel
Date: 2008-03-10 17:04:35 +0100 (Mon, 10 Mar 2008)
New Revision: 1341

Modified:
   trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_getcolumnmeta.phpt
Log:
Its really seems too early to test the function. It needs to be improved before any
testing makes sense. Otherwise its just failing all the time...


Modified: trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_getcolumnmeta.phpt
===================================================================
--- trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_getcolumnmeta.phpt	2008-03-10 13:42:50 UTC
(rev 1340)
+++ trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_getcolumnmeta.phpt	2008-03-10 16:04:35 UTC
(rev 1341)
@@ -17,24 +17,111 @@
 
 	$stmt = $db->prepare('SELECT id FROM test ORDER BY id ASC');
 
+	// execute() has not been called yet
+	// NOTE: no warning
+	if (false !== ($tmp = $stmt->getColumnMeta(0)))
+		printf("[002] Expecting false got %s\n", var_export($tmp, true));
+
+	$stmt->execute();
 	// Warning: PDOStatement::getColumnMeta() expects exactly 1 parameter, 0 given in
 	if (false !== ($tmp = @$stmt->getColumnMeta()))
-		printf("[002] Expecting false got %s\n", var_export($tmp, true));
+		printf("[003] Expecting false got %s\n", var_export($tmp, true));
 
 	// invalid offset
 	if (false !== ($tmp = @$stmt->getColumnMeta(-1)))
-		printf("[003] Expecting false got %s\n", var_export($tmp, true));
+		printf("[004] Expecting false got %s\n", var_export($tmp, true));
 
 	// Warning: PDOStatement::getColumnMeta() expects parameter 1 to be long, array given in
 	if (false !== ($tmp = @$stmt->getColumnMeta(array())))
-		printf("[004] Expecting false got %s\n", var_export($tmp, true));
+		printf("[005] Expecting false got %s\n", var_export($tmp, true));
 
 	// Warning: PDOStatement::getColumnMeta() expects exactly 1 parameter, 2 given in
 	if (false !== ($tmp = @$stmt->getColumnMeta(1, 1)))
-		printf("[005] Expecting false got %s\n", var_export($tmp, true));
+		printf("[006] Expecting false got %s\n", var_export($tmp, true));
 
-	var_dump($stmt->getColumnMeta(1));
+	$emulated =  $stmt->getColumnMeta(0);
 
+	printf("Testing native PS...\n");
+	$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
+		if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
+			printf("[007] Unable to turn off emulated prepared statements\n");
+
+	$stmt = $db->prepare('SELECT id FROM test ORDER BY id ASC');
+	$stmt->execute();
+	$native = $stmt->getColumnMeta(0);
+	if ((count($native) == 0) || ($native != $emulated)) {
+		printf("[008] Meta data seems wrong, %s / %s\n",
+			var_export($native, true), var_export($emulated, true));
+	}
+
+	function test_meta(&$db, $offset, $sql_type, $value, $native_type, $pdo_type) {
+
+		$db->exec('DROP TABLE IF EXISTS test');
+
+		$sql = sprintf('CREATE TABLE test(id %s) ENGINE=%s', $sql_type,
MySQLPDOTest::getTableEngine());
+		if (!($stmt = $db->prepare($sql)) || (!$stmt->execute())) {
+			// Some engines and/or MySQL server versions might not support the data type
+			return true;
+		}
+
+		if (!$db->exec(sprintf('INSERT INTO test(id) VALUES ("%s")', $value))) {
+			printf("[%03d] + 1] Insert failed, %d - %s\n", $offset,
+				$db->errorCode(), var_export($db->errorInfo(), true));
+			return false;
+		}
+
+		$stmt = $db->prepare('SELECT id FROM test');
+		$stmt->execute();
+		$meta = $stmt->getColumnMeta(0);
+
+		if (empty($meta)) {
+			printf("[%03d + 2] getColumnMeta() failed, %d - %s\n", $offset,
+				$stmt->errorCode(), var_export($stmt->errorInfo(), true));
+			return false;
+		}
+
+		$elements = array('native_type', 'flags', 'table', 'name', 'len', 'precision',
'pdo_type');
+		foreach ($elements as $k => $element)
+			if (!isset($meta[$element])) {
+				printf("[%03d + 3] Element %s missing, %s\n", $offset,
+					$element, var_export($meta, true));
+				return false;
+			}
+
+		if (($meta['table'] != 'test') || ($meta['name'] != 'id')) {
+			printf("[%03d + 4] Table or field name is wrong, %s\n", $offset,
+				var_export($meta, true));
+			return false;
+		}
+
+		if ($meta['native_type'] != $native_type) {
+			printf("[%03d + 5] Expecting native type %s, %s\n", $offset,
+				$native_type, var_export($meta, true));
+			return false;
+		}
+
+		if ($meta['native_type'] != $native_type) {
+			printf("[%03d + 6] Expecting native type %s, %s\n", $offset,
+				$native_type, var_export($meta, true));
+			return false;
+		}
+
+		return true;
+	}
+
+	/*
+	TODO: It seems to be too early to test any of those, the function implementation
+	seems incomplete...
+
+	test_meta($db, 20, 'BIT(8)', 1, '? INTEGER ?', PDO::PARAM_INT);
+	test_meta($db, 30, 'TINYINT', -127, '? SHORT ?', PDO::PARAM_INT);
+	test_meta($db, 40, 'TINYINT UNSIGNED', 255, '? SHORT ?', PDO::PARAM_INT);
+	test_meta($db, 50, 'BOOLEAN', 1, '? SHORT ?', PDO::PARAM_INT);
+	test_meta($db, 60, 'SMALLINT', -32768, '? SHORT ?', PDO::PARAM_INT);
+	test_meta($db, 70, 'SMALLINT', 32767, '? SHORT ?', PDO::PARAM_INT);
+	*/
+	test_meta($db, 80, 'VARCHAR(1)', "A", 'VAR_STRING', PDO::PARAM_STR);
+
 } catch (PDOException $e) {
 	// we should never get here, we use warnings, but never trust a system...
 	printf("[001] %s, [%s} %s\n",
@@ -43,5 +130,5 @@
 print "done!";
 ?>
 --EXPECTF--
-bool(false)
+Testing native PS...
 done!
\ No newline at end of file

Thread
PHP mysqlnd svn commit: r1341 - trunk/tests/ext/pdo_mysqluwendel10 Mar 2008