Beispiel #1
0
// Create a new session on store but only do ddl works.
func (s *testSessionSuite) bootstrapWithOnlyDDLWork(store kv.Storage, c *C) {
	ss := &session{
		values:      make(map[fmt.Stringer]interface{}),
		store:       store,
		parser:      parser.New(),
		sessionVars: variable.NewSessionVars(),
	}
	ss.SetValue(context.Initing, true)
	domain, err := domap.Get(store)
	c.Assert(err, IsNil)
	sessionctx.BindDomain(ss, domain)
	sessionMu.Lock()
	defer sessionMu.Unlock()
	b, err := checkBootstrapped(ss)
	c.Assert(b, IsFalse)
	c.Assert(err, IsNil)
	doDDLWorks(ss)
	// Leave dml unfinished.
}
Beispiel #2
0
func (s *testVarsutilSuite) TestVarsutil(c *C) {
	defer testleak.AfterTest(c)()
	v := variable.NewSessionVars()

	SetSystemVar(v, "autocommit", types.NewStringDatum("1"))
	val := GetSystemVar(v, "autocommit")
	c.Assert(val.GetString(), Equals, "1")
	c.Assert(SetSystemVar(v, "autocommit", types.Datum{}), NotNil)

	SetSystemVar(v, "sql_mode", types.NewStringDatum("strict_trans_tables"))
	val = GetSystemVar(v, "sql_mode")
	c.Assert(val.GetString(), Equals, "STRICT_TRANS_TABLES")
	c.Assert(v.StrictSQLMode, IsTrue)
	SetSystemVar(v, "sql_mode", types.NewStringDatum(""))
	c.Assert(v.StrictSQLMode, IsFalse)

	SetSystemVar(v, "character_set_connection", types.NewStringDatum("utf8"))
	SetSystemVar(v, "collation_connection", types.NewStringDatum("utf8_general_ci"))
	charset, collation := v.GetCharsetInfo()
	c.Assert(charset, Equals, "utf8")
	c.Assert(collation, Equals, "utf8_general_ci")

	c.Assert(SetSystemVar(v, "character_set_results", types.Datum{}), IsNil)

	// Test case for get TiDBSkipConstraintCheck session variable
	d := GetSystemVar(v, variable.TiDBSkipConstraintCheck)
	c.Assert(d.GetString(), Equals, "0")

	// Test case for tidb_skip_constraint_check
	c.Assert(v.SkipConstraintCheck, IsFalse)
	SetSystemVar(v, variable.TiDBSkipConstraintCheck, types.NewStringDatum("0"))
	c.Assert(v.SkipConstraintCheck, IsFalse)
	SetSystemVar(v, variable.TiDBSkipConstraintCheck, types.NewStringDatum("1"))
	c.Assert(v.SkipConstraintCheck, IsTrue)
	SetSystemVar(v, variable.TiDBSkipConstraintCheck, types.NewStringDatum("0"))
	c.Assert(v.SkipConstraintCheck, IsFalse)

	// Test case for change TiDBSkipConstraintCheck session variable.
	SetSystemVar(v, variable.TiDBSkipConstraintCheck, types.NewStringDatum("1"))
	d = GetSystemVar(v, variable.TiDBSkipConstraintCheck)
	c.Assert(d.GetString(), Equals, "1")
}
Beispiel #3
0
func createSession(store kv.Storage) (*session, error) {
	s := &session{
		values:      make(map[fmt.Stringer]interface{}),
		store:       store,
		maxRetryCnt: 10,
		parser:      parser.New(),
		sessionVars: variable.NewSessionVars(),
	}
	domain, err := domap.Get(store)
	if err != nil {
		return nil, errors.Trace(err)
	}
	sessionctx.BindDomain(s, domain)
	// session implements variable.GlobalVarAccessor. Bind it to ctx.
	s.sessionVars.GlobalVarsAccessor = s

	// TODO: Add auth here
	privChecker := &privileges.UserPrivileges{}
	privilege.BindPrivilegeChecker(s, privChecker)
	return s, nil
}
Beispiel #4
0
// NewContext creates a new mocked context.Context.
func NewContext() *Context {
	return &Context{
		values:      make(map[fmt.Stringer]interface{}),
		sessionVars: variable.NewSessionVars(),
	}
}