• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ast.ShowStmt类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/pingcap/tidb/ast.ShowStmt的典型用法代码示例。如果您正苦于以下问题:Golang ShowStmt类的具体用法?Golang ShowStmt怎么用?Golang ShowStmt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ShowStmt类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: buildShow

func (b *planBuilder) buildShow(show *ast.ShowStmt) Plan {
	var p Plan
	p = &Show{
		Tp:     show.Tp,
		DBName: show.DBName,
		Table:  show.Table,
		Column: show.Column,
		Flag:   show.Flag,
		Full:   show.Full,
		User:   show.User,
	}
	switch show.Tp {
	case ast.ShowProcedureStatus:
		p.SetFields(buildShowProcedureFields())
	case ast.ShowTriggers:
		p.SetFields(buildShowTriggerFields())
	default:
		p.SetFields(show.GetResultFields())
	}
	var conditions []ast.ExprNode
	if show.Pattern != nil {
		conditions = append(conditions, show.Pattern)
	}
	if show.Where != nil {
		conditions = append(conditions, show.Where)
	}
	if len(conditions) != 0 {
		filter := &Filter{Conditions: conditions}
		addChild(filter, p)
		p = filter
	}
	return p
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:33,代码来源:planbuilder.go


示例2: buildShow

func (b *planBuilder) buildShow(show *ast.ShowStmt) Plan {
	var resultPlan Plan
	p := &Show{
		Tp:              show.Tp,
		DBName:          show.DBName,
		Table:           show.Table,
		Column:          show.Column,
		Flag:            show.Flag,
		Full:            show.Full,
		User:            show.User,
		baseLogicalPlan: newBaseLogicalPlan("Show", b.allocator),
	}
	resultPlan = p
	p.initIDAndContext(b.ctx)
	p.self = p
	switch show.Tp {
	case ast.ShowProcedureStatus:
		p.SetSchema(buildShowProcedureSchema())
	case ast.ShowTriggers:
		p.SetSchema(buildShowTriggerSchema())
	case ast.ShowEvents:
		p.SetSchema(buildShowEventsSchema())
	default:
		p.SetSchema(expression.ResultFieldsToSchema(show.GetResultFields()))
	}
	for i, col := range p.schema {
		col.Position = i
	}
	var conditions []expression.Expression
	if show.Pattern != nil {
		expr, _, err := b.rewrite(show.Pattern, p, nil, false)
		if err != nil {
			b.err = errors.Trace(err)
			return nil
		}
		conditions = append(conditions, expr)
	}
	if show.Where != nil {
		conds := splitWhere(show.Where)
		for _, cond := range conds {
			expr, _, err := b.rewrite(cond, p, nil, false)
			if err != nil {
				b.err = errors.Trace(err)
				return nil
			}
			conditions = append(conditions, expr)
		}
	}
	if len(conditions) != 0 {
		sel := &Selection{
			baseLogicalPlan: newBaseLogicalPlan(Sel, b.allocator),
			Conditions:      conditions,
		}
		sel.initIDAndContext(b.ctx)
		sel.self = sel
		addChild(sel, p)
		resultPlan = sel
	}
	return resultPlan
}
开发者ID:pingcap,项目名称:tidb,代码行数:60,代码来源:planbuilder.go


示例3: buildShow

func (b *planBuilder) buildShow(show *ast.ShowStmt) Plan {
	var p Plan
	p = &Show{
		Tp:     show.Tp,
		DBName: show.DBName,
		Table:  show.Table,
		Column: show.Column,
		Flag:   show.Flag,
		Full:   show.Full,
		User:   show.User,
	}
	p.SetFields(show.GetResultFields())
	var conditions []ast.ExprNode
	if show.Pattern != nil {
		conditions = append(conditions, show.Pattern)
	}
	if show.Where != nil {
		conditions = append(conditions, show.Where)
	}
	if len(conditions) != 0 {
		filter := &Filter{Conditions: conditions}
		filter.SetSrc(p)
		p = filter
	}
	return p
}
开发者ID:astaxie,项目名称:tidb,代码行数:26,代码来源:planbuilder.go


示例4: convertShow

func convertShow(converter *expressionConverter, v *ast.ShowStmt) (*stmts.ShowStmt, error) {
	oldShow := &stmts.ShowStmt{
		DBName:      v.DBName,
		Flag:        v.Flag,
		Full:        v.Full,
		GlobalScope: v.GlobalScope,
		Text:        v.Text(),
	}
	if v.Table != nil {
		oldShow.TableIdent = table.Ident{
			Schema: v.Table.Schema,
			Name:   v.Table.Name,
		}
	}
	if v.Column != nil {
		oldShow.ColumnName = joinColumnName(v.Column)
	}
	if v.Where != nil {
		oldWhere, err := convertExpr(converter, v.Where)
		if err != nil {
			return nil, errors.Trace(err)
		}
		oldShow.Where = oldWhere
	}
	if v.Pattern != nil {
		oldPattern, err := convertExpr(converter, v.Pattern)
		if err != nil {
			return nil, errors.Trace(err)
		}
		oldShow.Pattern = oldPattern.(*expression.PatternLike)
	}
	switch v.Tp {
	case ast.ShowCharset:
		oldShow.Target = stmt.ShowCharset
	case ast.ShowCollation:
		oldShow.Target = stmt.ShowCollation
	case ast.ShowColumns:
		oldShow.Target = stmt.ShowColumns
	case ast.ShowCreateTable:
		oldShow.Target = stmt.ShowCreateTable
	case ast.ShowDatabases:
		oldShow.Target = stmt.ShowDatabases
	case ast.ShowTables:
		oldShow.Target = stmt.ShowTables
	case ast.ShowEngines:
		oldShow.Target = stmt.ShowEngines
	case ast.ShowVariables:
		oldShow.Target = stmt.ShowVariables
	case ast.ShowStatus:
		oldShow.Target = stmt.ShowStatus
	case ast.ShowWarnings:
		oldShow.Target = stmt.ShowWarnings
	case ast.ShowNone:
		oldShow.Target = stmt.ShowNone
	}
	return oldShow, nil
}
开发者ID:rorovic,项目名称:tidb,代码行数:57,代码来源:convert_stmt.go


示例5: fillShowFields

func (nr *nameResolver) fillShowFields(s *ast.ShowStmt) {
	if s.DBName == "" {
		if s.Table != nil && s.Table.Schema.L != "" {
			s.DBName = s.Table.Schema.O
		} else {
			s.DBName = nr.DefaultSchema.O
		}
	} else if s.Table != nil && s.Table.Schema.L == "" {
		s.Table.Schema = model.NewCIStr(s.DBName)
	}
	var fields []*ast.ResultField
	var (
		names  []string
		ftypes []byte
	)
	switch s.Tp {
	case ast.ShowEngines:
		names = []string{"Engine", "Support", "Comment", "Transactions", "XA", "Savepoints"}
	case ast.ShowDatabases:
		names = []string{"Database"}
	case ast.ShowTables:
		names = []string{fmt.Sprintf("Tables_in_%s", s.DBName)}
		if s.Full {
			names = append(names, "Table_type")
		}
	case ast.ShowTableStatus:
		names = []string{"Name", "Engine", "Version", "Row_format", "Rows", "Avg_row_length",
			"Data_length", "Max_data_length", "Index_length", "Data_free", "Auto_increment",
			"Create_time", "Update_time", "Check_time", "Collation", "Checksum",
			"Create_options", "Comment"}
		ftypes = []byte{mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLonglong, mysql.TypeVarchar, mysql.TypeLonglong, mysql.TypeLonglong,
			mysql.TypeLonglong, mysql.TypeLonglong, mysql.TypeLonglong, mysql.TypeLonglong, mysql.TypeLonglong,
			mysql.TypeDatetime, mysql.TypeDatetime, mysql.TypeDatetime, mysql.TypeVarchar, mysql.TypeVarchar,
			mysql.TypeVarchar, mysql.TypeVarchar}
	case ast.ShowColumns:
		names = table.ColDescFieldNames(s.Full)
	case ast.ShowWarnings:
		names = []string{"Level", "Code", "Message"}
		ftypes = []byte{mysql.TypeVarchar, mysql.TypeLong, mysql.TypeVarchar}
	case ast.ShowCharset:
		names = []string{"Charset", "Description", "Default collation", "Maxlen"}
		ftypes = []byte{mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLonglong}
	case ast.ShowVariables:
		names = []string{"Variable_name", "Value"}
	case ast.ShowStatus:
		names = []string{"Variable_name", "Value"}
	case ast.ShowCollation:
		names = []string{"Collation", "Charset", "Id", "Default", "Compiled", "Sortlen"}
		ftypes = []byte{mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLonglong,
			mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLonglong}
	case ast.ShowCreateTable:
		names = []string{"Table", "Create Table"}
	case ast.ShowGrants:
		names = []string{fmt.Sprintf("Grants for %s", s.User)}
	case ast.ShowTriggers:
		names = []string{"Trigger", "Event", "Table", "Statement", "Timing", "Created",
			"sql_mode", "Definer", "character_set_client", "collation_connection", "Database Collation"}
		ftypes = []byte{mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar,
			mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar}
	case ast.ShowProcedureStatus:
		names = []string{}
		ftypes = []byte{}
	case ast.ShowIndex:
		names = []string{"Table", "Non_unique", "Key_name", "Seq_in_index",
			"Column_name", "Collation", "Cardinality", "Sub_part", "Packed",
			"Null", "Index_type", "Comment", "Index_comment"}
		ftypes = []byte{mysql.TypeVarchar, mysql.TypeLonglong, mysql.TypeVarchar, mysql.TypeLonglong,
			mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLonglong, mysql.TypeLonglong,
			mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar}
	}
	for i, name := range names {
		f := &ast.ResultField{
			ColumnAsName: model.NewCIStr(name),
			Column:       &model.ColumnInfo{}, // Empty column info.
			Table:        &model.TableInfo{},  // Empty table info.
		}
		if ftypes == nil || ftypes[i] == 0 {
			// use varchar as the default return column type
			f.Column.Tp = mysql.TypeVarchar
		} else {
			f.Column.Tp = ftypes[i]
		}
		f.Column.Charset, f.Column.Collate = types.DefaultCharsetForType(f.Column.Tp)
		f.Expr = &ast.ValueExpr{}
		f.Expr.SetType(&f.Column.FieldType)
		fields = append(fields, f)
	}

	if s.Pattern != nil && s.Pattern.Expr == nil {
		rf := fields[0]
		s.Pattern.Expr = &ast.ColumnNameExpr{
			Name: &ast.ColumnName{Name: rf.ColumnAsName},
		}
		ast.SetFlag(s.Pattern)
	}
	s.SetResultFields(fields)
	nr.currentContext().fieldList = fields
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:98,代码来源:resolver.go



注:本文中的github.com/pingcap/tidb/ast.ShowStmt类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ast.TableName类代码示例发布时间:2022-05-28
下一篇:
Golang ast.SetPwdStmt类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap