From 737896627a67aa5de2a533dffd08e888f4226206 Mon Sep 17 00:00:00 2001 From: jonclex Date: Wed, 15 Apr 2026 10:06:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(mysql):=20=E8=A1=A8=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=8E=92=E9=99=A4=E8=A7=86=E5=9B=BE=20refs=20bug#375?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/mariadb_impl.go | 7 +++++-- internal/db/mysql_impl.go | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/db/mariadb_impl.go b/internal/db/mariadb_impl.go index c13e83b..e2f59e0 100644 --- a/internal/db/mariadb_impl.go +++ b/internal/db/mariadb_impl.go @@ -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) diff --git a/internal/db/mysql_impl.go b/internal/db/mysql_impl.go index d93e1f1..0e9071f 100644 --- a/internal/db/mysql_impl.go +++ b/internal/db/mysql_impl.go @@ -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)