本文整理汇总了Golang中github.com/pingcap/tidb/ast.SelectField.Text方法的典型用法代码示例。如果您正苦于以下问题:Golang SelectField.Text方法的具体用法?Golang SelectField.Text怎么用?Golang SelectField.Text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/ast.SelectField
的用法示例。
在下文中一共展示了SelectField.Text方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createResultFields
// createResultFields creates result field list for a single select field.
func (nr *nameResolver) createResultFields(field *ast.SelectField) (rfs []*ast.ResultField) {
ctx := nr.currentContext()
if field.WildCard != nil {
if len(ctx.tables) == 0 {
nr.Err = errors.New("No table used.")
return
}
if field.WildCard.Table.L == "" {
for _, v := range ctx.tables {
rfs = append(rfs, v.GetResultFields()...)
}
} else {
name := nr.tableUniqueName(field.WildCard.Schema, field.WildCard.Table)
tableIdx, ok := ctx.tableMap[name]
if !ok {
nr.Err = errors.Errorf("unknown table %s.", field.WildCard.Table.O)
}
rfs = ctx.tables[tableIdx].GetResultFields()
}
return
}
// The column is visited before so it must has been resolved already.
rf := &ast.ResultField{ColumnAsName: field.AsName}
innerExpr := getInnerFromParentheses(field.Expr)
switch v := innerExpr.(type) {
case *ast.ColumnNameExpr:
rf.Column = v.Refer.Column
rf.Table = v.Refer.Table
rf.DBName = v.Refer.DBName
rf.TableName = v.Refer.TableName
rf.Expr = v.Refer.Expr
default:
rf.Column = &model.ColumnInfo{} // Empty column info.
rf.Table = &model.TableInfo{} // Empty table info.
rf.Expr = v
}
if field.AsName.L == "" {
switch x := innerExpr.(type) {
case *ast.ColumnNameExpr:
rf.ColumnAsName = model.NewCIStr(x.Name.Name.O)
case *ast.ValueExpr:
if innerExpr.Text() != "" {
rf.ColumnAsName = model.NewCIStr(innerExpr.Text())
} else {
rf.ColumnAsName = model.NewCIStr(field.Text())
}
default:
rf.ColumnAsName = model.NewCIStr(field.Text())
}
}
rfs = append(rfs, rf)
return
}
示例2: createResultFields
// createResultFields creates result field list for a single select field.
func (nr *nameResolver) createResultFields(field *ast.SelectField) (rfs []*ast.ResultField) {
ctx := nr.currentContext()
if field.WildCard != nil {
if len(ctx.tables) == 0 {
nr.Err = errors.New("No table used.")
return
}
tableRfs := []*ast.ResultField{}
if field.WildCard.Table.L == "" {
for _, v := range ctx.tables {
tableRfs = append(tableRfs, v.GetResultFields()...)
}
} else {
name := nr.tableUniqueName(field.WildCard.Schema, field.WildCard.Table)
tableIdx, ok1 := ctx.tableMap[name]
derivedTableIdx, ok2 := ctx.derivedTableMap[name]
if !ok1 && !ok2 {
nr.Err = errors.Errorf("unknown table %s.", field.WildCard.Table.O)
}
if ok1 {
tableRfs = ctx.tables[tableIdx].GetResultFields()
}
if ok2 {
tableRfs = append(tableRfs, ctx.tables[derivedTableIdx].GetResultFields()...)
}
}
for _, trf := range tableRfs {
// Convert it to ColumnNameExpr
cn := &ast.ColumnName{
Schema: trf.DBName,
Table: trf.Table.Name,
Name: trf.ColumnAsName,
}
cnExpr := &ast.ColumnNameExpr{
Name: cn,
Refer: trf,
}
ast.SetFlag(cnExpr)
cnExpr.SetType(trf.Expr.GetType())
rf := *trf
rf.Expr = cnExpr
rfs = append(rfs, &rf)
}
return
}
// The column is visited before so it must has been resolved already.
rf := &ast.ResultField{ColumnAsName: field.AsName}
innerExpr := getInnerFromParentheses(field.Expr)
switch v := innerExpr.(type) {
case *ast.ColumnNameExpr:
rf.Column = v.Refer.Column
rf.Table = v.Refer.Table
rf.DBName = v.Refer.DBName
rf.TableName = v.Refer.TableName
rf.Expr = v
default:
rf.Column = &model.ColumnInfo{} // Empty column info.
rf.Table = &model.TableInfo{} // Empty table info.
rf.Expr = v
}
if field.AsName.L == "" {
switch x := innerExpr.(type) {
case *ast.ColumnNameExpr:
rf.ColumnAsName = model.NewCIStr(x.Name.Name.O)
case *ast.ValueExpr:
if innerExpr.Text() != "" {
rf.ColumnAsName = model.NewCIStr(innerExpr.Text())
} else {
rf.ColumnAsName = model.NewCIStr(field.Text())
}
default:
rf.ColumnAsName = model.NewCIStr(field.Text())
}
}
rfs = append(rfs, rf)
return
}