Ejemplo n.º 1
0
func (ts *testNameResolverSuite) TestNameResolver(c *C) {
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
	c.Assert(err, IsNil)
	defer store.Close()
	testKit := testkit.NewTestKit(c, store)
	testKit.MustExec("use test")
	testKit.MustExec("create table t1 (c1 int, c2 int)")
	testKit.MustExec("create table t2 (c1 int, c2 int)")
	testKit.MustExec("create table t3 (c1 int, c2 int)")
	ctx := testKit.Se.(context.Context)
	domain := sessionctx.GetDomain(ctx)
	db.BindCurrentSchema(ctx, "test")
	for _, tc := range resolverTestCases {
		node, err := parser.ParseOneStmt(tc.src, "", "")
		c.Assert(err, IsNil)
		resolveErr := plan.ResolveName(node, domain.InfoSchema(), ctx)
		if tc.valid {
			c.Assert(resolveErr, IsNil)
			verifier := &resolverVerifier{c: c, src: tc.src}
			node.Accept(verifier)
		} else {
			c.Assert(resolveErr, NotNil, Commentf("%s", tc.src))
		}
	}
}
Ejemplo n.º 2
0
Archivo: use.go Proyecto: ninefive/tidb
// Exec implements the stmt.Statement Exec interface.
func (s *UseStmt) Exec(ctx context.Context) (_ rset.Recordset, err error) {
	dbname := model.NewCIStr(s.DBName)
	if !sessionctx.GetDomain(ctx).InfoSchema().SchemaExists(dbname) {
		return nil, errors.ErrDatabaseNotExist
	}
	db.BindCurrentSchema(ctx, dbname.O)
	return nil, nil
}
Ejemplo n.º 3
0
Archivo: use.go Proyecto: lovedboy/tidb
// Exec implements the stmt.Statement Exec interface.
func (s *UseStmt) Exec(ctx context.Context) (_ rset.Recordset, err error) {
	dbname := model.NewCIStr(s.DBName)
	dbinfo, exists := sessionctx.GetDomain(ctx).InfoSchema().SchemaByName(dbname)
	if !exists {
		return nil, infoschema.DatabaseNotExists.Gen("database %s not exists", dbname)
	}
	db.BindCurrentSchema(ctx, dbname.O)
	s.updateSysVars(ctx, dbinfo)
	return nil, nil
}
Ejemplo n.º 4
0
func (s *testEvaluatorSuite) TestDatabase(c *C) {
	ctx := mock.NewContext()
	d, err := builtinDatabase(types.MakeDatums(), ctx)
	c.Assert(err, IsNil)
	c.Assert(d.Kind(), Equals, types.KindNull)

	db.BindCurrentSchema(ctx, "test")
	d, err = builtinDatabase(types.MakeDatums(), ctx)
	c.Assert(err, IsNil)
	c.Assert(d.GetString(), Equals, "test")
}
Ejemplo n.º 5
0
func (e *SimpleExec) executeUse(s *ast.UseStmt) error {
	dbname := model.NewCIStr(s.DBName)
	dbinfo, exists := sessionctx.GetDomain(e.ctx).InfoSchema().SchemaByName(dbname)
	if !exists {
		return infoschema.DatabaseNotExists.Gen("database %s not exists", dbname)
	}
	db.BindCurrentSchema(e.ctx, dbname.O)
	// character_set_database is the character set used by the default database.
	// The server sets this variable whenever the default database changes.
	// See: http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_character_set_database
	sessionVars := variable.GetSessionVars(e.ctx)
	sessionVars.Systems[variable.CharsetDatabase] = dbinfo.Charset
	sessionVars.Systems[variable.CollationDatabase] = dbinfo.Collate
	return nil
}
Ejemplo n.º 6
0
func (s *testBuiltinSuite) TestDatabase(c *C) {
	ctx := newMockCtx()
	m := map[interface{}]interface{}{}
	v, err := builtinDatabase(nil, m)
	c.Assert(err, NotNil)

	m[ExprEvalArgCtx] = ctx
	v, err = builtinDatabase(nil, m)
	c.Assert(err, IsNil)
	c.Assert(v, IsNil)

	db.BindCurrentSchema(ctx, "test")
	v, err = builtinDatabase(nil, m)
	c.Assert(err, IsNil)
	c.Assert(v, Equals, "test")
}
Ejemplo n.º 7
0
func (*testSuite) TestT(c *C) {
	var ident = ast.Ident{
		Name: model.NewCIStr("t"),
	}
	c.Assert(ident.String(), Not(Equals), "")
	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Assert(err, IsNil)
	se, err := tidb.CreateSession(store)
	c.Assert(err, IsNil)
	ctx := se.(context.Context)
	db.BindCurrentSchema(ctx, "test")
	fullIdent := ident.Full(ctx)
	c.Assert(fullIdent.Schema.L, Equals, "test")
	c.Assert(fullIdent.Name.L, Equals, "t")
	c.Assert(fullIdent.String(), Not(Equals), "")
	fullIdent2 := fullIdent.Full(ctx)
	c.Assert(fullIdent2.Schema.L, Equals, fullIdent.Schema.L)
}