當前位置: 首頁>>代碼示例>>Golang>>正文


Golang variable.BindSessionVars函數代碼示例

本文整理匯總了Golang中github.com/pingcap/tidb/sessionctx/variable.BindSessionVars函數的典型用法代碼示例。如果您正苦於以下問題:Golang BindSessionVars函數的具體用法?Golang BindSessionVars怎麽用?Golang BindSessionVars使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了BindSessionVars函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestSetCharsetStmt

func (s *testStmtSuite) TestSetCharsetStmt(c *C) {
	testSQL := `SET NAMES utf8;`

	stmtList, err := tidb.Compile(testSQL)
	c.Assert(err, IsNil)
	c.Assert(stmtList, HasLen, 1)

	testStmt, ok := stmtList[0].(*stmts.SetCharsetStmt)
	c.Assert(ok, IsTrue)

	c.Assert(testStmt.IsDDL(), IsFalse)
	c.Assert(len(testStmt.OriginText()), Greater, 0)

	ctx := mock.NewContext()
	variable.BindSessionVars(ctx)
	sessionVars := variable.GetSessionVars(ctx)
	for _, v := range variable.SetNamesVariables {
		c.Assert(sessionVars.Systems[v] != "utf8", IsTrue)
	}
	_, err = testStmt.Exec(ctx)
	c.Assert(err, IsNil)
	for _, v := range variable.SetNamesVariables {
		c.Assert(sessionVars.Systems[v], Equals, "utf8")
	}
	c.Assert(sessionVars.Systems[variable.CollationConnection], Equals, "utf8_general_ci")

	mf := newMockFormatter()
	testStmt.Explain(nil, mf)
	c.Assert(mf.Len(), Greater, 0)
}
開發者ID:js-for-kids,項目名稱:tidb,代碼行數:30,代碼來源:set_test.go

示例2: CreateSession

// 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)
	sessionMu.Lock()
	defer sessionMu.Unlock()

	_, ok := storeBootstrapped[store.UUID()]
	if !ok {
		bootstrap(s)
		storeBootstrapped[store.UUID()] = true
	}
	// Add auth here
	return s, nil
}
開發者ID:kevinhuo88888,項目名稱:tidb,代碼行數:26,代碼來源:session.go

示例3: CreateSession

// 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.GlobalVarAccessor. Bind it to ctx.
	variable.BindGlobalVarAccessor(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
}
開發者ID:kkpapa,項目名稱:tidb,代碼行數:36,代碼來源:session.go

示例4: SetUpSuite

func (p *testFromSuit) SetUpSuite(c *C) {
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
	c.Assert(err, IsNil)
	p.vars = map[string]interface{}{}
	p.txn, _ = store.Begin()
	p.cols = []*column.Col{
		{
			ColumnInfo: model.ColumnInfo{
				ID:           0,
				Name:         model.NewCIStr("id"),
				Offset:       0,
				DefaultValue: 0,
				FieldType:    *types.NewFieldType(mysql.TypeLonglong),
			},
		},
		{
			ColumnInfo: model.ColumnInfo{
				ID:           1,
				Name:         model.NewCIStr("name"),
				Offset:       1,
				DefaultValue: nil,
				FieldType:    *types.NewFieldType(mysql.TypeVarchar),
			},
		},
	}
	p.tbl = tables.NewTable(1, "t", "test", p.cols, &simpleAllocator{})
	variable.BindSessionVars(p)

	var i int64
	for i = 0; i < 10; i++ {
		p.tbl.AddRecord(p, []interface{}{i * 10, "hello"})
	}
}
開發者ID:rose1988c,項目名稱:tidb,代碼行數:33,代碼來源:from_test.go

示例5: SetUpSuite

func (p *testShowSuit) SetUpSuite(c *C) {
	nc := mock.NewContext()
	p.ctx = nc
	variable.BindSessionVars(p.ctx)
	variable.BindGlobalVarAccessor(p.ctx, nc)
	variable.RegisterStatistics(p.ms)

	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)

}
開發者ID:kellerli,項目名稱:tidb,代碼行數:33,代碼來源:show_test.go

示例6: SetUpTest

func (s *testStmtSuite) SetUpTest(c *C) {
	log.SetLevelByString("error")
	s.dbName = "teststmts"
	var err error
	s.testDB, err = sql.Open(tidb.DriverName, tidb.EngineGoLevelDBMemory+"/"+s.dbName+"/"+s.dbName)
	c.Assert(err, IsNil)
	// create db
	s.createDBSql = fmt.Sprintf("create database if not exists %s;", s.dbName)
	s.dropDBSql = fmt.Sprintf("drop database if exists %s;", s.dbName)
	s.useDBSql = fmt.Sprintf("use %s;", s.dbName)
	s.createTableSql = `
    CREATE TABLE test(id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id));
    CREATE TABLE test1(id INT NOT NULL DEFAULT 2, name varchar(255), PRIMARY KEY(id), INDEX name(name));
    CREATE TABLE test2(id INT NOT NULL DEFAULT 3, name varchar(255), PRIMARY KEY(id));`

	s.selectSql = `SELECT * from test limit 2;`
	mustExec(c, s.testDB, s.createDBSql)
	mustExec(c, s.testDB, s.useDBSql)

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

	mustExec(c, s.testDB, s.createSystemDBSQL)
	mustExec(c, s.testDB, s.createUserTableSQL)
	mustExec(c, s.testDB, s.createDBPrivTableSQL)
	mustExec(c, s.testDB, s.createTablePrivTableSQL)
	mustExec(c, s.testDB, s.createColumnPrivTableSQL)

	s.ctx = mock.NewContext()
	variable.BindSessionVars(s.ctx)
}
開發者ID:lovedboy,項目名稱:tidb,代碼行數:34,代碼來源:create_test.go

示例7: SetUpSuite

func (p *testShowSuit) SetUpSuite(c *C) {
	var err error
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
	c.Assert(err, IsNil)
	p.ctx = mock.NewContext()
	p.txn, _ = store.Begin()
	variable.BindSessionVars(p.ctx)
}
開發者ID:stumaxim28,項目名稱:tidb,代碼行數:8,代碼來源:show_test.go

示例8: SetUpSuite

func (p *testShowSuit) SetUpSuite(c *C) {
	var err error
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
	c.Assert(err, IsNil)
	p.vars = map[string]interface{}{}
	p.txn, _ = store.Begin()
	variable.BindSessionVars(p)
}
開發者ID:kevinhuo88888,項目名稱:tidb,代碼行數:8,代碼來源:show_test.go

示例9: TestCurrentUser

func (s *testEvaluatorSuite) TestCurrentUser(c *C) {
	ctx := mock.NewContext()
	variable.BindSessionVars(ctx)
	sessionVars := variable.GetSessionVars(ctx)
	sessionVars.User = "[email protected]"

	d, err := builtinCurrentUser(types.MakeDatums(), ctx)
	c.Assert(err, IsNil)
	c.Assert(d.GetString(), Equals, "[email protected]")
}
開發者ID:astaxie,項目名稱:tidb,代碼行數:10,代碼來源:builtin_info_test.go

示例10: TestConnectionID

func (s *testEvaluatorSuite) TestConnectionID(c *C) {
	ctx := mock.NewContext()
	variable.BindSessionVars(ctx)
	sessionVars := variable.GetSessionVars(ctx)
	sessionVars.ConnectionID = uint64(1)

	d, err := builtinConnectionID(types.MakeDatums(), ctx)
	c.Assert(err, IsNil)
	c.Assert(d.GetUint64(), Equals, uint64(1))
}
開發者ID:astaxie,項目名稱:tidb,代碼行數:10,代碼來源:builtin_info_test.go

示例11: CreateSession

// 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),
		debugInfos:  make(map[string]interface{}),
		maxRetryCnt: 10,
		parser:      parser.New(),
	}
	domain, err := domap.Get(store)
	if err != nil {
		return nil, errors.Trace(err)
	}
	sessionctx.BindDomain(s, domain)

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

	// session implements variable.GlobalVarAccessor. Bind it to ctx.
	variable.BindGlobalVarAccessor(s, s)

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

	ver := getStoreBootstrapVersion(store)
	if ver == notBootstrapped {
		// if no bootstrap and storage is remote, we must use a little lease time to
		// bootstrap quickly, after bootstrapped, we will reset the lease time.
		// TODO: Using a bootstap tool for doing this may be better later.
		if !localstore.IsLocalStore(store) {
			sessionctx.GetDomain(s).SetLease(chooseMinLease(100*time.Millisecond, schemaLease))
		}

		s.SetValue(context.Initing, true)
		bootstrap(s)
		s.ClearValue(context.Initing)

		if !localstore.IsLocalStore(store) {
			sessionctx.GetDomain(s).SetLease(schemaLease)
		}

		finishBootstrap(store)
	} else if ver < currentBootstrapVersion {
		s.SetValue(context.Initing, true)
		upgrade(s)
		s.ClearValue(context.Initing)
	}

	// TODO: Add auth here
	privChecker := &privileges.UserPrivileges{}
	privilege.BindPrivilegeChecker(s, privChecker)
	return s, nil
}
開發者ID:jmptrader,項目名稱:tidb,代碼行數:56,代碼來源:session.go

示例12: TestFoundRows

func (s *testEvaluatorSuite) TestFoundRows(c *C) {
	ctx := mock.NewContext()
	d, err := builtinFoundRows(types.MakeDatums(), ctx)
	c.Assert(err, NotNil)

	variable.BindSessionVars(ctx)

	d, err = builtinFoundRows(types.MakeDatums(), ctx)
	c.Assert(err, IsNil)
	c.Assert(d.GetUint64(), Equals, uint64(0))
}
開發者ID:astaxie,項目名稱:tidb,代碼行數:11,代碼來源:builtin_info_test.go

示例13: newMockResolve

func newMockResolve(node ast.Node) error {
	indices := []*model.IndexInfo{
		{
			Name: model.NewCIStr("b"),
			Columns: []*model.IndexColumn{
				{
					Name: model.NewCIStr("b"),
				},
			},
		},
		{
			Name: model.NewCIStr("c_d_e"),
			Columns: []*model.IndexColumn{
				{
					Name: model.NewCIStr("c"),
				},
				{
					Name: model.NewCIStr("d"),
				},
				{
					Name: model.NewCIStr("e"),
				},
			},
		},
	}
	pkColumn := &model.ColumnInfo{
		State: model.StatePublic,
		Name:  model.NewCIStr("a"),
	}
	col0 := &model.ColumnInfo{
		State: model.StatePublic,
		Name:  model.NewCIStr("b"),
	}
	col1 := &model.ColumnInfo{
		State: model.StatePublic,
		Name:  model.NewCIStr("c"),
	}
	col2 := &model.ColumnInfo{
		State: model.StatePublic,
		Name:  model.NewCIStr("d"),
	}
	pkColumn.Flag = mysql.PriKeyFlag
	table := &model.TableInfo{
		Columns:    []*model.ColumnInfo{pkColumn, col0, col1, col2},
		Indices:    indices,
		Name:       model.NewCIStr("t"),
		PKIsHandle: true,
	}
	is := infoschema.MockInfoSchema([]*model.TableInfo{table})
	ctx := mock.NewContext()
	variable.BindSessionVars(ctx)
	return MockResolveName(node, is, "test", ctx)
}
開發者ID:yuyongwei,項目名稱:tidb,代碼行數:53,代碼來源:new_plan_test.go

示例14: SetUpSuite

func (p *testIndexSuit) SetUpSuite(c *C) {
	store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
	c.Assert(err, IsNil)
	p.store = store
	p.vars = map[string]interface{}{}
	p.txn, _ = p.store.Begin()
	p.cols = []*column.Col{
		{
			ColumnInfo: model.ColumnInfo{
				ID:           0,
				Name:         model.NewCIStr("id"),
				Offset:       0,
				DefaultValue: 0,
				FieldType:    *types.NewFieldType(mysql.TypeLonglong),
			},
		},
		{
			ColumnInfo: model.ColumnInfo{
				ID:           1,
				Name:         model.NewCIStr("name"),
				Offset:       1,
				DefaultValue: nil,
				FieldType:    *types.NewFieldType(mysql.TypeVarchar),
			},
		},
	}
	p.tbl = tables.NewTable(2, "t2", "test", p.cols, &simpleAllocator{})

	idxCol := &column.IndexedCol{
		IndexInfo: model.IndexInfo{
			Name:  model.NewCIStr("id"),
			Table: model.NewCIStr("t2"),
			Columns: []*model.IndexColumn{
				{
					Name:   model.NewCIStr("id"),
					Offset: 0,
					Length: 0,
				},
			},
			Unique:  false,
			Primary: false,
		},
		X: kv.NewKVIndex("i", "id", false),
	}
	p.tbl.AddIndex(idxCol)

	variable.BindSessionVars(p)

	var i int64
	for i = 0; i < 10; i++ {
		p.tbl.AddRecord(p, []interface{}{i * 10, "hello"})
	}
}
開發者ID:nengwang,項目名稱:tidb,代碼行數:53,代碼來源:index_test.go

示例15: TestConnectionID

func (s *testBuiltinSuite) TestConnectionID(c *C) {
	ctx := mock.NewContext()
	m := map[interface{}]interface{}{}
	variable.BindSessionVars(ctx)
	sessionVars := variable.GetSessionVars(ctx)
	sessionVars.ConnectionID = uint64(1)

	m[ExprEvalArgCtx] = ctx
	v, err := builtinConnectionID(nil, m)
	c.Assert(err, IsNil)
	c.Assert(v, Equals, uint64(1))
}
開發者ID:lovedboy,項目名稱:tidb,代碼行數:12,代碼來源:info_test.go


注:本文中的github.com/pingcap/tidb/sessionctx/variable.BindSessionVars函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。