Annotation of embedaddon/php/ext/mysql/tests/mysql_field_flags.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: mysql_field_flags()
                      3: --SKIPIF--
                      4: <?php
                      5: require_once('skipif.inc');
                      6: require_once('skipifconnectfailure.inc');
                      7: ?>
                      8: --FILE--
                      9: <?php
                     10: include "connect.inc";
                     11: 
                     12: $tmp    = NULL;
                     13: $link   = NULL;
                     14: 
                     15: if (!is_null($tmp = @mysql_field_flags()))
                     16:        printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
                     17: 
                     18: if (null !== ($tmp = @mysql_field_flags($link)))
                     19:        printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
                     20: 
                     21: require('table.inc');
                     22: if (!$res = mysql_query("SELECT id, label FROM test ORDER BY id LIMIT 2", $link)) {
                     23:        printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
                     24: }
                     25: 
                     26: if (NULL !== ($tmp = mysql_field_flags($res)))
                     27:        printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
                     28: 
                     29: if (false !== ($tmp = mysql_field_flags($res, -1)))
                     30:        printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
                     31: 
                     32: if (!is_string($tmp = mysql_field_flags($res, 0)) || empty($tmp))
                     33:        printf("[006] Expecting non empty string, got %s/%s\n", gettype($tmp), $tmp);
                     34: 
                     35: if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp)) {
                     36:        printf("[007] Check the unicode support!\n");
                     37:        var_inspect($tmp);
                     38: }
                     39: 
                     40: if (false !== ($tmp = mysql_field_flags($res, 2)))
                     41:        printf("[008] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
                     42: 
                     43: mysql_free_result($res);
                     44: 
                     45: $version = mysql_get_server_info($link);
                     46: if (!preg_match('@(\d+)\.(\d+)\.(\d+)@ism', $version, $matches))
                     47:        printf("[009] Cannot get server version\n");
                     48: $version = ($matches[1] * 100) + ($matches[2] * 10) + $matches[3];
                     49: 
                     50: $tables = array(
                     51:        'label INT, UNIQUE KEY (label)'                         =>  array(
                     52:                                                                array('label', '1'),
                     53:                                                                'label' => array(($version < 500) ? 'multiple_key' : 'unique_key')
                     54:                                                                ),
                     55:        'labela INT, label2 CHAR(1), KEY keyname (labela, label2)'      =>  array(
                     56:                                                                array('labela, label2', "1, 'a'"),
                     57:                                                                'labela' => array('multiple_key'),
                     58:                                                                ),
                     59:        'label1 BLOB'                                           =>  array(
                     60:                                                                array('label1', "'blob'"),
                     61:                                                                'label1' => array('blob', 'binary'),
                     62:                                                                ),
                     63:        'label1 INT UNSIGNED'                                   =>  array(
                     64:                                                                array('label1', '100'),
                     65:                                                                'label1' => array('unsigned'),
                     66:                                                                ),
                     67:        'label1 INT UNSIGNED NOT NULL AUTO INCREMENT'           =>  array(
                     68:                                                                array('label1', '100'),
                     69:                                                                'label1' => array('auto_increment',
                     70:                                                                                'unsigned'),
                     71:                                                                ),
                     72:        'label1 ENUM("a", "b")'                                 =>  array(
                     73:                                                                array('label1', "'a'"),
                     74:                                                                'label1' => array('enum'),
                     75:                                                                ),
                     76:        'label1 SET("a", "b")'                                  =>  array(
                     77:                                                                array('label1', "'a'"),
                     78:                                                                'label1' => array('set'),
                     79:                                                                ),
                     80:        'label1 TIMESTAMP'                                      =>  array(
                     81:                                                                array('label1', sprintf("'%s'", @date("Y-m-d H:i:s"))),
                     82:                                                                'label1' => array(
                     83:                                                                                'timestamp',
                     84:                                                                                'binary',
                     85:                                                                                'not_null'),
                     86:                                                                ),
                     87: );
                     88: 
1.1.1.2 ! misho      89: if ($version < 560) {
        !            90:        $tables['label1 TIMESTAMP']['label1'][] = 'zerofill';
        !            91:        $tables['label1 TIMESTAMP']['label1'][] = 'unsigned';
        !            92: }
        !            93: 
        !            94: 
1.1       misho      95: foreach ($tables as $columns => $expected) {
                     96:        if (!mysql_query("DROP TABLE IF EXISTS test", $link)) {
                     97:                printf("[010/%s] [%d] %s\n", $columns, mysql_errno($link), mysql_error($link));
                     98:                continue;
                     99:        }
                    100:        $sql = sprintf("CREATE TABLE test(id INT, %s) ENGINE = %s", $columns, $engine);
                    101:                if (!@mysql_query($sql, $link)) {
                    102:                // server or engine might not support this
                    103:                continue;
                    104:        }
                    105: 
                    106:        reset($expected);
                    107:        list($k, $values) = each($expected);
                    108:        $sql = sprintf("INSERT INTO test(id, %s) VALUES (1, %s)", $values[0], $values[1]);
                    109:        if (!mysql_query($sql, $link)) {
                    110:                printf("[011/%s] '%s', [%d] %s\n", $columns, $sql, mysql_errno($link), mysql_error($link));
                    111:                continue;
                    112:        }
                    113: 
                    114:        if (!$res = mysql_query(sprintf("SELECT id, %s FROM test", $values[0]), $link)) {
                    115:                printf("[012/%s] [%d] %s\n", $columns, mysql_errno($link), mysql_error($link));
                    116:                continue;
                    117:        }
                    118: 
                    119:        $i = 1;
                    120:        while (list($field, $flags) = each($expected)) {
                    121:                $tmp = mysql_field_flags($res, $i++);
                    122: 
                    123:                foreach ($flags as $k => $flag) {
                    124:                if (!preg_match(sprintf('@\s*%s\s*@ismU', $flag), $tmp)) {
                    125:                        printf("[013/%s] Field '%s', flag '%s' not found, [%d] %s\n", $columns, $field, $flag, mysql_errno($link), mysql_error($link));
                    126:                }
                    127:        }
                    128:                foreach ($flags as $k => $flag) {
                    129:                        $tmp = preg_replace(sprintf('@\s*%s\s*@ismU', $flag), '', $tmp);
                    130:                }
                    131:                if ('' != $tmp)
                    132:                        printf("[014/%s] Field '%s', unexpected flags '%s' found, [%d] %s\n", $columns, $field, $tmp, mysql_errno($link), mysql_error($link));
                    133:        }
                    134:        mysql_free_result($res);
                    135: }
                    136: 
                    137: var_dump(mysql_field_flags($res, 0));
                    138: 
                    139: mysql_close($link);
                    140: print "done!";
                    141: ?>
                    142: --CLEAN--
                    143: <?php
                    144: require_once("clean_table.inc");
                    145: ?>
                    146: --EXPECTF--
                    147: Warning: mysql_field_flags() expects exactly 2 parameters, 1 given in %s on line %d
                    148: 
                    149: Warning: mysql_field_flags(): Field -1 is invalid for MySQL result index %d in %s on line %d
                    150: 
                    151: Warning: mysql_field_flags(): Field 2 is invalid for MySQL result index %d in %s on line %d
                    152: 
                    153: Warning: mysql_field_flags(): %d is not a valid MySQL result resource in %s on line %d
                    154: bool(false)
                    155: done!

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>