Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
beihaiguaishou committed Jan 12, 2021
1 parent a65d37d commit 23a16c4
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions table/tables/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (

. "github.com/pingcap/check"
"github.com/pingcap/errors"
"github.com/pingcap/parser/auth"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta/autoid"
Expand Down Expand Up @@ -670,3 +672,34 @@ func (ts *testSuite) TestConstraintCheckForUniqueIndex(c *C) {
// The data in channel is 1 means tk2 is blocked, that's the expected behavior.
c.Assert(<-ch, Equals, 1)
}

func (ts *testSuite) TestViewColumns(c *C) {
se, err := session.CreateSession4Test(ts.store)
c.Assert(err, IsNil)
c.Assert(se.Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil), IsTrue)
tk := testkit.NewTestKitWithSession(c, ts.store, se)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int primary key, b varchar(20))")
tk.MustExec("drop view if exists v")
tk.MustExec("create view v as select * from t")
tk.MustExec("drop view if exists va")
tk.MustExec("create view va as select count(a) from t")
testCases := []struct {
query string
expected []string
}{
{"select data_type from INFORMATION_SCHEMA.columns where table_name = 'v'", []string{types.TypeToStr(mysql.TypeLong, ""), types.TypeToStr(mysql.TypeVarchar, "")}},
{"select data_type from INFORMATION_SCHEMA.columns where table_name = 'va'", []string{types.TypeToStr(mysql.TypeLonglong, "")}},
}
for _, testCase := range testCases {
tk.MustQuery(testCase.query).Check(testutil.RowsWithSep("|", testCase.expected...))
}
tk.MustExec("drop table if exists t")
for _, testCase := range testCases {
c.Assert(tk.MustQuery(testCase.query).Rows(), HasLen, 0)
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|",
"Warning|1356|View 'test.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them",
"Warning|1356|View 'test.va' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them"))
}
}

0 comments on commit 23a16c4

Please sign in to comment.