Annotation of embedaddon/php/ext/mysqli/tests/mysqli_fetch_field_types.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: mysqli_fetch_field() - data types/field->type
! 3: --SKIPIF--
! 4: <?php
! 5: require_once('skipif.inc');
! 6: require_once('skipifemb.inc');
! 7: require_once('skipifconnectfailure.inc');
! 8: ?>
! 9: --FILE--
! 10: <?php
! 11: require('table.inc');
! 12:
! 13: function mysqli_field_datatypes($link, $sql_type, $php_value, $php_type, $datatypes, $default_charset="latin1") {
! 14: if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
! 15: printf("[001] %s, [%d] %s\n", $sql_type,
! 16: mysqli_errno($link), mysqli_error($link));
! 17: return false;
! 18: }
! 19:
! 20: $create = sprintf("CREATE TABLE test(id %s) DEFAULT CHARSET %s", $sql_type, $default_charset);
! 21: if (!mysqli_query($link, $create)) {
! 22: printf("[002] '%s' - '%s', [%d] %s\n", $sql_type, $create,
! 23: mysqli_errno($link), mysqli_error($link));
! 24: return false;
! 25: }
! 26:
! 27: if (is_string($php_value))
! 28: $sql = sprintf("INSERT INTO test(id) VALUES ('%s')", $php_value);
! 29: else
! 30: $sql = sprintf("INSERT INTO test(id) VALUES (%s)", $php_value);
! 31:
! 32: if (!mysqli_query($link, $sql)) {
! 33: printf("[003] '%s' - '%s' - '%s', [%d] %s\n", $sql_type, $create, $sql,
! 34: mysqli_errno($link), mysqli_error($link));
! 35: return false;
! 36: }
! 37:
! 38: if (!$res = mysqli_query($link, 'SELECT id FROM test')) {
! 39: printf("[004] %s, [%d] %s\n", $sql_type,
! 40: mysqli_errno($link), mysqli_error($link));
! 41: return false;
! 42: }
! 43:
! 44: if (!is_object($field = mysqli_fetch_field($res))) {
! 45: printf("[004] %s, expecting object got %s, [%d] %s\n", $sql_type,
! 46: gettype($field),
! 47: mysqli_errno($link), mysqli_error($link));
! 48: return false;
! 49: }
! 50:
! 51: if ($field->type != $php_type) {
! 52: $code_name = 'unknown';
! 53: foreach ($datatypes as $k => $v) {
! 54: if ($k == $field->type) {
! 55: $code_name = (is_array($v)) ? $v[0] : $v;
! 56: break;
! 57: }
! 58: }
! 59: printf("[006] Expecting %d for %s got code %d for %s\n",
! 60: $php_type, $sql_type, $field->type, $code_name);
! 61: return false;
! 62: }
! 63:
! 64: return true;
! 65: }
! 66:
! 67: $datatypes = array(
! 68: MYSQLI_TYPE_TINY => array('TINYINT', 5),
! 69: MYSQLI_TYPE_SHORT => array('SMALLINT', 10),
! 70: MYSQLI_TYPE_LONG => 'MYSQLI_TYPE_LONG - TODO add testing',
! 71: MYSQLI_TYPE_FLOAT => array('FLOAT', '1.3'),
! 72: MYSQLI_TYPE_DOUBLE => array('DOUBLE', '1.4'),
! 73: MYSQLI_TYPE_TIMESTAMP => array('TIMESTAMP', '2007-08-20 18:34:00'),
! 74: MYSQLI_TYPE_LONGLONG => array('BIGINT', 100),
! 75: MYSQLI_TYPE_INT24 => array('MEDIUMINT', 10),
! 76: MYSQLI_TYPE_DATE => array('DATE', '2007-08-20'),
! 77: MYSQLI_TYPE_TIME => array('TIME', '18:41:38'),
! 78: MYSQLI_TYPE_DATETIME => array('DATETIME', '2007-08-20 18:42:01'),
! 79: MYSQLI_TYPE_YEAR => array('YEAR', '2007'),
! 80: MYSQLI_TYPE_ENUM => array('ENUM("everything", "is", "just", "wonderful")', 'is'),
! 81: // MYSQLI_TYPE_SET => array('SET("I", "smash", "the")', 'I,smash,the'), - string
! 82: // MYSQLI_TYPE_TINY_BLOB => array("TINYBLOB", "I got a tiny blog"), - blob
! 83: // MYSQLI_TYPE_MEDIUM_BLOB => array("MEDIUMBLOB", "No blob for masses"), - blob
! 84: // MYSQLI_TYPE_LONG_BLOB => array("LONGBLOB", "Small is beautiful?"), - blob
! 85: MYSQLI_TYPE_BLOB => array("LONGBLOB", 'MySQL does not report proper type. Use Length to distinct BLOB types'),
! 86: MYSQLI_TYPE_BLOB => array("MEDIUMBLOB", 'MySQL does not report proper type. Use Length to distinct BLOB types'),
! 87: MYSQLI_TYPE_BLOB => array("TINYBLOB", 'MySQL does not report proper type. Use Length to distinct BLOB types'),
! 88: MYSQLI_TYPE_BLOB => array("BLOB", 'silly'),
! 89: MYSQLI_TYPE_VAR_STRING => array("VARCHAR(32768)", 'varchar'),
! 90: MYSQLI_TYPE_STRING => 'MYSQLI_TYPE_STRING - TODO add testing',
! 91: MYSQLI_TYPE_STRING => array('CHAR(1)', 'a'),
! 92: MYSQLI_TYPE_STRING => array("SET('I', 'smash', 'the')", 'smash'),
! 93: MYSQLI_TYPE_NULL => 'MYSQLI_TYPE_NULL - TODO add testing',
! 94: MYSQLI_TYPE_NEWDATE => 'MYSQLI_TYPE_NEWDATE - TODO add testing',
! 95: MYSQLI_TYPE_INTERVAL => 'MYSQLI_TYPE_INTERVAL - TODO add testing',
! 96: MYSQLI_TYPE_GEOMETRY => 'MYSQLI_TYPE_GEOMETRY - TODO add testing',
! 97: );
! 98:
! 99: if ($IS_MYSQLND) {
! 100: $version = 50007 + 1;
! 101: } else {
! 102: $version = mysqli_get_client_version();
! 103: }
! 104:
! 105: if ($version > 50002) {
! 106: $datatypes[MYSQLI_TYPE_NEWDECIMAL] = array('DECIMAL', '1.1');
! 107: $datatypes[MYSQLI_TYPE_BIT] = array('BIT', 0);
! 108: } else {
! 109: $datatypes[MYSQLI_TYPE_DECIMAL] = array('DECIMAL', '1.1');
! 110: }
! 111:
! 112: foreach ($datatypes as $php_type => $datatype) {
! 113: if (is_array($datatype))
! 114: mysqli_field_datatypes($link, $datatype[0], $datatype[1], $php_type, $datatypes);
! 115: }
! 116:
! 117: mysqli_close($link);
! 118:
! 119: print "done!";
! 120: ?>
! 121: --CLEAN--
! 122: <?php
! 123: require_once("clean_table.inc");
! 124: ?>
! 125: --EXPECTF--
! 126: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>