Skip to content

Commit 0a8ae2c

Browse files
committed
Restore column-name casing in Turso error messages
Turso lowercases column names in UNIQUE-constraint error messages ("_tmp_table.id" vs SQLite's "_tmp_table.ID"). Extend the existing error-normalizer callback to look up the canonical casing from information_schema.columns and substitute it back. Fixes testAlterTableModifyColumnComplexChange.
1 parent 7ced8d3 commit 0a8ae2c

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,27 @@ jobs:
914914
"\t\t\t\t},\n"
915915
"\t\t\t\t$msg\n"
916916
"\t\t\t);\n"
917+
"\t\t\t// Turso lowercases column names in UNIQUE-constraint errors;\n"
918+
"\t\t\t// restore original casing from information_schema.\n"
919+
"\t\t\t$msg = preg_replace_callback(\n"
920+
"\t\t\t\t'/(\\w+)\\.(\\w+)/',\n"
921+
"\t\t\t\tfunction ( $m ) {\n"
922+
"\t\t\t\t\ttry {\n"
923+
"\t\t\t\t\t\t$cols_table = $this->information_schema_builder->get_table_name( false, 'columns' );\n"
924+
"\t\t\t\t\t\t$canonical = $this->execute_sqlite_query(\n"
925+
"\t\t\t\t\t\t\tsprintf(\n"
926+
"\t\t\t\t\t\t\t\t'SELECT column_name FROM %s WHERE table_name = ? AND lower(column_name) = ?',\n"
927+
"\t\t\t\t\t\t\t\t$this->quote_sqlite_identifier( $cols_table )\n"
928+
"\t\t\t\t\t\t\t),\n"
929+
"\t\t\t\t\t\t\tarray( $m[1], strtolower( $m[2] ) )\n"
930+
"\t\t\t\t\t\t)->fetchColumn();\n"
931+
"\t\t\t\t\t\treturn $m[1] . '.' . ( $canonical !== false ? $canonical : $m[2] );\n"
932+
"\t\t\t\t\t} catch ( \\Throwable $_ ) {\n"
933+
"\t\t\t\t\t\treturn $m[0];\n"
934+
"\t\t\t\t\t}\n"
935+
"\t\t\t\t},\n"
936+
"\t\t\t\t$msg\n"
937+
"\t\t\t);\n"
917938
"\t\t\tthrow $this->new_driver_exception( $msg, $e->getCode(), $e );"
918939
)
919940
assert old in src, 'rethrow block not found'

0 commit comments

Comments
 (0)