summaryrefslogtreecommitdiff
path: root/ext/mysqli/tests/mysqli_change_user_locks_temporary.phpt
blob: fd4e9943ab22b5623a2787c85103cd8edee05351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--TEST--
mysqli_change_user() - table locks, GET_LOCK(), temporary tables
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
require_once('skipifconnectfailure.inc');
die("skip - is the server still buggy?");
?>
--FILE--
<?php
    require_once('connect.inc');
    require_once('table.inc');

    if (!$link2 = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
        printf("[001] Cannot create second connection handle, [%d] %s\n",
            mysqli_connect_errno(), mysqli_connect_error());

    if (!mysqli_query($link, 'LOCK TABLE test WRITE'))
        printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

    /*
    if ($res = mysqli_query($link2, 'SELECT COUNT(*) AS _num FROM test')) {
        printf("[003] Reading from test should not be possible due to a lock, [%d] %s\n",
            mysqli_errno($link2), mysqli_error($link2));
        mysqli_free_result($res);
    }
    */

    // LOCKS should be removed
    mysqli_change_user($link, $user, $passwd, $db);

    if (!$res = mysqli_query($link2, 'SELECT COUNT(*) AS _num FROM test'))
        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

    if (!$row = mysqli_fetch_assoc($res))
        printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

    if ($row['_num'] < 1)
        printf("[005] There should be some rows in the table test\n");

    mysqli_free_result($res);
    mysqli_close($link2);

    if (!mysqli_query($link, 'DROP TABLE test'))
        printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

    if (!mysqli_query($link, 'CREATE TEMPORARY TABLE test(id INT)'))
        printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

    if (!mysqli_query($link, 'INSERT INTO test(id) VALUES (1), (2), (3)'))
        printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

    if (!$res = mysqli_query($link, 'SELECT COUNT(*) AS _num FROM test'))
        printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

    if (!$row = mysqli_fetch_assoc($res))
        printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

    if ($row['_num'] != 3)
        printf("[011] There should be three rows in the table test\n");

    mysqli_free_result($res);

    // Temporary tables should be dropped
    mysqli_change_user($link, $user, $passwd, $db);

    if ($res = mysqli_query($link, 'SELECT COUNT(*) AS _num FROM test')) {
        printf("[012] There should be no table test any more, [%d] %s\n",
            mysqli_errno($link), mysqli_error($link));
        mysqli_free_result($res);
    }

    if (!$res = mysqli_query($link, 'SELECT GET_LOCK("phptest", 2) AS _ok'))
        printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

    if (!$row = mysqli_fetch_assoc($res))
        printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

    if ($row['_ok'] != 1)
        printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

    mysqli_free_result($res);

    // GET_LOCK("phptest") should be released
    mysqli_change_user($link, $user, $passwd, $db);

    if (!$res = mysqli_query($link, 'SELECT IS_FREE_LOCK("phptest") AS _ok'))
        printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

    if (!$row = mysqli_fetch_assoc($res))
        printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

    if ($row['_ok'] != 1)
        printf("[018] Lock 'phptest' should have been released, [%d] %s\n",
            mysqli_errno($link), mysqli_error($link));

    mysqli_free_result($res);
    mysqli_close($link);
    print "done!";
?>
--CLEAN--
<?php
    require_once("clean_table.inc");
?>
--EXPECT--
done!