Skip to content

Commit 073bbbd

Browse files
committed
Install diagnostic query logger on driver's own connection
1 parent c327e29 commit 073bbbd

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

.github/workflows/phpunit-tests-turso.yml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -293,29 +293,31 @@ jobs:
293293
working-directory: packages/mysql-on-sqlite
294294
run: |
295295
# Reproduce the first failing test's setUp path with a query logger
296-
# wired up. When Turso rejects SQL, the last logged query is what
297-
# Turso saw — printed right before the exception.
296+
# wired up. The driver replaces any logger during construction, so
297+
# we install ours on the driver's own connection afterwards.
298298
php <<'PHP'
299299
<?php
300300
require __DIR__ . '/tests/bootstrap.php';
301301
302302
$pdo = new PDO('sqlite::memory:');
303303
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
304-
305304
$conn = new WP_SQLite_Connection([ 'pdo' => $pdo ]);
305+
306+
$engine = new WP_SQLite_Driver($conn, 'wp');
307+
fwrite(STDERR, "Driver construction ok\n");
308+
306309
$logged = [];
307-
$conn->set_query_logger(function (string $sql, array $params) use (&$logged) {
308-
$logged[] = [$sql, $params];
309-
fwrite(STDERR, sprintf("[sql #%d] %s\n", count($logged), $sql));
310-
if ($params) {
311-
fwrite(STDERR, ' params: ' . json_encode($params) . "\n");
310+
$engine->get_connection()->set_query_logger(
311+
function (string $sql, array $params) use (&$logged) {
312+
$logged[] = [$sql, $params];
313+
fwrite(STDERR, sprintf("[sql #%d] %s\n", count($logged), $sql));
314+
if ($params) {
315+
fwrite(STDERR, ' params: ' . json_encode($params) . "\n");
316+
}
312317
}
313-
});
318+
);
314319
315320
try {
316-
$engine = new WP_SQLite_Driver($conn, 'wp');
317-
fwrite(STDERR, "Driver construction ok\n");
318-
319321
$engine->query("CREATE TABLE _options (
320322
ID INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
321323
option_name TEXT NOT NULL default '',
@@ -324,10 +326,12 @@ jobs:
324326
fwrite(STDERR, "CREATE TABLE _options ok\n");
325327
} catch (\Throwable $e) {
326328
fwrite(STDERR, "EXC: " . $e->getMessage() . "\n");
327-
fwrite(STDERR, "last SQL: " . ($logged[count($logged) - 1][0] ?? '<none>') . "\n");
328-
if (($last = $logged[count($logged) - 1][0] ?? null) !== null) {
329-
fwrite(STDERR, "char at offset 189: " . substr($last, 180, 20) . "\n");
330-
}
329+
$last = end($logged) ?: ['<no SQL logged>', []];
330+
fwrite(STDERR, "last SQL:\n" . $last[0] . "\n");
331+
fwrite(STDERR, sprintf(
332+
"char at offset 189 window [180..209]:\n %s\n",
333+
substr($last[0], 180, 30)
334+
));
331335
}
332336
PHP
333337

0 commit comments

Comments
 (0)