1--TEST--
2mysqli_stmt_send_long_data() - exceed packet size, mysqlnd
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7
8if (!stristr(mysqli_get_client_info(), 'mysqlnd'))
9    die("skip: warnings only available in mysqlnd");
10?>
11--FILE--
12<?php
13    require('table.inc');
14
15    if (!$stmt = mysqli_stmt_init($link))
16        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
17
18    if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
19        printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
20
21    if (!mysqli_query($link, sprintf("CREATE TABLE test(id INT NOT NULL AUTO_INCREMENT, label LONGBLOB, PRIMARY KEY(id)) ENGINE = %s", $engine)))
22        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
23
24    if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)"))
25        printf("[004] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
26
27    $id = null;
28    $label = null;
29    if (!mysqli_stmt_bind_param($stmt, "ib", $id, $label))
30        printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
31
32    if (!$res = mysqli_query($link, "SHOW VARIABLES LIKE 'max_allowed_packet'"))
33        printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
34
35    if (!$row = mysqli_fetch_assoc($res))
36        printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
37
38    mysqli_free_result($res);
39
40    if (0 === ($max_allowed_packet = (int)$row['Value']))
41        printf("[008] Cannot determine max_allowed_packet size and/or bogus max_allowed_packet setting used.\n");
42
43    // let's ignore upper limits for LONGBLOB (2^32) ...
44    // maximum packet size up to which we test is 10M
45    $tmp = '';
46    $blob = '';
47    $tmp = str_repeat('a', 1024);
48
49    $limit = min(floor($max_allowed_packet / 1024 / 2), 10240);
50    $blob = str_repeat($tmp, $limit);
51
52    assert(strlen($blob) <= $max_allowed_packet);
53
54    if (true !== ($tmp = mysqli_stmt_send_long_data($stmt, 1, $blob)))
55        printf("[009] Expecting boolean/true, got %s/%s. [%d] %s\n",
56            gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
57
58    $id = 1;
59    if (true !== mysqli_stmt_execute($stmt))
60        printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
61
62        /*
63        TODO - we skip this because of the open bug http://bugs.mysql.com/bug.php?id=26824
64        It would always fail.
65
66        This should be added to the EXPECTF, if you reactivate the test
67Warning: mysqli_stmt_send_long_data(): Skipped %d bytes. Last command STMT_SEND_LONG_DATA hasn't consumed all the output from the server in %s on line %d
68
69Warning: mysqli_stmt_send_long_data(): There was an error while sending long data. Probably max_allowed_packet_size is smaller than the data. You have to increase it or send smaller chunks of data. Answer was %d bytes long. in %s on line %d
70
71
72
73        if (floor($max_allowed_packet / 1024 / 2) <= 10240) {
74                // test with a blob smaller than 10M allows us to test
75                // for too long packages without wasting too much memory
76                $limit = $max_allowed_packet - strlen($blob) + 1;
77                $blob2 = $blob;
78        $blob2 .= str_repeat('b', $limit);
79
80                assert(strlen($blob2) > $max_allowed_packet);
81
82                if (false !== ($tmp = mysqli_stmt_send_long_data($stmt, 1, $blob2)))
83                        printf("[011] Expecting boolean/false, got %s/%s. [%d] %s\n",
84                                gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
85
86                $id = 2;
87                if (false !== ($tmp = mysqli_stmt_execute($stmt)))
88                        printf("[012] Expecting boolean/false, got %s/%s, [%d] %s\n",
89                                gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
90        }
91        */
92    mysqli_stmt_close($stmt);
93    mysqli_close($link);
94
95    print "done!";
96?>
97--CLEAN--
98<?php
99    require_once("clean_table.inc");
100?>
101--EXPECT--
102done!
103