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