Skip to content

Commit 70393ec

Browse files
committed
Fix VALUES-aliasing and CHECK TABLE under Turso
- Force the driver's pre-3.33 VALUES-aliasing fallback (prepend an explicit UNION ALL header) unconditionally. Turso doesn't propagate VALUES implicit column names (column1, column2, ...) through INSERT ... SELECT ... FROM (VALUES (...)) subqueries, even though top-level SELECT column1 FROM (VALUES(...)) works. Should fix five "no such column: columnN" errors. - CHECK TABLE on missing table: Turso's PRAGMA integrity_check is a no-op for unknown tables; add an explicit sqlite_master existence probe so testCheckTable's error path fires.
1 parent 66df0f3 commit 70393ec

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,63 @@ jobs:
986986
src = src.replace(old, new, 1)
987987
open(path, 'w').write(src)
988988
print('patched hex-literal alias force under Turso')
989+
990+
# 9. Turso doesn't propagate VALUES row-column aliases (column1,
991+
# column2, ...) through `INSERT ... SELECT ... FROM (VALUES (...))`
992+
# subqueries, even though top-level `SELECT column1 FROM (VALUES
993+
# (...))` works in its own test suite. The driver already has a
994+
# legacy fallback for SQLite < 3.33 that prepends an explicit
995+
# `SELECT NULL AS column1, ... WHERE FALSE UNION ALL ...` so the
996+
# UNION output carries the aliases. Force-enable that fallback
997+
# unconditionally so it applies under Turso too.
998+
path = 'src/sqlite/class-wp-pdo-mysql-on-sqlite.php'
999+
src = open(path).read()
1000+
old = "\t\t\t$is_values_naming_supported = version_compare( $this->get_sqlite_version(), '3.33.0', '>=' );"
1001+
new = "\t\t\t$is_values_naming_supported = false; // Turso: always use UNION ALL header fallback."
1002+
assert old in src, 'is_values_naming_supported assignment not found'
1003+
open(path, 'w').write(src.replace(old, new, 1))
1004+
print('patched VALUES-aliasing fallback to always-on under Turso')
1005+
1006+
# 10. CHECK TABLE on a missing table on real SQLite raises from
1007+
# `PRAGMA integrity_check(<tbl>)`; on Turso the PRAGMA is a
1008+
# no-op for unknown tables, so testCheckTable sees status=OK
1009+
# instead of the expected "Table 'missing' doesn't exist"
1010+
# error. Check sqlite_master explicitly before the PRAGMA.
1011+
path = 'src/sqlite/class-wp-pdo-mysql-on-sqlite.php'
1012+
src = open(path).read()
1013+
old = (
1014+
"\t\t\t\t\tcase WP_MySQL_Lexer::CHECK_SYMBOL:\n"
1015+
"\t\t\t\t\t\t$stmt = $this->execute_sqlite_query(\n"
1016+
"\t\t\t\t\t\t\tsprintf( 'PRAGMA integrity_check(%s)', $quoted_table_name )\n"
1017+
"\t\t\t\t\t\t);\n"
1018+
"\t\t\t\t\t\t$errors = $stmt->fetchAll( PDO::FETCH_COLUMN );\n"
1019+
"\t\t\t\t\t\tif ( 'ok' === $errors[0] ) {\n"
1020+
"\t\t\t\t\t\t\tarray_shift( $errors );\n"
1021+
"\t\t\t\t\t\t}\n"
1022+
"\t\t\t\t\t\tbreak;\n"
1023+
)
1024+
new = (
1025+
"\t\t\t\t\tcase WP_MySQL_Lexer::CHECK_SYMBOL:\n"
1026+
"\t\t\t\t\t\t$exists_stmt = $this->execute_sqlite_query(\n"
1027+
"\t\t\t\t\t\t\t\"SELECT 1 FROM sqlite_master WHERE type='table' AND name=?\",\n"
1028+
"\t\t\t\t\t\t\tarray( $table_name )\n"
1029+
"\t\t\t\t\t\t);\n"
1030+
"\t\t\t\t\t\tif ( ! $exists_stmt->fetchColumn() ) {\n"
1031+
"\t\t\t\t\t\t\t$errors = array( \"Table '$table_name' doesn't exist\" );\n"
1032+
"\t\t\t\t\t\t\tbreak;\n"
1033+
"\t\t\t\t\t\t}\n"
1034+
"\t\t\t\t\t\t$stmt = $this->execute_sqlite_query(\n"
1035+
"\t\t\t\t\t\t\tsprintf( 'PRAGMA integrity_check(%s)', $quoted_table_name )\n"
1036+
"\t\t\t\t\t\t);\n"
1037+
"\t\t\t\t\t\t$errors = $stmt->fetchAll( PDO::FETCH_COLUMN );\n"
1038+
"\t\t\t\t\t\tif ( 'ok' === $errors[0] ) {\n"
1039+
"\t\t\t\t\t\t\tarray_shift( $errors );\n"
1040+
"\t\t\t\t\t\t}\n"
1041+
"\t\t\t\t\t\tbreak;\n"
1042+
)
1043+
assert old in src, 'CHECK TABLE handler not found'
1044+
open(path, 'w').write(src.replace(old, new, 1))
1045+
print('patched CHECK TABLE missing-table check')
9891046
PY
9901047
9911048
- name: Capture failing SQL from the first failing driver test

0 commit comments

Comments
 (0)