Пример #1
0
// CreateSession creates a new session environment.
func CreateSession(store kv.Storage) (Session, error) {
	s := &session{
		values: make(map[fmt.Stringer]interface{}),
		store:  store,
		sid:    atomic.AddInt64(&sessionID, 1),
	}
	domain, err := domap.Get(store)
	if err != nil {
		return nil, err
	}
	sessionctx.BindDomain(s, domain)

	variable.BindSessionVars(s)
	variable.GetSessionVars(s).SetStatusFlag(mysql.ServerStatusAutocommit, true)

	// session implements variable.GlobalSysVarAccessor. Bind it to ctx.
	variable.BindGlobalSysVarAccessor(s, s)

	// session implements autocommit.Checker. Bind it to ctx
	autocommit.BindAutocommitChecker(s, s)
	sessionMu.Lock()
	defer sessionMu.Unlock()

	_, ok := storeBootstrapped[store.UUID()]
	if !ok {
		s.initing = true
		bootstrap(s)
		s.initing = false
		storeBootstrapped[store.UUID()] = true
	}
	// TODO: Add auth here
	privChecker := &privileges.UserPrivileges{}
	privilege.BindPrivilegeChecker(s, privChecker)
	return s, nil
}
Пример #2
0
func (p *testShowSuit) SetUpSuite(c *C) {
	nc := mock.NewContext()
	p.ctx = nc
	variable.BindSessionVars(p.ctx)
	variable.BindGlobalSysVarAccessor(p.ctx, nc)

	p.dbName = "testshowplan"
	p.store = newStore(c, p.dbName)
	p.txn, _ = p.store.Begin()
	se := newSession(c, p.store, p.dbName)
	p.createDBSQL = fmt.Sprintf("create database if not exists %s;", p.dbName)
	p.dropDBSQL = fmt.Sprintf("drop database if exists %s;", p.dbName)
	p.useDBSQL = fmt.Sprintf("use %s;", p.dbName)
	p.createTableSQL = `CREATE TABLE test(id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id));`

	mustExecSQL(c, se, p.createDBSQL)
	mustExecSQL(c, se, p.useDBSQL)
	mustExecSQL(c, se, p.createTableSQL)

	p.createSystemDBSQL = fmt.Sprintf("create database if not exists %s;", mysql.SystemDB)
	p.createUserTableSQL = tidb.CreateUserTable
	p.createDBPrivTableSQL = tidb.CreateDBPrivTable
	p.createTablePrivTableSQL = tidb.CreateTablePrivTable
	p.createColumnPrivTableSQL = tidb.CreateColumnPrivTable

	mustExecSQL(c, se, p.createSystemDBSQL)
	mustExecSQL(c, se, p.createUserTableSQL)
	mustExecSQL(c, se, p.createDBPrivTableSQL)
	mustExecSQL(c, se, p.createTablePrivTableSQL)
	mustExecSQL(c, se, p.createColumnPrivTableSQL)

}
Пример #3
0
func (s *testVariableSuite) SetUpSuite(c *C) {
	nc := mock.NewContext()
	s.ctx = nc
	variable.BindSessionVars(s.ctx)
	variable.BindGlobalSysVarAccessor(s.ctx, nc)
}