1--TEST--
2mysqli_stmt_get_warnings() - TODO
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once "connect.inc";
8
9if (!$link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
10    die(sprintf("skip Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
11        $host, $user, $db, $port, $socket));
12}
13
14if (!mysqli_query($link, "DROP TABLE IF EXISTS test") ||
15    !mysqli_query($link, "CREATE TABLE test(id SMALLINT)"))
16    die(sprintf("skip [%d] %s\n", $link->errno, $link->error));
17
18if (!@mysqli_query($link, "SET sql_mode=''") || !@mysqli_query($link, "INSERT INTO test(id) VALUES (100001)"))
19    die("skip Strict sql mode seems to be active. We won't get a warning to check for.");
20
21mysqli_query($link, "DROP TABLE IF EXISTS test");
22?>
23--FILE--
24<?php
25    require 'table.inc';
26
27    if (!$stmt = mysqli_stmt_init($link))
28        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
29
30    try {
31        mysqli_stmt_get_warnings($stmt);
32    } catch (Error $exception) {
33        echo $exception->getMessage() . "\n";
34    }
35
36    if (!mysqli_stmt_prepare($stmt, "SET sql_mode=''") || !mysqli_stmt_execute($stmt))
37        printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
38
39    if (!mysqli_stmt_prepare($stmt, "DROP TABLE IF EXISTS test") || !mysqli_stmt_execute($stmt))
40        printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
41
42    if (false !== ($tmp = mysqli_stmt_get_warnings($stmt)))
43        printf("[007] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
44
45    if (!mysqli_stmt_prepare($stmt, "CREATE TABLE test(id SMALLINT, label CHAR(1))") || !mysqli_stmt_execute($stmt))
46        printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
47
48    if (false !== ($tmp = mysqli_stmt_get_warnings($stmt)))
49        printf("[009] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
50
51    if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (100000, 'a'), (100001, 'b')") ||
52        !mysqli_stmt_execute($stmt))
53        printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
54
55    if (!is_object($warning = mysqli_stmt_get_warnings($stmt)))
56        printf("[011] Expecting mysqli_warning object, got %s/%s\n", gettype($warning), $warning);
57
58    if ('mysqli_warning' !== get_class($warning))
59        printf("[012] Expecting object of type mysqli_warning got type '%s'", get_class($warning));
60
61    if (!method_exists($warning, 'next'))
62        printf("[013] Object mysqli_warning seems to lack method next()\n");
63
64    $i = 0;
65    do {
66
67        if ('' == $warning->message)
68            printf("[014 - %d] Message should not be empty\n", $i);
69
70        if ('' == $warning->sqlstate)
71            printf("[015 - %d] SQL State should not be empty\n", $i);
72
73        if (0 == $warning->errno)
74            printf("[016 - %d] Error number should not be zero\n", $i);
75
76        $i++;
77
78    } while ($warning->next());
79
80    if (2 != $i)
81        printf("[017] Expected 2 warnings, got %d warnings\n", $i);
82
83    mysqli_stmt_close($stmt);
84
85    try {
86        mysqli_stmt_get_warnings($stmt);
87    } catch (Error $exception) {
88        echo $exception->getMessage() . "\n";
89    }
90
91    mysqli_close($link);
92    print "done!";
93?>
94--CLEAN--
95<?php
96require_once "clean_table.inc";
97?>
98--EXPECT--
99mysqli_stmt object is not fully initialized
100mysqli_stmt object is already closed
101done!
102