Author: uwendel
Date: 2008-02-28 16:06:44 +0100 (Thu, 28 Feb 2008)
New Revision: 1308
Added:
trunk/tests/ext/pdo/pdo_stmt_columncount.phpt
Log:
Simple PDOStatement::columnCount() test
Added: trunk/tests/ext/pdo/pdo_stmt_columncount.phpt
===================================================================
--- trunk/tests/ext/pdo/pdo_stmt_columncount.phpt (rev 0)
+++ trunk/tests/ext/pdo/pdo_stmt_columncount.phpt 2008-02-28 15:06:44 UTC (rev 1308)
@@ -0,0 +1,99 @@
+--TEST--
+PDO Common: PDOStatement->columnCount()
+--SKIPIF--
+<?php # vim:ft=php
+if (!extension_loaded('pdo')) die('skip');
+$dir = getenv('REDIR_TEST_DIR');
+if (false == $dir) die('skip no driver');
+require_once $dir . 'pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) .
'/../../pdo/tests/');
+require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
+$db = PDOTest::factory();
+
+$db->exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp
VARCHAR(10))');
+$db->exec('INSERT INTO test VALUES(1, \'A\', \'Group1\')');
+$db->exec('INSERT INTO test VALUES(2, \'B\', \'Group2\')');
+
+try {
+
+ $stmt = $db->prepare('SELECT id FROM test WHERE id > ? ORDER BY id ASC');
+
+ if (false !== ($tmp = $stmt->columnCount(1)))
+ printf("[002] Expecting boolean/false got %s\n", var_export($tmp, true));
+
+ $tmp = array();
+ if (false !== ($tmp = $stmt->columnCount($tmp)))
+ printf("[003] Expecting boolean/false got %s\n", var_export($tmp, true));
+
+ $tmp = new stdClass();
+ if (false !== ($tmp = $stmt->columnCount($tmp)))
+ printf("[004] Expecting boolean/false got %s\n", var_export($tmp, true));
+
+ $stmt = @$db->prepare('SELECT id FROM test WHERE id > ? ORDER BY id ASC');
+ if (0 !== ($tmp = $stmt->columnCount()))
+ printf("[005] Prepared but not executed, column count should be unknown, got %s\n",
var_export($tmp, true));
+
+ printf("Testing prepare & execute()...\n");
+ $stmt = $db->prepare('SELECT id FROM test');
+ $stmt->execute();
+ var_dump($stmt->columnCount());
+
+ $stmt = $db->prepare('SELECT id, val FROM test');
+ $stmt->execute();
+ var_dump($stmt->columnCount());
+
+ $stmt = $db->prepare('SELECT id, val, "?" as foo FROM test');
+ $stmt->execute();
+ var_dump($stmt->columnCount());
+
+ $stmt = $db->prepare('SELECT * FROM test');
+ $stmt->execute();
+ var_dump($stmt->columnCount());
+
+ $stmt = $db->prepare('UPDATE test SET id = 3 WHERE id = 3');
+ $stmt->execute();
+ var_dump($stmt->columnCount());
+
+
+ printf("Testing query() - should give the very same results...\n");
+
+ $stmt = $db->query('SELECT id FROM test');
+ var_dump($stmt->columnCount());
+
+ $stmt = $db->query('SELECT id, val FROM test');
+ var_dump($stmt->columnCount());
+
+ $stmt = $db->query('SELECT id, val, "?" as foo FROM test');
+ var_dump($stmt->columnCount());
+
+ $stmt = $db->query('SELECT * FROM test');
+ var_dump($stmt->columnCount());
+
+ $stmt = $db->query('UPDATE test SET id = 3 WHERE id = 3');
+ var_dump($stmt->columnCount());
+
+} catch (PDOException $e) {
+ // we should never get here, we use warnings, but never trust a system...s
+ printf("[001] %s, [%s} %s\n",
+ $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
+}
+print "done!";
+?>
+--EXPECTF--
+Testing prepare & execute()...
+int(1)
+int(2)
+int(3)
+int(3)
+int(0)
+Testing query() - should give the very same results...
+int(1)
+int(2)
+int(3)
+int(3)
+int(0)
+done!
\ No newline at end of file
| Thread |
|---|
| • PHP mysqlnd svn commit: r1308 - trunk/tests/ext/pdo | uwendel | 28 Feb |