Skip to content

Commit 25dba81

Browse files
author
James Cor
committed
fix and tests
1 parent a95d64c commit 25dba81

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

enginetest/queries/information_schema_queries.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,15 +1158,18 @@ FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'mydb'`,
11581158
SetUpScript: []string{
11591159
"USE foo",
11601160
"drop table othertable",
1161-
"CREATE TABLE t (i int)",
1162-
"CREATE VIEW v as select * from t",
1161+
"CREATE TABLE t (i int primary key, j int)",
1162+
"CREATE VIEW v as select i + 1, j * 2, mod(i, j) from t",
11631163
},
11641164
Assertions: []ScriptTestAssertion{
11651165
{
11661166
Query: "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'foo'",
11671167
Expected: []sql.Row{
1168-
{"def", "foo", "t", "i", uint32(1), nil, "YES", "int", nil, nil, int64(10), int64(0), nil, nil, nil, "int", "", "", "insert,references,select,update", "", "", nil},
1169-
{"def", "foo", "v", "", uint32(0), nil, "", nil, nil, nil, nil, nil, nil, "", "", "", "", "", "select", "", "", nil},
1168+
{"def", "foo", "t", "i", uint32(1), nil, "NO", "int", nil, nil, 10, 0, nil, nil, nil, "int", "PRI", "", "insert,references,select,update", "", "", nil},
1169+
{"def", "foo", "t", "j", uint32(2), nil, "YES", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "", "insert,references,select,update", "", "", nil},
1170+
{"def", "foo", "v", "i + 1", uint32(1), nil, "NO", "bigint", nil, nil, 19, 0, nil, nil, nil, "bigint", "", "", "insert,references,select,update", "", "", nil},
1171+
{"def", "foo", "v", "j * 2", uint32(2), nil, "YES", "bigint", nil, nil, 19, 0, nil, nil, nil, "bigint", "", "", "insert,references,select,update", "", "", nil},
1172+
{"def", "foo", "v", "mod(i, j)", uint32(3), nil, "YES", "decimal", nil, nil, 10, 0, nil, nil, nil, "decimal(10,0)", "", "", "insert,references,select,update", "", "", nil},
11701173
},
11711174
},
11721175
},

sql/information_schema/columns_table.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"github.com/dolthub/go-mysql-server/sql"
3030
"github.com/dolthub/go-mysql-server/sql/mysql_db"
31+
"github.com/dolthub/go-mysql-server/sql/plan"
3132
"github.com/dolthub/go-mysql-server/sql/planbuilder"
3233
"github.com/dolthub/go-mysql-server/sql/transform"
3334
"github.com/dolthub/go-mysql-server/sql/types"
@@ -371,17 +372,19 @@ func getRowsFromViews(ctx *sql.Context, catalog sql.Catalog, db DbWithNames, pri
371372
if err != nil {
372373
return nil, err
373374
}
374-
375-
for i, view := range views {
376-
node, _, err := planbuilder.Parse(ctx, catalog, view.TextDefinition)
375+
privSetDb := privSet.Database(db.Database.Name())
376+
for _, view := range views {
377+
node, _, err := planbuilder.Parse(ctx, catalog, view.CreateViewStatement)
377378
if err != nil {
378-
// TODO: should we error?
379+
continue // sometimes views contains views from other databases
380+
}
381+
createViewNode, ok := node.(*plan.CreateView)
382+
if !ok {
379383
continue
380384
}
381-
privSetDb := privSet.Database(db.Database.Name())
382385
privSetTbl := privSetDb.Table(view.Name)
383386
curPrivSetMap := getCurrentPrivSetMapForColumn(privSetDb.ToSlice(), privSetMap)
384-
for _, col := range node.Schema() {
387+
for i, col := range createViewNode.Definition.Schema() {
385388
r := getRowFromColumn(ctx, i, col, db.CatalogName, db.SchemaName, view.Name, "", privSetTbl, curPrivSetMap)
386389
if r != nil {
387390
rows = append(rows, r)

0 commit comments

Comments
 (0)