|
| 1 | +--TEST-- |
| 2 | +Sqlite3Stmt::explain/setExplain usage |
| 3 | +--EXTENSIONS-- |
| 4 | +pdo_sqlite |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +if (PHP_OS_FAMILY === "Darwin") die("skip on darwin for now"); |
| 8 | +$version = SQLite3::version()['versionNumber']; |
| 9 | +if ($version <= 3043000) die("skip for sqlite3 < 3.43.0"); |
| 10 | +?> |
| 11 | +--FILE-- |
| 12 | +<?php |
| 13 | + |
| 14 | +require_once(__DIR__ . '/new_db.inc'); |
| 15 | + |
| 16 | +$db->exec('CREATE TABLE test_explain (a string);'); |
| 17 | +$stmt = $db->prepare('INSERT INTO test_explain VALUES ("first insert"), ("second_insert")'); |
| 18 | +$stmt->setExplain(Sqlite3Stmt::EXPLAIN_MODE_EXPLAIN); |
| 19 | +var_dump($stmt->explain() == Sqlite3Stmt::EXPLAIN_MODE_EXPLAIN); |
| 20 | +$r = $stmt->execute(); |
| 21 | +while (($arr = $r->fetchArray(SQLITE3_ASSOC)) !== false) var_dump($arr); |
| 22 | +var_dump($r->fetchArray(SQLITE3_ASSOC)); |
| 23 | +$stmts = $db->prepare('SELECT * FROM test_explain'); |
| 24 | +$stmts->setExplain(Sqlite3Stmt::EXPLAIN_MODE_EXPLAIN_QUERY_PLAN); |
| 25 | +var_dump($stmt->explain() == Sqlite3Stmt::EXPLAIN_MODE_EXPLAIN_QUERY_PLAN); |
| 26 | +$r = $stmts->execute(); |
| 27 | +while (($arr = $r->fetchArray(SQLITE3_ASSOC)) !== false) var_dump($arr); |
| 28 | + |
| 29 | +$stmt = $db->prepare('INSERT INTO test_explain VALUES ("first insert"), ("second_insert")'); |
| 30 | +$stmt->setExplain(Sqlite3Stmt::EXPLAIN_MODE_PREPARED); |
| 31 | +$stmt->execute(); |
| 32 | +$stmts->setExplain(Sqlite3Stmt::EXPLAIN_MODE_PREPARED); |
| 33 | +$r = $stmts->execute(); |
| 34 | +while (($arr = $r->fetchArray(SQLITE3_ASSOC)) !== false) var_dump($arr); |
| 35 | + |
| 36 | +try { |
| 37 | + $stmts->setExplain(-1); |
| 38 | +} catch (\ValueError $e) { |
| 39 | + echo $e->getMessage(), PHP_EOL; |
| 40 | +} |
| 41 | + |
| 42 | +try { |
| 43 | + $stmts->setExplain(256); |
| 44 | +} catch (\ValueError $e) { |
| 45 | + echo $e->getMessage(), PHP_EOL; |
| 46 | +} |
| 47 | + |
| 48 | +var_dump($stmts->explain() == Sqlite3Stmt::EXPLAIN_MODE_PREPARED); |
| 49 | +?> |
| 50 | +--EXPECT-- |
| 51 | +bool(true) |
| 52 | +array(8) { |
| 53 | + ["addr"]=> |
| 54 | + int(0) |
| 55 | + ["opcode"]=> |
| 56 | + string(4) "Init" |
| 57 | + ["p1"]=> |
| 58 | + int(0) |
| 59 | + ["p2"]=> |
| 60 | + int(14) |
| 61 | + ["p3"]=> |
| 62 | + int(0) |
| 63 | + ["p4"]=> |
| 64 | + NULL |
| 65 | + ["p5"]=> |
| 66 | + int(0) |
| 67 | + ["comment"]=> |
| 68 | + NULL |
| 69 | +} |
| 70 | +array(8) { |
| 71 | + ["addr"]=> |
| 72 | + int(1) |
| 73 | + ["opcode"]=> |
| 74 | + string(13) "InitCoroutine" |
| 75 | + ["p1"]=> |
| 76 | + int(3) |
| 77 | + ["p2"]=> |
| 78 | + int(7) |
| 79 | + ["p3"]=> |
| 80 | + int(2) |
| 81 | + ["p4"]=> |
| 82 | + NULL |
| 83 | + ["p5"]=> |
| 84 | + int(0) |
| 85 | + ["comment"]=> |
| 86 | + NULL |
| 87 | +} |
| 88 | +array(8) { |
| 89 | + ["addr"]=> |
| 90 | + int(2) |
| 91 | + ["opcode"]=> |
| 92 | + string(7) "String8" |
| 93 | + ["p1"]=> |
| 94 | + int(0) |
| 95 | + ["p2"]=> |
| 96 | + int(2) |
| 97 | + ["p3"]=> |
| 98 | + int(0) |
| 99 | + ["p4"]=> |
| 100 | + string(12) "first insert" |
| 101 | + ["p5"]=> |
| 102 | + int(0) |
| 103 | + ["comment"]=> |
| 104 | + NULL |
| 105 | +} |
| 106 | +array(8) { |
| 107 | + ["addr"]=> |
| 108 | + int(3) |
| 109 | + ["opcode"]=> |
| 110 | + string(5) "Yield" |
| 111 | + ["p1"]=> |
| 112 | + int(3) |
| 113 | + ["p2"]=> |
| 114 | + int(0) |
| 115 | + ["p3"]=> |
| 116 | + int(0) |
| 117 | + ["p4"]=> |
| 118 | + NULL |
| 119 | + ["p5"]=> |
| 120 | + int(0) |
| 121 | + ["comment"]=> |
| 122 | + NULL |
| 123 | +} |
| 124 | +array(8) { |
| 125 | + ["addr"]=> |
| 126 | + int(4) |
| 127 | + ["opcode"]=> |
| 128 | + string(7) "String8" |
| 129 | + ["p1"]=> |
| 130 | + int(0) |
| 131 | + ["p2"]=> |
| 132 | + int(2) |
| 133 | + ["p3"]=> |
| 134 | + int(0) |
| 135 | + ["p4"]=> |
| 136 | + string(13) "second_insert" |
| 137 | + ["p5"]=> |
| 138 | + int(0) |
| 139 | + ["comment"]=> |
| 140 | + NULL |
| 141 | +} |
| 142 | +array(8) { |
| 143 | + ["addr"]=> |
| 144 | + int(5) |
| 145 | + ["opcode"]=> |
| 146 | + string(5) "Yield" |
| 147 | + ["p1"]=> |
| 148 | + int(3) |
| 149 | + ["p2"]=> |
| 150 | + int(0) |
| 151 | + ["p3"]=> |
| 152 | + int(0) |
| 153 | + ["p4"]=> |
| 154 | + NULL |
| 155 | + ["p5"]=> |
| 156 | + int(0) |
| 157 | + ["comment"]=> |
| 158 | + NULL |
| 159 | +} |
| 160 | +array(8) { |
| 161 | + ["addr"]=> |
| 162 | + int(6) |
| 163 | + ["opcode"]=> |
| 164 | + string(12) "EndCoroutine" |
| 165 | + ["p1"]=> |
| 166 | + int(3) |
| 167 | + ["p2"]=> |
| 168 | + int(0) |
| 169 | + ["p3"]=> |
| 170 | + int(0) |
| 171 | + ["p4"]=> |
| 172 | + NULL |
| 173 | + ["p5"]=> |
| 174 | + int(0) |
| 175 | + ["comment"]=> |
| 176 | + NULL |
| 177 | +} |
| 178 | +array(8) { |
| 179 | + ["addr"]=> |
| 180 | + int(7) |
| 181 | + ["opcode"]=> |
| 182 | + string(9) "OpenWrite" |
| 183 | + ["p1"]=> |
| 184 | + int(0) |
| 185 | + ["p2"]=> |
| 186 | + int(2) |
| 187 | + ["p3"]=> |
| 188 | + int(0) |
| 189 | + ["p4"]=> |
| 190 | + string(1) "1" |
| 191 | + ["p5"]=> |
| 192 | + int(0) |
| 193 | + ["comment"]=> |
| 194 | + NULL |
| 195 | +} |
| 196 | +array(8) { |
| 197 | + ["addr"]=> |
| 198 | + int(8) |
| 199 | + ["opcode"]=> |
| 200 | + string(5) "Yield" |
| 201 | + ["p1"]=> |
| 202 | + int(3) |
| 203 | + ["p2"]=> |
| 204 | + int(13) |
| 205 | + ["p3"]=> |
| 206 | + int(0) |
| 207 | + ["p4"]=> |
| 208 | + NULL |
| 209 | + ["p5"]=> |
| 210 | + int(0) |
| 211 | + ["comment"]=> |
| 212 | + NULL |
| 213 | +} |
| 214 | +array(8) { |
| 215 | + ["addr"]=> |
| 216 | + int(9) |
| 217 | + ["opcode"]=> |
| 218 | + string(8) "NewRowid" |
| 219 | + ["p1"]=> |
| 220 | + int(0) |
| 221 | + ["p2"]=> |
| 222 | + int(1) |
| 223 | + ["p3"]=> |
| 224 | + int(0) |
| 225 | + ["p4"]=> |
| 226 | + NULL |
| 227 | + ["p5"]=> |
| 228 | + int(0) |
| 229 | + ["comment"]=> |
| 230 | + NULL |
| 231 | +} |
| 232 | +array(8) { |
| 233 | + ["addr"]=> |
| 234 | + int(10) |
| 235 | + ["opcode"]=> |
| 236 | + string(10) "MakeRecord" |
| 237 | + ["p1"]=> |
| 238 | + int(2) |
| 239 | + ["p2"]=> |
| 240 | + int(1) |
| 241 | + ["p3"]=> |
| 242 | + int(4) |
| 243 | + ["p4"]=> |
| 244 | + string(1) "C" |
| 245 | + ["p5"]=> |
| 246 | + int(0) |
| 247 | + ["comment"]=> |
| 248 | + NULL |
| 249 | +} |
| 250 | +array(8) { |
| 251 | + ["addr"]=> |
| 252 | + int(11) |
| 253 | + ["opcode"]=> |
| 254 | + string(6) "Insert" |
| 255 | + ["p1"]=> |
| 256 | + int(0) |
| 257 | + ["p2"]=> |
| 258 | + int(4) |
| 259 | + ["p3"]=> |
| 260 | + int(1) |
| 261 | + ["p4"]=> |
| 262 | + string(12) "test_explain" |
| 263 | + ["p5"]=> |
| 264 | + int(57) |
| 265 | + ["comment"]=> |
| 266 | + NULL |
| 267 | +} |
| 268 | +array(8) { |
| 269 | + ["addr"]=> |
| 270 | + int(12) |
| 271 | + ["opcode"]=> |
| 272 | + string(4) "Goto" |
| 273 | + ["p1"]=> |
| 274 | + int(0) |
| 275 | + ["p2"]=> |
| 276 | + int(8) |
| 277 | + ["p3"]=> |
| 278 | + int(0) |
| 279 | + ["p4"]=> |
| 280 | + NULL |
| 281 | + ["p5"]=> |
| 282 | + int(0) |
| 283 | + ["comment"]=> |
| 284 | + NULL |
| 285 | +} |
| 286 | +array(8) { |
| 287 | + ["addr"]=> |
| 288 | + int(13) |
| 289 | + ["opcode"]=> |
| 290 | + string(4) "Halt" |
| 291 | + ["p1"]=> |
| 292 | + int(0) |
| 293 | + ["p2"]=> |
| 294 | + int(0) |
| 295 | + ["p3"]=> |
| 296 | + int(0) |
| 297 | + ["p4"]=> |
| 298 | + NULL |
| 299 | + ["p5"]=> |
| 300 | + int(0) |
| 301 | + ["comment"]=> |
| 302 | + NULL |
| 303 | +} |
| 304 | +array(8) { |
| 305 | + ["addr"]=> |
| 306 | + int(14) |
| 307 | + ["opcode"]=> |
| 308 | + string(11) "Transaction" |
| 309 | + ["p1"]=> |
| 310 | + int(0) |
| 311 | + ["p2"]=> |
| 312 | + int(1) |
| 313 | + ["p3"]=> |
| 314 | + int(1) |
| 315 | + ["p4"]=> |
| 316 | + string(1) "0" |
| 317 | + ["p5"]=> |
| 318 | + int(1) |
| 319 | + ["comment"]=> |
| 320 | + NULL |
| 321 | +} |
| 322 | +array(8) { |
| 323 | + ["addr"]=> |
| 324 | + int(15) |
| 325 | + ["opcode"]=> |
| 326 | + string(4) "Goto" |
| 327 | + ["p1"]=> |
| 328 | + int(0) |
| 329 | + ["p2"]=> |
| 330 | + int(1) |
| 331 | + ["p3"]=> |
| 332 | + int(0) |
| 333 | + ["p4"]=> |
| 334 | + NULL |
| 335 | + ["p5"]=> |
| 336 | + int(0) |
| 337 | + ["comment"]=> |
| 338 | + NULL |
| 339 | +} |
| 340 | +bool(false) |
| 341 | +bool(false) |
| 342 | +array(4) { |
| 343 | + ["id"]=> |
| 344 | + int(2) |
| 345 | + ["parent"]=> |
| 346 | + int(0) |
| 347 | + ["notused"]=> |
| 348 | + int(0) |
| 349 | + ["detail"]=> |
| 350 | + string(17) "SCAN test_explain" |
| 351 | +} |
| 352 | +array(4) { |
| 353 | + ["id"]=> |
| 354 | + int(2) |
| 355 | + ["parent"]=> |
| 356 | + int(0) |
| 357 | + ["notused"]=> |
| 358 | + int(0) |
| 359 | + ["detail"]=> |
| 360 | + string(17) "SCAN test_explain" |
| 361 | +} |
| 362 | +SQLite3Stmt::setExplain(): Argument #1 ($mode) must be one of the SQLite3Stmt::EXPLAIN_MODE_* constants |
| 363 | +SQLite3Stmt::setExplain(): Argument #1 ($mode) must be one of the SQLite3Stmt::EXPLAIN_MODE_* constants |
| 364 | +bool(false) |
0 commit comments