1--TEST--
2mysqli_get_warnings() - TODO
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8if (!$TEST_EXPERIMENTAL)
9    die("skip - experimental (= unsupported) feature");
10?>
11--FILE--
12<?php
13    require_once 'connect.inc';
14
15    $tmp    = NULL;
16    $link   = NULL;
17
18    if (!is_null($tmp = @mysqli_get_warnings()))
19        printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
20
21    if (!is_null($tmp = @mysqli_get_warnings($link)))
22        printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
23
24    if (!is_null($tmp = @mysqli_get_warnings('')))
25        printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
26
27    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
28        printf("[003] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
29    }
30
31    if (false !== ($tmp = mysqli_get_warnings($link))) {
32        printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp));
33    }
34
35    if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
36        printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
37
38    if (!mysqli_query($link, "CREATE TABLE test (id SMALLINT)"))
39        printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
40
41    if (!mysqli_query($link, "INSERT INTO test (id) VALUES (1000000)"))
42        printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
43
44    if (!is_object($warning = mysqli_get_warnings($link)) || 'mysqli_warning' != get_class($warning)) {
45        printf("[008] Expecting object/mysqli_warning, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp));
46    }
47
48    if (!method_exists($warning, 'next'))
49        printf("[009] Borked object, method next is missing\n");
50
51    $properties = array_merge(get_object_vars($warning), get_class_vars(get_class($warning)));
52    if (!empty($properties))
53        printf("[010] Properties have always been magic, hidden things - why are they visible now, a BC break...\n");
54
55    if ((!is_string($warning->message)) || ('' == $warning->message)) /* NULL or not there at all */
56        printf("[011] Expecting string/not empty, got %s/%s\n", gettype($warning->message), $warning->message);
57
58    if ((!is_string($warning->sqlstate)) || ('' == $warning->sqlstate)) /* NULL or not there at all */
59        printf("[012] Expecting string/not empty, got %s/%s\n", gettype($warning->sqlstate), $warning->sqlstate);
60
61    if ((!is_int($warning->errno)) || (0 == $warning->errno)) /* NULL or not there at all */
62        printf("[013] Expecting int/not 0, got %s/%s\n", gettype($warning->errno), $warning->errno);
63
64    if (false !== ($tmp = $warning->next()))
65        printf("[014] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
66
67    if (!mysqli_query($link, "INSERT INTO test (id) VALUES (1000000), (1000001)"))
68        printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
69
70    if (($tmp = mysqli_warning_count($link)) !== 2)
71        printf("[016] Expecting 2 warnings, got %d warnings", $tmp);
72
73    if (!is_object($warning = mysqli_get_warnings($link)) || 'mysqli_warning' != get_class($warning)) {
74        printf("[017] Expecting object/mysqli_warning, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp));
75    }
76
77    if (true !== ($tmp = $warning->next()))
78        printf("[018] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
79
80    if (false !== ($tmp = $warning->next()))
81        printf("[020] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
82
83    mysqli_close($link);
84
85
86    $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
87
88    if (!$mysqli->query("DROP TABLE IF EXISTS t1"))
89        printf("[022] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
90
91    if (!$mysqli->query("CREATE TABLE t1 (a smallint)"))
92        printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
93
94    $warning = new mysqli_warning($mysqli);
95
96    if (!is_string($warning->message) || ('' == $warning->message))
97        printf("[025] Expecting string, got %s/%s", gettype($warning->message), $warning->message);
98
99    if (!$mysqli->query("DROP TABLE t1"))
100        printf("[026] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
101
102    /* Yes, I really want to check if the object property is empty */
103    $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
104
105    $warning = new mysqli_warning($mysqli);
106    if (false !== ($tmp = $warning->next()))
107        printf("[028] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
108
109    if ('' != ($tmp = $warning->message))
110        printf("[029] Expecting string/empty, got %s/%s\n", gettype($tmp), $tmp);
111
112    $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
113
114    if (!$mysqli->query("DROP TABLE IF EXISTS t1"))
115        printf("[031] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
116
117    if (!$mysqli->query("CREATE TABLE t1 (a smallint)"))
118        printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
119
120    /* out of range, three warnings */
121    if (!$mysqli->query("INSERT IGNORE INTO t1(a) VALUES (65536), (65536), (65536)"))
122        printf("[033] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
123
124    $warning = new mysqli_warning($mysqli);
125        $i = 1;
126    while ($warning->next() && ('' != ($tmp = $warning->message))) {
127        $i++;
128    }
129    if (3 != $i)
130        printf("[034] Expecting three warnings, got %d warnings\n", $i);
131
132    $stmt = mysqli_stmt_init();
133    $warning = new mysqli_warning($stmt);
134    if (false !== ($tmp = $warning->next()))
135        printf("[035] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
136
137    print "done!";
138?>
139<?php
140require_once 'connect.inc';
141if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
142   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
143
144if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
145    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
146
147if (!mysqli_query($link, "DROP TABLE IF EXISTS t1"))
148    printf("[c003] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
149
150mysqli_close($link);
151?>
152--EXPECT--
153done!
154