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

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:                                                                                'unsigned',
        !            85:                                                                                'zerofill',
        !            86:                                                                                'binary',
        !            87:                                                                                'not_null'),
        !            88:                                                                ),
        !            89: );
        !            90: 
        !            91: foreach ($tables as $columns => $expected) {
        !            92:        if (!mysql_query("DROP TABLE IF EXISTS test", $link)) {
        !            93:                printf("[010/%s] [%d] %s\n", $columns, mysql_errno($link), mysql_error($link));
        !            94:                continue;
        !            95:        }
        !            96:        $sql = sprintf("CREATE TABLE test(id INT, %s) ENGINE = %s", $columns, $engine);
        !            97:                if (!@mysql_query($sql, $link)) {
        !            98:                // server or engine might not support this
        !            99:                continue;
        !           100:        }
        !           101: 
        !           102:        reset($expected);
        !           103:        list($k, $values) = each($expected);
        !           104:        $sql = sprintf("INSERT INTO test(id, %s) VALUES (1, %s)", $values[0], $values[1]);
        !           105:        if (!mysql_query($sql, $link)) {
        !           106:                printf("[011/%s] '%s', [%d] %s\n", $columns, $sql, mysql_errno($link), mysql_error($link));
        !           107:                continue;
        !           108:        }
        !           109: 
        !           110:        if (!$res = mysql_query(sprintf("SELECT id, %s FROM test", $values[0]), $link)) {
        !           111:                printf("[012/%s] [%d] %s\n", $columns, mysql_errno($link), mysql_error($link));
        !           112:                continue;
        !           113:        }
        !           114: 
        !           115:        $i = 1;
        !           116:        while (list($field, $flags) = each($expected)) {
        !           117:                $tmp = mysql_field_flags($res, $i++);
        !           118: 
        !           119:                foreach ($flags as $k => $flag) {
        !           120:                if (!preg_match(sprintf('@\s*%s\s*@ismU', $flag), $tmp)) {
        !           121:                        printf("[013/%s] Field '%s', flag '%s' not found, [%d] %s\n", $columns, $field, $flag, mysql_errno($link), mysql_error($link));
        !           122:                }
        !           123:        }
        !           124:                foreach ($flags as $k => $flag) {
        !           125:                        $tmp = preg_replace(sprintf('@\s*%s\s*@ismU', $flag), '', $tmp);
        !           126:                }
        !           127:                if ('' != $tmp)
        !           128:                        printf("[014/%s] Field '%s', unexpected flags '%s' found, [%d] %s\n", $columns, $field, $tmp, mysql_errno($link), mysql_error($link));
        !           129:        }
        !           130:        mysql_free_result($res);
        !           131: }
        !           132: 
        !           133: var_dump(mysql_field_flags($res, 0));
        !           134: 
        !           135: mysql_close($link);
        !           136: print "done!";
        !           137: ?>
        !           138: --CLEAN--
        !           139: <?php
        !           140: require_once("clean_table.inc");
        !           141: ?>
        !           142: --EXPECTF--
        !           143: Warning: mysql_field_flags() expects exactly 2 parameters, 1 given in %s on line %d
        !           144: 
        !           145: Warning: mysql_field_flags(): Field -1 is invalid for MySQL result index %d in %s on line %d
        !           146: 
        !           147: Warning: mysql_field_flags(): Field 2 is invalid for MySQL result index %d in %s on line %d
        !           148: 
        !           149: Warning: mysql_field_flags(): %d is not a valid MySQL result resource in %s on line %d
        !           150: bool(false)
        !           151: done!

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