Skip to content

Commit c327e29

Browse files
committed
Revert driver SQL-logging patch; use standalone diagnostic instead
Wrapping Connection::query in try/catch made the full PHPUnit run far slower (exception object churn on the 425 failing tests). Replace with a focused reproduction step that rebuilds the driver and logs every SQLite-bound query via the existing set_query_logger hook.
1 parent 50ff4b7 commit c327e29

1 file changed

Lines changed: 44 additions & 31 deletions

File tree

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

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -283,40 +283,53 @@ jobs:
283283
ignore-cache: "yes"
284284
composer-options: "--optimize-autoloader"
285285

286-
- name: Patch driver to surface failing SQL in exceptions
286+
- name: Install gdb
287+
run: sudo apt-get install -y --no-install-recommends gdb
288+
289+
- name: Capture failing SQL from the first failing driver test
290+
continue-on-error: true
291+
env:
292+
LD_PRELOAD: ${{ steps.preload.outputs.value }}
287293
working-directory: packages/mysql-on-sqlite
288294
run: |
289-
# Wrap WP_SQLite_Connection::query() in a try/catch that rethrows with
290-
# the SQL appended to the message, so we see what Turso rejects.
291-
python3 - <<'PY'
292-
import re
293-
path = 'src/sqlite/class-wp-sqlite-connection.php'
294-
src = open(path).read()
295-
before = (
296-
"\t\t$stmt = $this->pdo->prepare( $sql );\n"
297-
"\t\t$stmt->execute( $params );\n"
298-
"\t\treturn $stmt;"
299-
)
300-
after = (
301-
"\t\ttry {\n"
302-
"\t\t\t$stmt = $this->pdo->prepare( $sql );\n"
303-
"\t\t\t$stmt->execute( $params );\n"
304-
"\t\t\treturn $stmt;\n"
305-
"\t\t} catch ( \\PDOException $e ) {\n"
306-
"\t\t\tthrow new \\PDOException(\n"
307-
"\t\t\t\t$e->getMessage() . \" [SQL: \" . $sql . \"]\",\n"
308-
"\t\t\t\t(int) $e->getCode(),\n"
309-
"\t\t\t\t$e\n"
310-
"\t\t\t);\n"
311-
"\t\t}"
312-
)
313-
assert before in src, 'query() body not found'
314-
open(path, 'w').write(src.replace(before, after, 1))
315-
print('patched WP_SQLite_Connection::query()')
316-
PY
295+
# 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.
298+
php <<'PHP'
299+
<?php
300+
require __DIR__ . '/tests/bootstrap.php';
317301
318-
- name: Install gdb
319-
run: sudo apt-get install -y --no-install-recommends gdb
302+
$pdo = new PDO('sqlite::memory:');
303+
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
304+
305+
$conn = new WP_SQLite_Connection([ 'pdo' => $pdo ]);
306+
$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");
312+
}
313+
});
314+
315+
try {
316+
$engine = new WP_SQLite_Driver($conn, 'wp');
317+
fwrite(STDERR, "Driver construction ok\n");
318+
319+
$engine->query("CREATE TABLE _options (
320+
ID INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
321+
option_name TEXT NOT NULL default '',
322+
option_value TEXT NOT NULL default ''
323+
);");
324+
fwrite(STDERR, "CREATE TABLE _options ok\n");
325+
} catch (\Throwable $e) {
326+
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+
}
331+
}
332+
PHP
320333
321334
- name: Diagnose createFunction behavior
322335
continue-on-error: true

0 commit comments

Comments
 (0)