From: Ulf Wendel Date: Wed, 11 Jul 2007 14:11:18 +0000 (+0000) Subject: Whitespace/Coding Standards, removal of skipifemb.inc, improved testing X-Git-Tag: BEFORE_IMPORT_OF_MYSQLND~229 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4ec515c660d4c88ec559153f6e8da16ec16c44f8;p=php Whitespace/Coding Standards, removal of skipifemb.inc, improved testing and checking for expected field types. --- diff --git a/ext/mysql/tests/mysql_field_flags.phpt b/ext/mysql/tests/mysql_field_flags.phpt index b2f2deeda0..3595ba0500 100644 --- a/ext/mysql/tests/mysql_field_flags.phpt +++ b/ext/mysql/tests/mysql_field_flags.phpt @@ -2,48 +2,135 @@ mysql_field_flags() --SKIPIF-- - --FILE-- array( + array('label', '1'), + 'label' => array(($version < 500) ? 'multiple_key' : 'unique_key') + ), + 'labela INT, label2 CHAR(1), KEY keyname (labela, label2)' => array( + array('labela, label2', '1, "a"'), + 'labela' => array('multiple_key'), + ), + 'label1 BLOB' => array( + array('label1', '"blob"'), + 'label1' => array('blob', 'binary'), + ), + 'label1 INT UNSIGNED' => array( + array('label1', '100'), + 'label1' => array('unsigned'), + ), + 'label1 INT UNSIGNED NOT NULL AUTO INCREMENT' => array( + array('label1', '100'), + 'label1' => array('auto_increment', + 'unsigned'), + ), + 'label1 ENUM("a", "b")' => array( + array('label1', '"a"'), + 'label1' => array('enum'), + ), + 'label1 SET("a", "b")' => array( + array('label1', '"a"'), + 'label1' => array('set'), + ), + 'label1 TIMESTAMP' => array( + array('label1', sprintf('"%s"', @date("Y-m-d H:i:s"))), + 'label1' => array( + 'timestamp', + 'unsigned', + 'zerofill', + 'binary', + 'not_null'), + ), +); + +foreach ($tables as $columns => $expected) { + if (!mysql_query("DROP TABLE IF EXISTS test", $link)) { + printf("[010/%s] [%d] %s\n", $columns, mysql_errno($link), mysql_error($link)); + continue; + } + $sql = sprintf("CREATE TABLE test(id INT, %s) ENGINE = %s", $columns, $engine); + if (!@mysql_query($sql, $link)) { + // server or engine might not support this + continue; + } + + reset($expected); + list($k, $values) = each($expected); + $sql = sprintf("INSERT INTO test(id, %s) VALUES (1, %s)", $values[0], $values[1]); + if (!mysql_query($sql, $link)) { + printf("[011/%s] '%s', [%d] %s\n", $columns, $sql, mysql_errno($link), mysql_error($link)); + continue; + } + + if (!$res = mysql_query(sprintf("SELECT id, %s FROM test", $values[0]), $link)) { + printf("[012/%s] [%d] %s\n", $columns, mysql_errno($link), mysql_error($link)); + continue; + } + + $i = 1; + while (list($field, $flags) = each($expected)) { + $tmp = mysql_field_flags($res, $i++); + + foreach ($flags as $k => $flag) { + if (!preg_match(sprintf('@\s*%s\s*@ismU', $flag), $tmp)) { + printf("[013/%s] Field '%s', flag '%s' not found, [%d] %s\n", $columns, $field, $flag, mysql_errno($link), mysql_error($link)); + } + } + foreach ($flags as $k => $flag) { + $tmp = preg_replace(sprintf('@\s*%s\s*@ismU', $flag), '', $tmp); + } + if ('' != $tmp) + printf("[014/%s] Field '%s', unexpected flags '%s' found, [%d] %s\n", $columns, $field, $tmp, mysql_errno($link), mysql_error($link)); + } + mysql_free_result($res); +} + +var_dump(mysql_field_flags($res, 0)); + +mysql_close($link); +print "done!"; ?> --EXPECTF-- Warning: Wrong parameter count for mysql_field_flags() in %s on line %d @@ -54,4 +141,4 @@ Warning: mysql_field_flags(): Field 2 is invalid for MySQL result index %d in %s Warning: mysql_field_flags(): %d is not a valid MySQL result resource in %s on line %d bool(false) -done! +done! \ No newline at end of file