Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions sqle/driver/mysql/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,28 @@ func (c *Executor) ShowDatabases(ignoreSysDatabase bool) ([]string, error) {
+------------+------------------+
*/
func (c *Executor) ShowSchemaTables(schema string) ([]string, error) {
query := fmt.Sprintf(
"select TABLE_NAME from information_schema.tables where table_schema='%s' and TABLE_TYPE in ('BASE TABLE','SYSTEM VIEW')", schema)
return c.showSchemaObjects(schema, "'BASE TABLE'", "'SYSTEM VIEW'")
}

func (c *Executor) ShowAllSchemaObjects(schema string) ([]string, error) {
return c.showSchemaObjects(schema)
}

func (c *Executor) showSchemaObjects(schema string, objects ...string) ([]string, error) {
var query string
if c.IsLowerCaseTableNames() {
schema = strings.ToLower(schema)
query = fmt.Sprintf(
"select TABLE_NAME from information_schema.tables where lower(table_schema)='%s' and TABLE_TYPE in ('BASE TABLE','SYSTEM VIEW')", schema)

if len(objects) == 0 {
query = fmt.Sprintf("select TABLE_NAME from information_schema.tables where lower(table_schema)='%s'", schema)
} else {
query = fmt.Sprintf("select TABLE_NAME from information_schema.tables where lower(table_schema)='%s' and TABLE_TYPE in (%s)", schema, strings.Join(objects, ","))
}
} else {
if len(objects) == 0 {
query = fmt.Sprintf("select TABLE_NAME from information_schema.tables where table_schema='%s'", schema)
} else {
query = fmt.Sprintf("select TABLE_NAME from information_schema.tables where table_schema='%s' and TABLE_TYPE in (%s)", schema, strings.Join(objects, ","))
}
}
result, err := c.Db.Query(query)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion sqle/driver/mysql/session/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (c *Context) IsTableExist(stmt *ast.TableName) (bool, error) {
return false, nil
}

tables, err := c.e.ShowSchemaTables(schemaName)
tables, err := c.e.ShowAllSchemaObjects(schemaName)
if err != nil {
return false, err
}
Expand Down
Loading