|
| 1 | +--TEST-- |
| 2 | +Bug #79375: mysqli_store_result does not report error from lock wait timeout |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +require_once('skipif.inc'); |
| 6 | +require_once('skipifconnectfailure.inc'); |
| 7 | +if (!defined('MYSQLI_STORE_RESULT_COPY_DATA')) die('skip requires mysqlnd'); |
| 8 | +?> |
| 9 | +--FILE-- |
| 10 | +<?php |
| 11 | + |
| 12 | +require_once("connect.inc"); |
| 13 | +mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); |
| 14 | +$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); |
| 15 | +$mysqli2 = new my_mysqli($host, $user, $passwd, $db, $port, $socket); |
| 16 | + |
| 17 | +$mysqli->query('DROP TABLE IF EXISTS test'); |
| 18 | +$mysqli->query('CREATE TABLE test (first int) ENGINE = InnoDB'); |
| 19 | +$mysqli->query('INSERT INTO test VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9)'); |
| 20 | + |
| 21 | +function testStmtStoreResult(mysqli $mysqli, string $name) { |
| 22 | + $mysqli->query("SET innodb_lock_wait_timeout = 1"); |
| 23 | + $mysqli->query("START TRANSACTION"); |
| 24 | + $query = "SELECT first FROM test WHERE first = 1 FOR UPDATE"; |
| 25 | + echo "Running query on $name\n"; |
| 26 | + $stmt = $mysqli->prepare($query); |
| 27 | + $stmt->execute(); |
| 28 | + try { |
| 29 | + $stmt->store_result(); |
| 30 | + echo "Got {$stmt->num_rows} for $name\n"; |
| 31 | + } catch(mysqli_sql_exception $e) { |
| 32 | + echo $e->getMessage()."\n"; |
| 33 | + } |
| 34 | +} |
| 35 | +function testStmtGetResult(mysqli $mysqli, string $name) { |
| 36 | + $mysqli->query("SET innodb_lock_wait_timeout = 1"); |
| 37 | + $mysqli->query("START TRANSACTION"); |
| 38 | + $query = "SELECT first FROM test WHERE first = 1 FOR UPDATE"; |
| 39 | + echo "Running query on $name\n"; |
| 40 | + $stmt = $mysqli->prepare($query); |
| 41 | + $stmt->execute(); |
| 42 | + try { |
| 43 | + $res = $stmt->get_result(); |
| 44 | + echo "Got {$res->num_rows} for $name\n"; |
| 45 | + } catch(mysqli_sql_exception $e) { |
| 46 | + echo $e->getMessage()."\n"; |
| 47 | + } |
| 48 | +} |
| 49 | +function testNormalQuery(mysqli $mysqli, string $name) { |
| 50 | + $mysqli->query("SET innodb_lock_wait_timeout = 1"); |
| 51 | + $mysqli->query("START TRANSACTION"); |
| 52 | + $query = "SELECT first FROM test WHERE first = 1 FOR UPDATE"; |
| 53 | + echo "Running query on $name\n"; |
| 54 | + try { |
| 55 | + $res = $mysqli->query($query); |
| 56 | + echo "Got {$res->num_rows} for $name\n"; |
| 57 | + } catch(mysqli_sql_exception $e) { |
| 58 | + echo $e->getMessage()."\n"; |
| 59 | + } |
| 60 | +} |
| 61 | +function testStmtUseResult(mysqli $mysqli, string $name) { |
| 62 | + $mysqli->query("SET innodb_lock_wait_timeout = 1"); |
| 63 | + $mysqli->query("START TRANSACTION"); |
| 64 | + $query = "SELECT first FROM test WHERE first = 1 FOR UPDATE"; |
| 65 | + echo "Running query on $name\n"; |
| 66 | + $stmt = $mysqli->prepare($query); |
| 67 | + $stmt->execute(); |
| 68 | + try { |
| 69 | + $stmt->fetch(); // should throw an error |
| 70 | + $stmt->fetch(); |
| 71 | + echo "Got {$stmt->num_rows} for $name\n"; |
| 72 | + } catch (mysqli_sql_exception $e) { |
| 73 | + echo $e->getMessage()."\n"; |
| 74 | + } |
| 75 | +} |
| 76 | +function testResultFetchRow(mysqli $mysqli, string $name) { |
| 77 | + $mysqli->query("SET innodb_lock_wait_timeout = 1"); |
| 78 | + $mysqli->query("START TRANSACTION"); |
| 79 | + $query = "SELECT first FROM test WHERE first = 1 FOR UPDATE"; |
| 80 | + echo "Running query on $name\n"; |
| 81 | + $res = $mysqli->query($query, MYSQLI_USE_RESULT); |
| 82 | + try { |
| 83 | + $res->fetch_row(); |
| 84 | + $res->fetch_row(); |
| 85 | + echo "Got {$res->num_rows} for $name\n"; |
| 86 | + } catch(mysqli_sql_exception $e) { |
| 87 | + echo $e->getMessage()."\n"; |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +testStmtStoreResult($mysqli, 'first connection'); |
| 92 | +testStmtStoreResult($mysqli2, 'second connection'); |
| 93 | + |
| 94 | +$mysqli->close(); |
| 95 | +$mysqli2->close(); |
| 96 | + |
| 97 | +echo "\n"; |
| 98 | +// try it again for get_result |
| 99 | +$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); |
| 100 | +$mysqli2 = new my_mysqli($host, $user, $passwd, $db, $port, $socket); |
| 101 | + |
| 102 | +testStmtGetResult($mysqli, 'first connection'); |
| 103 | +testStmtGetResult($mysqli2, 'second connection'); |
| 104 | + |
| 105 | +$mysqli->close(); |
| 106 | +$mysqli2->close(); |
| 107 | + |
| 108 | +echo "\n"; |
| 109 | +// try it again with unprepared query |
| 110 | +$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); |
| 111 | +$mysqli2 = new my_mysqli($host, $user, $passwd, $db, $port, $socket); |
| 112 | + |
| 113 | +testNormalQuery($mysqli, 'first connection'); |
| 114 | +testNormalQuery($mysqli2, 'second connection'); |
| 115 | + |
| 116 | +$mysqli->close(); |
| 117 | +$mysqli2->close(); |
| 118 | + |
| 119 | +echo "\n"; |
| 120 | +// try it again with unprepared query |
| 121 | +$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); |
| 122 | +$mysqli2 = new my_mysqli($host, $user, $passwd, $db, $port, $socket); |
| 123 | + |
| 124 | +testStmtUseResult($mysqli, 'first connection'); |
| 125 | +testStmtUseResult($mysqli2, 'second connection'); |
| 126 | + |
| 127 | +$mysqli->close(); |
| 128 | +$mysqli2->close(); |
| 129 | + |
| 130 | +echo "\n"; |
| 131 | +// try it again using fetch_row on a result object |
| 132 | +$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); |
| 133 | +$mysqli2 = new my_mysqli($host, $user, $passwd, $db, $port, $socket); |
| 134 | + |
| 135 | +testResultFetchRow($mysqli, 'first connection'); |
| 136 | +testResultFetchRow($mysqli2, 'second connection'); |
| 137 | + |
| 138 | +$mysqli->close(); |
| 139 | +$mysqli2->close(); |
| 140 | + |
| 141 | +?> |
| 142 | +--CLEAN-- |
| 143 | +<?php |
| 144 | + require_once("clean_table.inc"); |
| 145 | +?> |
| 146 | +--EXPECTF-- |
| 147 | +Running query on first connection |
| 148 | +Got %d for first connection |
| 149 | +Running query on second connection |
| 150 | +Lock wait timeout exceeded; try restarting transaction |
| 151 | + |
| 152 | +Running query on first connection |
| 153 | +Got %d for first connection |
| 154 | +Running query on second connection |
| 155 | +Lock wait timeout exceeded; try restarting transaction |
| 156 | + |
| 157 | +Running query on first connection |
| 158 | +Got %d for first connection |
| 159 | +Running query on second connection |
| 160 | +Lock wait timeout exceeded; try restarting transaction |
| 161 | + |
| 162 | +Running query on first connection |
| 163 | +Got %d for first connection |
| 164 | +Running query on second connection |
| 165 | +Lock wait timeout exceeded; try restarting transaction |
| 166 | + |
| 167 | +Running query on first connection |
| 168 | +Got 1 for first connection |
| 169 | +Running query on second connection |
| 170 | + |
| 171 | +Warning: mysqli_result::fetch_row(): Error while reading a row in %s on line %d |
| 172 | +Got 0 for second connection |
0 commit comments