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)