Repository navigation
fix: resolve schema-qualified table names in getFieldData() and protectIdentifiers() - #10604
paulbalandan wants to merge 1 commit into
Conversation
…otectIdentifiers()`
| private function protectDotItem(string $item, string $alias, bool $protectIdentifiers, bool $fieldExists): string | ||
| { | ||
| $parts = explode('.', $item); | ||
| $parts = array_map(fn (string $part): string => trim($part, $this->escapeChar), explode('.', $item)); |
There was a problem hiding this comment.
With QUOTED_IDENTIFIER OFF, the SQLSRV driver sets $this->escapeChar to ['[', ']']. Passing this array as the second argument to trim() causes a TypeError when processing dotted identifiers. I verified that protectIdentifiers('jobs.id') returned [jobs].[id] before this change and now throws. We should handle the array form of escapeChar and add a regression test.
| private function protectDotItem(string $item, string $alias, bool $protectIdentifiers, bool $fieldExists): string | ||
| { | ||
| $parts = explode('.', $item); | ||
| $parts = array_map(fn (string $part): string => trim($part, $this->escapeChar), explode('.', $item)); |
There was a problem hiding this comment.
This case also failed before the PR, but it appears to be a missing case within the intended fix. With an empty DBPrefix, the normalized $parts are not joined back into $item, so getFieldData('"public"."jobs"') still passes the quotes into the metadata query and returns no columns. Since Query Builder passes protected table names, could we cover this path too and add a test for a quoted, schema-qualified table name with an empty prefix?
Description
getFieldData()returned no fields for a schema-qualified table name (e.g.public.jobs). Found while reviewing #10601 and #10602, whose batch casts depend on it.BaseConnection::protectDotItem()did not strip the escape character before checking for the prefix, so an already protected"tenant"."db_jobs"was prefixed again. The builders pass protected table names togetFieldData(), so every driver got a mangled name.PostgreandSQLSRVignored the schema segment, andSQLite3produced an invalidPRAGMA.MySQLiandOCI8already handled a cleanschema.table.Unqualified names behave as before. Tests cover the
protectIdentifiers()cases andgetFieldData()with a qualified name on all drivers.Checklist: