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    if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
87        printf("[021] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
88
89    if (!$mysqli->query("DROP TABLE IF EXISTS t1"))
90        printf("[022] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
91
92    if (!$mysqli->query("CREATE TABLE t1 (a smallint)"))
93        printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
94
95    $warning = new mysqli_warning($mysqli);
96
97    if (!is_string($warning->message) || ('' == $warning->message))
98        printf("[025] Expecting string, got %s/%s", gettype($warning->message), $warning->message);
99
100    if (!$mysqli->query("DROP TABLE t1"))
101        printf("[026] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
102
103    /* Yes, I really want to check if the object property is empty */
104    if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
105        printf("[027] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
106
107    $warning = new mysqli_warning($mysqli);
108    if (false !== ($tmp = $warning->next()))
109        printf("[028] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
110
111    if ('' != ($tmp = $warning->message))
112        printf("[029] Expecting string/empty, got %s/%s\n", gettype($tmp), $tmp);
113
114    if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
115        printf("[030] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
116
117    if (!$mysqli->query("DROP TABLE IF EXISTS t1"))
118        printf("[031] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
119
120    if (!$mysqli->query("CREATE TABLE t1 (a smallint)"))
121        printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
122
123    /* out of range, three warnings */
124    if (!$mysqli->query("INSERT IGNORE INTO t1(a) VALUES (65536), (65536), (65536)"))
125        printf("[033] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
126
127    $warning = new mysqli_warning($mysqli);
128        $i = 1;
129    while ($warning->next() && ('' != ($tmp = $warning->message))) {
130        $i++;
131    }
132    if (3 != $i)
133        printf("[034] Expecting three warnings, got %d warnings\n", $i);
134
135    $stmt = mysqli_stmt_init();
136    $warning = new mysqli_warning($stmt);
137    if (false !== ($tmp = $warning->next()))
138        printf("[035] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
139
140    print "done!";
141?>
142<?php
143require_once "connect.inc";
144if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
145   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
146
147if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
148    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
149
150if (!mysqli_query($link, "DROP TABLE IF EXISTS t1"))
151    printf("[c003] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
152
153mysqli_close($link);
154?>
155--EXPECT--
156done!
157