uw Wed Jul 11 15:26:08 2007 UTC Modified files: /php-src/ext/mysql/tests mysql_fetch_field.phpt Log: Whitespace and more testing. http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/mysql_fetch_field.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/mysql/tests/mysql_fetch_field.phpt diff -u php-src/ext/mysql/tests/mysql_fetch_field.phpt:1.1 php-src/ext/mysql/tests/mysql_fetch_field.phpt:1.2 --- php-src/ext/mysql/tests/mysql_fetch_field.phpt:1.1 Sun Nov 19 12:14:44 2006 +++ php-src/ext/mysql/tests/mysql_fetch_field.phpt Wed Jul 11 15:26:07 2007 @@ -2,7 +2,6 @@ mysql_fetch_field() --SKIPIF-- <?php require_once('skipif.inc'); ?> -<?php require_once('skipifemb.inc'); ?> --FILE-- <?php include "connect.inc"; @@ -18,8 +17,15 @@ printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); require('table.inc'); + + + $version = mysql_get_server_info($link); + if (!preg_match('@(\d+)\.(\d+)\.(\d+)@ism', $version, $matches)) + printf("[003] Cannot get server version\n"); + $version = ($matches[1] * 100) + ($matches[2] * 10) + $matches[3]; + if (!$res = mysql_query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1", $link)) { - printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link)); + printf("[004] [%d] %s\n", mysql_errno($link), mysql_error($link)); } while ($tmp = mysql_fetch_field($res)) @@ -28,8 +34,73 @@ mysql_free_result($res); + if (!$res = mysql_query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1", $link)) { + printf("[005] [%d] %s\n", mysql_errno($link), mysql_error($link)); + } + if (false !== ($tmp = mysql_fetch_field($res, PHP_INT_MAX * 2))) + printf("[006] Expecting boolean/false got %s/%s\n", gettype($tmp), $tmp); + + mysql_free_result($res); + if (false !== ($tmp = mysql_fetch_field($res))) - printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + printf("[007] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + + $types = array( + 'BIT' => array(1, 'int'), + 'TINYINT' => array(1, 'int'), + 'BOOL' => array('true', 'int'), + 'SMALLINT' => array(32767, 'int'), + 'MEDIUMINT' => array(8388607, 'int'), + 'INT' => array(100, 'int'), + 'BIGINT' => array(100, 'int'), + 'FLOAT' => array(100, 'real'), + 'DOUBLE' => array(100, 'real'), + 'DECIMAL' => array(100, 'real'), + 'DATE' => array(@date('Y-m-d'), 'date'), + 'DATETIME' => array(@date('Y-m-d H:i:s'), 'datetime'), + 'TIMESTAMP' => array(@date('Y-m-d H:i:s'), 'timestamp'), + 'TIME' => array(@date('H:i:s'), 'time'), + 'YEAR' => array(@date('Y'), 'year'), + 'CHAR(1)' => array('a', 'string'), + 'VARCHAR(1)' => array('a', 'string'), + 'BINARY(1)' => array('a', 'string'), + 'VARBINARY(1)' => array('a', 'string'), + 'TINYBLOB' => array('a', 'blob'), + 'TINYTEXT' => array('a', 'blob'), + 'BLOB' => array('a', 'blob'), + 'TEXT' => array('a', 'blob'), + 'MEDIUMBLOB' => array('a', 'blob'), + 'MEDIUMTEXT' => array('a', 'blob'), + 'LONGBLOB' => array('a', 'blob'), + 'LONGTEXT' => array('a', 'blob'), + 'ENUM("a", "b")' => array('a', 'string'), /* !!! */ + 'SET("a", "b")' => array('a', 'string'), /* !!! */ + ); + + foreach ($types as $type_name => $type_desc) { + if (!mysql_query("DROP TABLE IF EXISTS test", $link)) + printf("[008/%s] [%d] %s\n", $type_name, mysql_errno($link), mysql_error($link)); + if (!mysql_query(sprintf("CREATE TABLE test(id INT, label %s) ENGINE = %s", $type_name, $engine), $link)) { + // server and/or engine might not support the data type + continue; + } + if (!mysql_query(sprintf("INSERT INTO test(id, label) VALUES (1, '%s')", $type_desc[0]), $link)) { + printf("[009/%s] [%d] %s\n", $type_name, mysql_errno($link), mysql_error($link)); + continue; + } + if (!$res = mysql_query("SELECT id, label FROM test", $link)) { + printf("[010/%s] [%d] %s\n", $type_name, mysql_errno($link), mysql_error($link)); + continue; + } + if (!$tmp = mysql_fetch_field($res, 1)) { + printf("[011/%s] [%d] %s\n", $type_name, mysql_errno($link), mysql_error($link)); + } + + if ($type_desc[1] != $tmp->type) { + printf("[012/%s] Expecting type '%s' got '%s'\n", $type_name, $type_desc[1], $tmp->type); + } + mysql_free_result($res); + } mysql_close($link); print "done!"; @@ -93,6 +164,8 @@ } bool(false) +Warning: mysql_fetch_field(): Bad field offset in %s on line %d + Warning: mysql_fetch_field(): %d is not a valid MySQL result resource in %s on line %d done! --UEXPECTF-- @@ -154,5 +227,7 @@ } bool(false) +Warning: mysql_fetch_field(): Bad field offset in %s on line %d + Warning: mysql_fetch_field(): %d is not a valid MySQL result resource in %s on line %d done!
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php