Skip to content

Commit bb71ccf

Browse files
lingcodergqcn
andauthored
fix(database/gdb): strip quote chars from schema in Model.TableFields (gogf#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 gogf#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 gogf#4725 Co-authored-by: John Guo <claymore1986@gmail.com>
1 parent f67b2dc commit bb71ccf

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

database/gdb/gdb_model_utility.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ func (m *Model) TableFields(tableStr string, schema ...string) (fields map[strin
3737
usedTable = m.db.GetCore().guessPrimaryTableName(tableStr)
3838
usedSchema = gutil.GetOrDefaultStr(m.schema, schema...)
3939
)
40+
// Strip quote characters from schema name, as it may come from cross-database
41+
// table parsing (e.g., `schema`.`table`) and contain database-specific quote chars.
42+
charL, charR := m.db.GetChars()
43+
if usedSchema != "" && (charL != "" || charR != "") {
44+
usedSchema = gstr.Trim(usedSchema, charL+charR)
45+
}
4046
// Sharding feature.
4147
usedSchema, err = m.getActualSchema(ctx, usedSchema)
4248
if err != nil {

0 commit comments

Comments
 (0)