mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
fix(database/gdb): strip quote chars from schema in Model.TableFields (#4730)
## Summary When performing cross-database JOINs with soft-delete, the schema name parsed from `` `schema`.`table` `` format retains database-specific quote characters. These quoted schema names break `information_schema` WHERE clause queries in `TableFields` lookups. This PR strips quote characters from `usedSchema` in `Model.TableFields()`, matching the existing unquoting pattern used for `usedTable` via `guessPrimaryTableName`. ## Changes - `database/gdb/gdb_model_utility.go`: Add quote-stripping for `usedSchema` using `gstr.Trim` with database-specific quote chars from `GetChars()` ## Test Existing `Test_Issue2338` in MySQL (`contrib/drivers/mysql/mysql_z_unit_issue_test.go:685`) covers this case. The MariaDB version exists in PR #4724 branch (`contrib/drivers/mariadb/mariadb_z_unit_issue_test.go:688`), not yet merged. Once both PRs are merged, the MariaDB test will also validate this fix. closes #4725 Co-authored-by: John Guo <claymore1986@gmail.com>
This commit is contained in:
@ -37,6 +37,12 @@ func (m *Model) TableFields(tableStr string, schema ...string) (fields map[strin
|
|||||||
usedTable = m.db.GetCore().guessPrimaryTableName(tableStr)
|
usedTable = m.db.GetCore().guessPrimaryTableName(tableStr)
|
||||||
usedSchema = gutil.GetOrDefaultStr(m.schema, schema...)
|
usedSchema = gutil.GetOrDefaultStr(m.schema, schema...)
|
||||||
)
|
)
|
||||||
|
// Strip quote characters from schema name, as it may come from cross-database
|
||||||
|
// table parsing (e.g., `schema`.`table`) and contain database-specific quote chars.
|
||||||
|
charL, charR := m.db.GetChars()
|
||||||
|
if usedSchema != "" && (charL != "" || charR != "") {
|
||||||
|
usedSchema = gstr.Trim(usedSchema, charL+charR)
|
||||||
|
}
|
||||||
// Sharding feature.
|
// Sharding feature.
|
||||||
usedSchema, err = m.getActualSchema(ctx, usedSchema)
|
usedSchema, err = m.getActualSchema(ctx, usedSchema)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user