Author: uwendel
Date: 2008-03-07 15:01:10 +0100 (Fri, 07 Mar 2008)
New Revision: 1325
Added:
trunk/tests/ext/pdo/pdo_stmt_fetchcolumn.phpt
Log:
This is no real PDO function: it does what its supposed to do...
Added: trunk/tests/ext/pdo/pdo_stmt_fetchcolumn.phpt
===================================================================
--- trunk/tests/ext/pdo/pdo_stmt_fetchcolumn.phpt (rev 0)
+++ trunk/tests/ext/pdo/pdo_stmt_fetchcolumn.phpt 2008-03-07 14:01:10 UTC (rev 1325)
@@ -0,0 +1,124 @@
+--TEST--
+PDO Common: PDOStatement->fetchColumn()
+--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,grp VARCHAR(10), val
VARCHAR(10))');
+$db->exec('INSERT INTO test(id, grp, val) VALUES(5, "A", "5-A")');
+$db->exec('INSERT INTO test(id, grp, val) VALUES(6, "A", "6-A")');
+$db->exec('INSERT INTO test(id, grp, val) VALUES(7, "B", "7-B")');
+
+try {
+
+ // default settings
+ $query = 'SELECT id, grp, val FROM test ORDER BY id ASC';
+ $stmt = $db->prepare($query);
+ $stmt->execute();
+ $expected = $stmt->fetchAll(PDO::FETCH_NUM);
+ var_dump($expected);
+
+ // no more results
+ if (false !== ($tmp = $stmt->fetchColumn()))
+ printf("[002] Expecting false got %s\n", var_export($tmp, true));
+
+ // wrong type
+ $stmt->execute();
+ if (false !== ($tmp = @$stmt->fetchColumn(array())))
+ printf("[003] Expecting false got %s\n", var_export($tmp, true));
+
+ // too many arguments
+ $stmt->execute();
+ if (false !== ($tmp = @$stmt->fetchColumn(1, 1)))
+ printf("[004] Expecting false got %s\n", var_export($tmp, true));
+
+ // invalid offset
+ $stmt->execute();
+ if (NULL !== ($tmp = $stmt->fetchColumn(-1)))
+ printf("[005] Expecting NULL got %s\n", var_export($tmp, true));
+
+ $stmt->execute();
+ if (NULL !== ($tmp = $stmt->fetchColumn(3)))
+ printf("[006] Expecting NULL got %s\n", var_export($tmp, true));
+
+ $stmt->execute();
+ // row 1, column 0
+ $column = $stmt->fetchColumn();
+ if ($column !== $expected[0][0])
+ printf("[007] Expecting %s got %s\n",
+ var_export($expected[0][0], true), var_export($column, true));
+
+ for ($col = 0; $col < 3; $col++) {
+ $stmt->execute();
+ for ($row = 0; $row < 3; $row++) {
+ $column = $stmt->fetchColumn($col);
+ if ($column !== $expected[$row][$col])
+ printf("[008] Row %d, Column %d, Expecting %s got %s\n",
+ $row, $col,
+ var_export($expected[$row][$col], true), var_export($column, true));
+ }
+ }
+
+
+ // ... what about NULL ?
+ $db->exec('DELETE FROM test');
+ $db->exec('INSERT INTO test(id) VALUES (1)');
+ $stmt = $db->prepare('SELECT id, val FROM test ORDER BY id ASC');
+
+ $stmt->execute();
+ var_dump($stmt->fetchColumn(0));
+
+ $stmt->execute();
+ var_dump($stmt->fetchColumn(1));
+
+
+} catch (PDOException $e) {
+ // we should never get here, we use warnings, but never trust a system...
+ printf("[001] %s, [%s} %s\n",
+ $e->getMessage(), $db->errorInfo(), implode(' ', $db->errorInfo()));
+}
+print "done!";
+?>
+--EXPECTF--
+array(3) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(1) "5"
+ [1]=>
+ string(1) "A"
+ [2]=>
+ string(3) "5-A"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(1) "6"
+ [1]=>
+ string(1) "A"
+ [2]=>
+ string(3) "6-A"
+ }
+ [2]=>
+ array(3) {
+ [0]=>
+ string(1) "7"
+ [1]=>
+ string(1) "B"
+ [2]=>
+ string(3) "7-B"
+ }
+}
+string(1) "1"
+NULL
+done!
\ No newline at end of file
| Thread |
|---|
| • PHP mysqlnd svn commit: r1325 - trunk/tests/ext/pdo | uwendel | 7 Mar |