diff --git a/enginetest/queries/information_schema_queries.go b/enginetest/queries/information_schema_queries.go index b3540bc199..2c25849fce 100644 --- a/enginetest/queries/information_schema_queries.go +++ b/enginetest/queries/information_schema_queries.go @@ -30,6 +30,17 @@ var InfoSchemaQueries = []QueryTest{ Query: "SHOW KEYS FROM `columns` FROM `information_schema`;", Expected: []sql.Row{}, }, + { + Query: `SELECT table_schema AS TABLE_CAT, + NULL AS TABLE_SCHEM, + table_name, + CASE WHEN table_type = 'BASE TABLE' THEN + CASE WHEN table_schema = 'mysql' OR table_schema = 'performance_schema' THEN 'SYSTEM TABLE' + ELSE 'TABLE' END + WHEN table_type = 'TEMPORARY' THEN 'LOCAL_TEMPORARY' + ELSE table_type END AS TABLE_TYPE FROM information_schema.tables ORDER BY table_name LIMIT 1;`, + Expected: []sql.Row{{"information_schema", nil, "administrable_role_authorizations", "SYSTEM VIEW"}}, + }, { Query: `SELECT table_name, index_name, comment, non_unique, GROUP_CONCAT(column_name ORDER BY seq_in_index) AS COLUMNS diff --git a/sql/expression/enum.go b/sql/expression/enum.go index 8637863bc7..36b4af9c22 100644 --- a/sql/expression/enum.go +++ b/sql/expression/enum.go @@ -69,7 +69,19 @@ func (e *EnumToString) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) } enumType := e.Enum.Type().(types.EnumType) - str, _ := enumType.At(int(val.(uint16))) + var str string + val, err = sql.UnwrapAny(ctx, val) + if err != nil { + return nil, err + } + switch v := val.(type) { + case uint16: + str, _ = enumType.At(int(v)) + case string: + str = v + default: + return nil, sql.ErrInvalidType.New(val, types.Text) + } return str, nil } diff --git a/sql/information_schema/tables_table.go b/sql/information_schema/tables_table.go index 1edd99d057..b3f80dc7b6 100644 --- a/sql/information_schema/tables_table.go +++ b/sql/information_schema/tables_table.go @@ -65,7 +65,7 @@ var tablesSchema = Schema{ func tablesRowIter(ctx *Context, cat Catalog) (RowIter, error) { var rows []Row var ( - tableType string + tableType uint16 tableRows uint64 avgRowLength uint64 dataLength uint64 @@ -82,9 +82,9 @@ func tablesRowIter(ctx *Context, cat Catalog) (RowIter, error) { for _, db := range databases { if db.Database.Name() == InformationSchemaDatabaseName { - tableType = "SYSTEM VIEW" + tableType = 3 // SYSTEM_VIEW } else { - tableType = "BASE TABLE" + tableType = 1 // BASE_TABLE engine = "InnoDB" rowFormat = "Dynamic" }