Author: uwendel
Date: 2007-10-22 15:18:41 +0200 (Mon, 22 Oct 2007)
New Revision: 1124
Added:
trunk/tests/ext/pdo/pdo_get_attribute.phpt
Log:
Check the code comments and its TODO entries to
smile about the PDO documentation...
Added: trunk/tests/ext/pdo/pdo_get_attribute.phpt
===================================================================
--- trunk/tests/ext/pdo/pdo_get_attribute.phpt 2007-10-22 11:52:12 UTC (rev 1123)
+++ trunk/tests/ext/pdo/pdo_get_attribute.phpt 2007-10-22 13:18:41 UTC (rev 1124)
@@ -0,0 +1,206 @@
+--TEST--
+PDO Common: PDO->getAttribute()
+--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();
+
+if (false !== ($tmp = @$db->getAttribute()))
+ printf("[001] Expecting false got %s/%s\n", $tmp, gettype($tmp));
+
+if (false !== ($tmp = @$db->getAttribute(array())))
+ printf("[002] Expecting false got %s/%s\n", $tmp, gettype($tmp));
+
+if (false !== ($tmp = @$db->getAttribute(-1, -1)))
+ printf("[003] Expecting false got %s/%s\n", $tmp, gettype($tmp));
+
+/* type_code refers to 5_3/pdo_dbh.c in 11/2007 */
+/* this list is compiled from the php.net manual + pdo_dbh.c code inspection */
+$attributes = array(
+ /*
+ TODO: manual is wrong, not all drivers support this (Postgres)
+ 'PDO::ATTR_AUTOCOMMIT' =>
+ array(
+ 'const' => PDO::ATTR_AUTOCOMMIT,
+ 'type_manual' => 'integer',
+ 'type_code' => null,
+ ),
+ */
+ 'PDO::ATTR_CASE' =>
+ array(
+ 'const' => PDO::ATTR_CASE,
+ 'type_manual' => 'integer',
+ 'type_code' => 'integer',
+ ),
+ 'PDO::ATTR_CLIENT_VERSION' =>
+ array(
+ 'const' => PDO::ATTR_CLIENT_VERSION,
+ 'type_manual' => 'integer',
+ 'type_code' => null,
+ ),
+ /*
+ TODO: manual is wrong - not all drivers support it (SQLite)
+ 'PDO::ATTR_CONNECTION_STATUS' =>
+ array(
+ 'const' => PDO::ATTR_CONNECTION_STATUS,
+ 'type_manual' => 'integer',
+ 'type_code' => null
+ ),
+ */
+ 'PDO::ATTR_DRIVER_NAME' =>
+ array(
+ 'const' => PDO::ATTR_DRIVER_NAME,
+ 'type_manual' => 'string',
+ 'type_code' => 'string',
+ ),
+ 'PDO::ATTR_ERRMODE' =>
+ array(
+ 'const' => PDO::ATTR_ERRMODE,
+ 'type_manual' => 'integer',
+ 'type_code' => 'integer',
+ ),
+ 'PDO::ATTR_ORACLE_NULLS' =>
+ array(
+ 'const' => PDO::ATTR_ORACLE_NULLS,
+ 'type_manual' => 'integer',
+ 'type_code' => 'integer',
+ ),
+ 'PDO::ATTR_PERSISTENT' =>
+ array(
+ 'const' => PDO::ATTR_PERSISTENT,
+ 'type_manual' => 'integer',
+ 'type_code' => 'boolean',
+ ),
+ /*
+ TODO: manual is wrong - not all drivers support it (MySQL)
+ 'PDO::ATTR_PREFETCH' =>
+ array(
+ 'const' => PDO::ATTR_PREFETCH,
+ 'type_manual' => 'integer',
+ 'type_code' => null,
+ ),
+ */
+ /*
+ TODO: manual is wrong - not all drivers support it (SQLite)
+ 'PDO::ATTR_SERVER_INFO' =>
+ array(
+ 'const' => PDO::ATTR_SERVER_INFO,
+ 'type_manual' => 'integer',
+ 'type_code' => null,
+ ),
+ */
+ 'PDO::ATTR_SERVER_VERSION' =>
+ array(
+ 'const' => PDO::ATTR_SERVER_VERSION,
+ 'type_manual' => 'integer',
+ 'type_code' => null,
+ ),
+ /*
+ TODO: manual is wrong - not all drivers support it (MySQL)
+ 'PDO::ATTR_TIMEOUT' =>
+ array(
+ 'const' => PDO::ATTR_TIMEOUT,
+ 'type_manual' => 'integer',
+ 'type_code' => null,
+ ),
+ */
+ /* not in the manual but in pdo_dbh.c */
+ 'PDO::ATTR_STATEMENT_CLASS' =>
+ array(
+ 'const' => PDO::ATTR_STATEMENT_CLASS,
+ 'type_manual' => 'integer',
+ 'type_code' => 'array',
+ ),
+
+);
+
+if (version_compare(PHP_VERSION, '5.2.0', '>='))
+ $attributes['PDO::ATTR_DEFAULT_FETCH_MODE'] =
+ array(
+ 'const' => PDO::ATTR_DEFAULT_FETCH_MODE,
+ 'type_manual' => 'integer',
+ 'type_code' => 'integer',
+ );
+
+ /*
+ Manual also mentions:
+
+ PDO::ATTR_CURSOR_NAME (integer)
+ Get or set the name to use for a cursor. Most useful when using scrollable cursors
and positioned updates.
+ PDO::ATTR_CURSOR (integer)
+ Selects the cursor type. PDO currently supports either PDO::CURSOR_FWDONLY and
PDO::CURSOR_SCROLL. Stick with PDO::CURSOR_FWDONLY unless you know that you need a
scrollable cursor.
+ PDO::ATTR_STATEMENT_CLASS (integer)
+ PDO::ATTR_FETCH_CATALOG_NAMES (integer)
+ Prepend the containing catalog name to each column name returned in the result set.
The catalog name and column name are separated by a decimal (.) character. Support of
this attribute is at the driver level; it may not be supported by your driver.
+ PDO::ATTR_FETCH_TABLE_NAMES (integer)
+ Prepend the containing table name to each column name returned in the result set. The
table name and column name are separated by a decimal (.) character. Support of this
attribute is at the driver level; it may not be supported by your driver.
+ PDO::ATTR_STRINGIFY_FETCHES (integer)
+ PDO::ATTR_MAX_COLUMN_LEN (integer)
+ PDO::ATTR_DEFAULT_FETCH_MODE (integer)
+ Available since PHP 5.2.0
+ PDO::ATTR_EMULATE_PREPARES (integer)
+ Available since PHP 5.1.3.
+*/
+
+$tmp = array();
+foreach ($attributes as $name => $attribute) {
+ if (!isset($tmp[$attribute['const']]))
+ $tmp[$attribute['const']] = array($name);
+ else
+ $tmp[$attribute['const']][] = $name;
+}
+foreach ($tmp as $const => $duplicates)
+ if (count($duplicates) > 1) {
+ printf("[004] Several constants share the value '%s', dumping list\n", $const);
+ var_dump($duplicates);
+ }
+
+try {
+
+ foreach ($attributes as $name => $attribute) {
+ printf("PDO::getAttribute(%s)\n", $name);
+ $setting = $db->getAttribute($attribute['const']);
+
+ $type = gettype($setting);
+ switch ($type) {
+ case 'int':
+ $type = 'integer';
+ break;
+ case 'bool':
+ $type = 'boolean';
+ break;
+ default:
+ break;
+ }
+
+ if ($type != $attribute['type_manual']) {
+ printf("[005] According to the manual PDO::getAttribute(%s) should return a value of
type '%s' found type '%s'\n",
+ $name, $attribute['type_manual'], $type);
+ }
+
+ if (!is_null($attribute['type_code']) && ($type != $attribute['type_code'])) {
+ printf("[006] According to the code PDO::getAttribute(%s) should return a value of
type '%s' found type '%s'\n",
+ $name, $attribute['type_code'], $type);
+ }
+ }
+
+} catch (PDOException $e) {
+ printf("[007] %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: r1124 - trunk/tests/ext/pdo | uwendel | 22 Oct |