本文整理汇总了Golang中github.com/pingcap/tidb/sessionctx/variable.BindSessionVars函数的典型用法代码示例。如果您正苦于以下问题:Golang BindSessionVars函数的具体用法?Golang BindSessionVars怎么用?Golang BindSessionVars使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BindSessionVars函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: TestCurrentUser
func (s *testBuiltinSuite) TestCurrentUser(c *C) {
ctx := mock.NewContext()
m := map[interface{}]interface{}{}
variable.BindSessionVars(ctx)
sessionVars := variable.GetSessionVars(ctx)
sessionVars.User = "[email protected]"
m[ExprEvalArgCtx] = ctx
v, err := builtinCurrentUser(nil, m)
c.Assert(err, IsNil)
c.Assert(v, Equals, "[email protected]")
}
开发者ID:lovedboy,项目名称:tidb,代码行数:12,代码来源:info_test.go
示例17: TestFoundRows
func (s *testBuiltinSuite) TestFoundRows(c *C) {
ctx := newMockCtx()
m := map[interface{}]interface{}{}
v, err := builtinFoundRows(nil, m)
c.Assert(err, NotNil)
variable.BindSessionVars(ctx)
m[ExprEvalArgCtx] = ctx
v, err = builtinFoundRows(nil, m)
c.Assert(err, IsNil)
c.Assert(v, Equals, uint64(0))
}
开发者ID:hxiaodon,项目名称:tidb,代码行数:13,代码来源:builtin_info_test.go
示例18: 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).SetStatus(mysql.ServerStatusAutocommit)
return s, nil
}
开发者ID:ninefive,项目名称:tidb,代码行数:17,代码来源:session.go
示例19: TestExplain
func (s *testStmtSuite) TestExplain(c *C) {
testSQL := "explain select 1"
stmtList, err := tidb.Compile(s.ctx, testSQL)
c.Assert(err, IsNil)
c.Assert(stmtList, HasLen, 1)
testStmt, ok := stmtList[0].(*stmts.ExplainStmt)
c.Assert(ok, IsTrue)
c.Assert(testStmt.IsDDL(), IsFalse)
c.Assert(len(testStmt.OriginText()), Greater, 0)
newTestSql := "explain " + testSQL
newTestStmt := &stmts.ExplainStmt{S: testStmt, Text: newTestSql}
mf := newMockFormatter()
ctx := mock.NewContext()
variable.BindSessionVars(ctx)
newTestStmt.Explain(ctx, mf)
c.Assert(mf.Len(), Greater, 0)
_, err = testStmt.Exec(ctx)
c.Assert(err, IsNil)
showColumnSQL := "desc t;"
stmtList, err = tidb.Compile(s.ctx, showColumnSQL)
c.Assert(err, IsNil)
c.Assert(stmtList, HasLen, 1)
testStmt, ok = stmtList[0].(*stmts.ExplainStmt)
c.Assert(ok, IsTrue)
showStmt, ok := testStmt.S.(*stmts.ShowStmt)
c.Assert(ok, IsTrue)
// Mock DBName for ShowStmt
showStmt.DBName = "test"
mf = newMockFormatter()
testStmt.Explain(ctx, mf)
c.Assert(mf.Len(), Greater, 0)
_, err = testStmt.Exec(ctx)
c.Assert(err, IsNil)
}
开发者ID:lovedboy,项目名称:tidb,代码行数:47,代码来源:explain_test.go
示例20: TestSession
func (*testSessionSuite) TestSession(c *C) {
ctx := mock.NewContext()
variable.BindSessionVars(ctx)
v := variable.GetSessionVars(ctx)
c.Assert(v, NotNil)
// For AffectedRows
v.AddAffectedRows(1)
c.Assert(v.AffectedRows, Equals, uint64(1))
v.AddAffectedRows(1)
c.Assert(v.AffectedRows, Equals, uint64(2))
// For FoundRows
v.AddFoundRows(1)
c.Assert(v.FoundRows, Equals, uint64(1))
v.AddFoundRows(1)
c.Assert(v.FoundRows, Equals, uint64(2))
// For last insert id
v.SetLastInsertID(uint64(1))
c.Assert(v.LastInsertID, Equals, uint64(1))
v.SetSystemVar("autocommit", types.NewStringDatum("1"))
val := v.GetSystemVar("autocommit")
c.Assert(val.GetString(), Equals, "1")
c.Assert(v.SetSystemVar("autocommit", types.Datum{}), NotNil)
v.SetSystemVar("sql_mode", types.NewStringDatum("strict_trans_tables"))
val = v.GetSystemVar("sql_mode")
c.Assert(val.GetString(), Equals, "STRICT_TRANS_TABLES")
c.Assert(v.StrictSQLMode, IsTrue)
v.SetSystemVar("sql_mode", types.NewStringDatum(""))
c.Assert(v.StrictSQLMode, IsFalse)
v.SetSystemVar("character_set_connection", types.NewStringDatum("utf8"))
v.SetSystemVar("collation_connection", types.NewStringDatum("utf8_general_ci"))
charset, collation := variable.GetCharsetInfo(ctx)
c.Assert(charset, Equals, "utf8")
c.Assert(collation, Equals, "utf8_general_ci")
c.Assert(v.SetSystemVar("character_set_results", types.Datum{}), IsNil)
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:44,代码来源:session_test.go
注:本文中的github.com/pingcap/tidb/sessionctx/variable.BindSessionVars函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论