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


Golang ShowStmt.SetResultFields方法代碼示例

本文整理匯總了Golang中github.com/pingcap/tidb/ast.ShowStmt.SetResultFields方法的典型用法代碼示例。如果您正苦於以下問題:Golang ShowStmt.SetResultFields方法的具體用法?Golang ShowStmt.SetResultFields怎麽用?Golang ShowStmt.SetResultFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/pingcap/tidb/ast.ShowStmt的用法示例。


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

示例1: 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.SetResultFields方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。