fix(mysql): 表列表排除视图 refs bug#375

This commit is contained in:
jonclex
2026-04-15 10:06:44 +08:00
parent f78b132c7c
commit 737896627a
2 changed files with 10 additions and 4 deletions

View File

@@ -185,9 +185,12 @@ func (m *MariaDB) GetDatabases() ([]string, error) {
}
func (m *MariaDB) GetTables(dbName string) ([]string, error) {
query := "SHOW TABLES"
query := "SELECT TABLE_NAME FROM information_schema.tables WHERE TABLE_SCHEMA = DATABASE() AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME"
if dbName != "" {
query = fmt.Sprintf("SHOW TABLES FROM `%s`", dbName)
query = fmt.Sprintf(
"SELECT TABLE_NAME FROM information_schema.tables WHERE TABLE_SCHEMA = '%s' AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME",
strings.ReplaceAll(dbName, "'", "''"),
)
}
data, _, err := m.Query(query)

View File

@@ -424,9 +424,12 @@ func (m *MySQLDB) GetDatabases() ([]string, error) {
}
func (m *MySQLDB) GetTables(dbName string) ([]string, error) {
query := "SHOW TABLES"
query := "SELECT TABLE_NAME FROM information_schema.tables WHERE TABLE_SCHEMA = DATABASE() AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME"
if dbName != "" {
query = fmt.Sprintf("SHOW TABLES FROM `%s`", dbName)
query = fmt.Sprintf(
"SELECT TABLE_NAME FROM information_schema.tables WHERE TABLE_SCHEMA = '%s' AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME",
strings.ReplaceAll(dbName, "'", "''"),
)
}
data, _, err := m.Query(query)