Skip to content

Commit a9f8e32

Browse files
authored
Merge pull request #3029 from dolthub/elianddb/fix-9347-panic-case-statements-info-schema
Fix 9347 panic case statements info schema
2 parents 8dd259f + 2a472df commit a9f8e32

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

enginetest/queries/information_schema_queries.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ var InfoSchemaQueries = []QueryTest{
3030
Query: "SHOW KEYS FROM `columns` FROM `information_schema`;",
3131
Expected: []sql.Row{},
3232
},
33+
{
34+
Query: `SELECT table_schema AS TABLE_CAT,
35+
NULL AS TABLE_SCHEM,
36+
table_name,
37+
CASE WHEN table_type = 'BASE TABLE' THEN
38+
CASE WHEN table_schema = 'mysql' OR table_schema = 'performance_schema' THEN 'SYSTEM TABLE'
39+
ELSE 'TABLE' END
40+
WHEN table_type = 'TEMPORARY' THEN 'LOCAL_TEMPORARY'
41+
ELSE table_type END AS TABLE_TYPE FROM information_schema.tables ORDER BY table_name LIMIT 1;`,
42+
Expected: []sql.Row{{"information_schema", nil, "administrable_role_authorizations", "SYSTEM VIEW"}},
43+
},
3344
{
3445
Query: `SELECT
3546
table_name, index_name, comment, non_unique, GROUP_CONCAT(column_name ORDER BY seq_in_index) AS COLUMNS

sql/expression/enum.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,19 @@ func (e *EnumToString) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
6969
}
7070

7171
enumType := e.Enum.Type().(types.EnumType)
72-
str, _ := enumType.At(int(val.(uint16)))
72+
var str string
73+
val, err = sql.UnwrapAny(ctx, val)
74+
if err != nil {
75+
return nil, err
76+
}
77+
switch v := val.(type) {
78+
case uint16:
79+
str, _ = enumType.At(int(v))
80+
case string:
81+
str = v
82+
default:
83+
return nil, sql.ErrInvalidType.New(val, types.Text)
84+
}
7385
return str, nil
7486
}
7587

sql/information_schema/tables_table.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var tablesSchema = Schema{
6565
func tablesRowIter(ctx *Context, cat Catalog) (RowIter, error) {
6666
var rows []Row
6767
var (
68-
tableType string
68+
tableType uint16
6969
tableRows uint64
7070
avgRowLength uint64
7171
dataLength uint64
@@ -82,9 +82,9 @@ func tablesRowIter(ctx *Context, cat Catalog) (RowIter, error) {
8282

8383
for _, db := range databases {
8484
if db.Database.Name() == InformationSchemaDatabaseName {
85-
tableType = "SYSTEM VIEW"
85+
tableType = 3 // SYSTEM_VIEW
8686
} else {
87-
tableType = "BASE TABLE"
87+
tableType = 1 // BASE_TABLE
8888
engine = "InnoDB"
8989
rowFormat = "Dynamic"
9090
}

0 commit comments

Comments
 (0)