Skip to content

Commit 50ff4b7

Browse files
committed
Patch driver to include failing SQL in exception messages
PHPUnit output shows 343 errors with 'unexpected token '%'' at a specific offset, but not the SQL that triggered it. Instrument Connection::query so rethrown PDOExceptions carry the SQL, letting us see what Turso is parsing.
1 parent 0e7338a commit 50ff4b7

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,38 @@ jobs:
283283
ignore-cache: "yes"
284284
composer-options: "--optimize-autoloader"
285285

286+
- name: Patch driver to surface failing SQL in exceptions
287+
working-directory: packages/mysql-on-sqlite
288+
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
317+
286318
- name: Install gdb
287319
run: sudo apt-get install -y --no-install-recommends gdb
288320

0 commit comments

Comments
 (0)