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


Golang db.GetCurrentSchema函數代碼示例

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


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

示例1: Next

// Next implements Executor Next interface.
func (e *CheckTableExec) Next() (*Row, error) {
	if e.done {
		return nil, nil
	}

	dbName := model.NewCIStr(db.GetCurrentSchema(e.ctx))
	is := sessionctx.GetDomain(e.ctx).InfoSchema()

	for _, t := range e.tables {
		tb, err := is.TableByName(dbName, t.Name)
		if err != nil {
			return nil, errors.Trace(err)
		}
		for _, idx := range tb.Indices() {
			txn, err := e.ctx.GetTxn(false)
			if err != nil {
				return nil, errors.Trace(err)
			}
			err = inspectkv.CompareIndexData(txn, tb, idx)
			if err != nil {
				return nil, errors.Errorf("%v err:%v", t.Name, err)
			}
		}
	}
	e.done = true

	return nil, nil
}
開發者ID:XuHuaiyu,項目名稱:tidb,代碼行數:29,代碼來源:executor.go

示例2: builtinDatabase

// See https://dev.mysql.com/doc/refman/5.7/en/information-functions.html
func builtinDatabase(args []types.Datum, ctx context.Context) (d types.Datum, err error) {
	s := db.GetCurrentSchema(ctx)
	if s == "" {
		return d, nil
	}
	d.SetString(s)
	return d, nil
}
開發者ID:XuHuaiyu,項目名稱:tidb,代碼行數:9,代碼來源:builtin_info.go

示例3: getDBName

func (r *ShowRset) getDBName(ctx context.Context) string {
	if len(r.DBName) > 0 {
		return r.DBName
	}

	// if r.DBName is empty, we should use current db name if possible.
	return db.GetCurrentSchema(ctx)
}
開發者ID:rose1988c,項目名稱:tidb,代碼行數:8,代碼來源:show.go

示例4: Full

// Full returns an Ident which set schema to the current schema if it is empty.
func (i Ident) Full(ctx context.Context) (full Ident) {
	full.Name = i.Name
	if i.Schema.O != "" {
		full.Schema = i.Schema
	} else {
		full.Schema = model.NewCIStr(db.GetCurrentSchema(ctx))
	}
	return
}
開發者ID:anywhy,項目名稱:tidb,代碼行數:10,代碼來源:misc.go

示例5: String

func (s *session) String() string {
	// TODO: how to print binded context in values appropriately?
	data := map[string]interface{}{
		"userName":   s.userName,
		"currDBName": db.GetCurrentSchema(s),
		"sid":        s.sid,
		"txn":        s.txn.String(),
	}

	b, _ := json.MarshalIndent(data, "", "  ")
	return string(b)
}
開發者ID:ninefive,項目名稱:tidb,代碼行數:12,代碼來源:session.go

示例6: builtinDatabase

func builtinDatabase(args []interface{}, data map[interface{}]interface{}) (v interface{}, err error) {
	c, ok := data[ExprEvalArgCtx]
	if !ok {
		return nil, errors.Errorf("Missing ExprEvalArgCtx when evalue builtin")
	}
	ctx := c.(context.Context)
	d := db.GetCurrentSchema(ctx)
	if d == "" {
		return nil, nil
	}
	return d, nil
}
開發者ID:rose1988c,項目名稱:tidb,代碼行數:12,代碼來源:builtin.go

示例7: getDBName

func (s *ShowStmt) getDBName(ctx context.Context) string {
	if len(s.DBName) > 0 {
		return s.DBName
	}

	// maybe db.table format
	if len(s.TableIdent.Schema.O) > 0 {
		return s.TableIdent.Schema.O
	}

	// try use current db name if possible.
	return db.GetCurrentSchema(ctx)
}
開發者ID:lovedboy,項目名稱:tidb,代碼行數:13,代碼來源:show.go

示例8: String

func (s *session) String() string {
	// TODO: how to print binded context in values appropriately?
	data := map[string]interface{}{
		"currDBName": db.GetCurrentSchema(s),
		"sid":        s.sid,
	}

	if s.txn != nil {
		// if txn is committed or rolled back, txn is nil.
		data["txn"] = s.txn.String()
	}

	b, _ := json.MarshalIndent(data, "", "  ")
	return string(b)
}
開發者ID:losas,項目名稱:tidb,代碼行數:15,代碼來源:session.go

示例9: getTargetSchema

// Find the schema by dbName.
func (e *GrantExec) getTargetSchema() (*model.DBInfo, error) {
	dbName := e.Level.DBName
	if len(dbName) == 0 {
		// Grant *, use current schema
		dbName = db.GetCurrentSchema(e.ctx)
		if len(dbName) == 0 {
			return nil, errors.New("Miss DB name for grant privilege.")
		}
	}
	//check if db exists
	schema := model.NewCIStr(dbName)
	is := sessionctx.GetDomain(e.ctx).InfoSchema()
	db, ok := is.SchemaByName(schema)
	if !ok {
		return nil, errors.Errorf("Unknown schema name: %s", dbName)
	}
	return db, nil
}
開發者ID:jmptrader,項目名稱:tidb,代碼行數:19,代碼來源:grant.go

示例10: ResolveName

// ResolveName resolves table name and column name.
// It generates ResultFields for ResultSetNode and resolves ColumnNameExpr to a ResultField.
func ResolveName(node ast.Node, info infoschema.InfoSchema, ctx context.Context) error {
	defaultSchema := db.GetCurrentSchema(ctx)
	resolver := nameResolver{Info: info, Ctx: ctx, DefaultSchema: model.NewCIStr(defaultSchema)}
	node.Accept(&resolver)
	return errors.Trace(resolver.Err)
}
開發者ID:youprofit,項目名稱:tidb,代碼行數:8,代碼來源:resolver.go


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