16tableinfo.phpt
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHPT 代码 · 共 1,341 行 · 第 1/3 页
PHPT
1,341 行
--TEST--DB_driver::tableInfo--INI--error_reporting = 2047--SKIPIF--<?php/** * Calls tableInfo() in various ways and checks to see that the output * matches what's expected. * * These tests account for each DBMS using different column types and * reporting back different information. These differences are accounted * for in the <var>$quirks</var> array, which has the following format: * * <pre> * 'driver' => array( * 'clob' => DBMS's column type for creating CLOB fields * 'date' => DBMS's column type for creating DATE fields * 'dateliteral' => The SQL keyword necessary for defining dates * 'finds_table' => Can this DBMS determine table names from queries? * 'size_from_table' => Does this DBMS know the column size via table name? * 'handles_results' => Can the DBMS get info from query results? * 'commands' => array( * Extra commands to be passed to PHP's eval() function * ) * 0 => array( * // Info expected to be reported for phptest_fk.a * // (INTEGER NOT NULL) (UNIQUE KEY with d) * 'type' => Column type reported by the DBMS * 'len' => Column size reported by the DBMS * 'flags' => Flags reported by the DBMS * ) * 1 => array() Info expected to be reported for phptest_fk.fk * (INTEGER NOT NULL) (PRIMARY KEY) * 2 => array() Info expected to be reported for phptest_fk.c * (CLOB/CHAR/VARCHAR NULL) * 3 => array() Info expected to be reported for phptest_fk.d * (DATE NOT NULL) (UNIQUE KEY with a) * 4 => array() Info expected to be reported for phptest_fk.e * (CHAR(2) DEFAULT ' e' NOT NULL) * 5 => array() Info expected to be reported for phptest_fk.f * (DECIMAL(2,1) NULL) * 9 => array() Info expected to be reported for phptest.d * (VARCHAR(20) NULL) * ) * </pre> * * @category Database * @package DB * @version $Id: 16tableinfo.phpt,v 1.32 2005/02/14 17:04:17 danielc Exp $ * @author Daniel Convissor <danielc@analysisandsolutions.com> * @see DB_common::tableInfo() */error_reporting(E_ALL);chdir(dirname(__FILE__));require_once './skipif.inc';$tableInfo = $db->tableInfo('ajkdslfajoijkadie');if (DB::isError($tableInfo) && $tableInfo->code == DB_ERROR_NOT_CAPABLE) { die("skip $tableInfo->message");}?>--FILE--<?php// $Id: 16tableinfo.phpt,v 1.32 2005/02/14 17:04:17 danielc Exp $/** * Connect to the database and make the phptest table. */require_once './mktable.inc';/** * Local error callback handler. * * In general, it prints out an error message and kills the process. * But some errors are expected and allowed to exist. * * @param object $o PEAR error object automatically passed to this method * @return void * @see PEAR::setErrorHandling() */function pe($o){ global $dbh, $quirks; if ($o->getMessage() == "DB Error: can't distinguish duplicate field names") { print "NOTICE: $dbh->phptype can't distinguish duplicate field names"; return; } if ($o->getCode() == DB_ERROR_NOT_CAPABLE && !$quirks[$dbh->phptype . ':' . $dbh->dbsyntax]['handles_results']) { return; } $dbh->setErrorHandling(PEAR_ERROR_RETURN); drop_table($dbh, 'phptest'); drop_table($dbh, 'phptest_fk'); die($o->toString());}/** * Loop through an array returned from tableInfo(), compare the actual * contents to the expected contents. If the actual results match the * expectations, say so. If not, say so and show the information. * * @param array $array the array to be examined * @param string $expected the expected contents of the array * @param string $field field index number of $quriks and table * @param boolean $query true if array is from a query or false if array * is tableInfo() * @return void */function examineArrayData($array, $expected, $field = false, $query = true) { global $dbh, $quirks; $quirk_key = $dbh->phptype . ':' . $dbh->dbsyntax; if (DB::isError($array) && $array->getCode() == DB_ERROR_NOT_CAPABLE) { print "matched expected result\n"; return; } if (!is_array($array)) { print "This DMBS didn't produce proper results\n"; return; } if (is_int($field)) { $array = $array[$field]; } $actual = ''; foreach ($array as $key => $value) { if ($field !== false && isset($quirks[$quirk_key][$field][$key])) { if ($key == 'flags' && $value == '' && $query && !$quirks[$quirk_key]['finds_table']) { $actual .= "$key ... matched expected value\n"; } else { if ($quirks[$quirk_key][$field][$key] == $value) { $actual .= "$key ... matched expected value\n"; } else { if ($value == 0 && !$quirks[$quirk_key]['size_from_table']) { $actual .= "$key ... matched expected value\n"; } else { $actual .= "$key ... was '$value' but we expected "; $actual .= "'{$quirks[$quirk_key][$field][$key]}'\n"; } } } } else { if ($key == 'table') { if ($field <= 5) { if ($value == 'phptest_fk') { $actual .= "$key ... matched expected value\n"; } else { if ($value == '' && $query && !$quirks[$quirk_key]['finds_table']) { $actual .= "$key ... matched expected value\n"; } else { $actual .= "$key ... was '$value' but we expected 'phptest_fk'\n"; } } } else { if ($value == 'phptest') { $actual .= "$key ... matched expected value\n"; } else { if ($value == '' && $query && !$quirks[$quirk_key]['finds_table']) { $actual .= "$key ... matched expected value\n"; } else { $actual .= "$key ... was '$value' but we expected 'phptest_fk'\n"; } } } } else { $actual .= "$key => $value\n"; } } } if ($actual == $expected) { print "matched expected result\n"; } else { print "DIDN'T match expected values...\n"; print "~~~~~~~~\nExpected:\n$expected\n"; print "~~~~\nActual:\n$actual\n~~~~~~~~\n\n"; }}/** * Loop through an array of table info data and return the results. * * @param array $array the array to be examined * @return string */function returnArrayData($array) { global $dbh, $quirks; $quirk_key = $dbh->phptype . ':' . $dbh->dbsyntax; if (!$quirks[$quirk_key]['handles_results']) { return "\n"; } $out = ''; foreach ($array as $key => $value) { $out .= "$key => $value\n"; } return $out;}$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');$quirks = array( 'fbsql:fbsql' => array( 'clob' => 'CHAR(29)', 'date' => 'DATE', 'dateliteral' => ' DATE ', 'finds_table' => false, 'size_from_table' => false, 'handles_results' => true, 'commands' => array( ), 0 => array( 'type' => 'INTEGER', 'len' => 0, 'flags' => '', ), 1 => array( 'type' => 'INTEGER', 'len' => 0, 'flags' => 'not_null', ), 2 => array( 'type' => 'CHARACTER', 'len' => 29, 'flags' => '', ), 3 => array( 'type' => 'DATE', 'len' => 0, 'flags' => '', ), 4 => array( 'type' => 'CHARACTER', 'len' => 2, 'flags' => '', ), 5 => array( 'type' => 'DECIMAL', 'len' => 0, 'flags' => '', ), 9 => array( 'type' => 'CHARACTER', 'len' => 20, 'flags' => '', ), ), 'ibase:ibase' => array( 'clob' => 'VARCHAR(50)', 'date' => 'DATE', 'dateliteral' => '', 'finds_table' => false, 'size_from_table' => false, 'handles_results' => true, 'commands' => array( ), 0 => array( 'type' => 'INTEGER', 'len' => 4, 'flags' => 'unique_key not_null', ), 1 => array( 'type' => 'INTEGER', 'len' => 4, 'flags' => 'primary_key not_null', ), 2 => array( 'type' => 'VARCHAR', 'len' => 50, 'flags' => '', ), 3 => array( 'type' => 'DATE', 'len' => 4, 'flags' => 'unique_key not_null', ), 4 => array( 'type' => 'CHAR', 'len' => 2, 'flags' => 'not_null default', ), 5 => array( 'type' => 'NUMERIC(9,1)', 'len' => 4, 'flags' => '', ), 9 => array( 'type' => 'VARCHAR', 'len' => 20, 'flags' => '', ), ), 'ibase:firebird' => array( 'clob' => 'VARCHAR(50)', 'date' => 'DATE', 'dateliteral' => '', 'finds_table' => false, 'size_from_table' => false, 'handles_results' => true, 'commands' => array( ), 0 => array( 'type' => 'INTEGER', 'len' => 4, 'flags' => 'unique_key not_null', ), 1 => array( 'type' => 'INTEGER', 'len' => 4, 'flags' => 'primary_key not_null', ), 2 => array( 'type' => 'VARCHAR', 'len' => 50, 'flags' => '', ), 3 => array( 'type' => 'DATE', 'len' => 4, 'flags' => 'unique_key not_null', ), 4 => array( 'type' => 'CHAR', 'len' => 2, 'flags' => 'not_null default', ), 5 => array( 'type' => 'NUMERIC(9,1)', 'len' => 4, 'flags' => '', ), 9 => array( 'type' => 'VARCHAR', 'len' => 20, 'flags' => '', ), ), 'ifx:ifx' => array( 'clob' => 'CHAR(29)', 'date' => 'CHAR(10)', 'dateliteral' => '', 'finds_table' => false, 'size_from_table' => false, 'handles_results' => true, 'commands' => array( ), 0 => array( 'type' => 'SQLINT', 'len' => 4, 'flags' => 'not_null', ), 1 => array( 'type' => 'SQLINT', 'len' => 4, 'flags' => 'not_null', ), 2 => array( 'type' => 'SQLCHAR', 'len' => 29, 'flags' => '', ), 3 => array( 'type' => 'SQLCHAR', 'len' => 10, 'flags' => 'not_null', ), 4 => array( 'type' => 'SQLCHAR', 'len' => 2, 'flags' => 'not_null', ), 5 => array( 'type' => 'SQLDECIMAL', 'len' => 513, 'flags' => '', ), 9 => array( 'type' => 'SQLCHAR', 'len' => 20, 'flags' => '', ), ), 'msql:msql' => array( 'clob' => 'TEXT(255)', 'date' => 'CHAR(10)', 'dateliteral' => '', 'finds_table' => true, 'size_from_table' => true, 'handles_results' => true, 'commands' => array( ), 0 => array( 'type' => 'int', 'len' => 4, 'flags' => 'not_null', ), 1 => array( 'type' => 'int', 'len' => 4, // for some reason, the unique property always contains 0 // 'flags' => 'unique_key not_null', 'flags' => 'not_null', ), 2 => array( 'type' => 'text', 'len' => 255, 'flags' => '', ), 3 => array( 'type' => 'char', 'len' => 10, 'flags' => 'not_null', ), 4 => array( 'type' => 'char', 'len' => 2, 'flags' => 'not_null', ),
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?