本文整理汇总了Golang中github.com/youtube/vitess/go/vt/sqlparser.GetColName函数的典型用法代码示例。如果您正苦于以下问题:Golang GetColName函数的具体用法?Golang GetColName怎么用?Golang GetColName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetColName函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: analyzeSelectExprs
func analyzeSelectExprs(exprs sqlparser.SelectExprs, table *schema.Table) (selects []int, err error) {
selects = make([]int, 0, len(exprs))
for _, expr := range exprs {
switch expr := expr.(type) {
case *sqlparser.StarExpr:
// Append all columns.
for colIndex := range table.Columns {
selects = append(selects, colIndex)
}
case *sqlparser.NonStarExpr:
name := sqlparser.GetColName(expr.Expr)
if name == "" {
// Not a simple column name.
return nil, nil
}
colIndex := table.FindColumn(name)
if colIndex == -1 {
return nil, fmt.Errorf("column %s not found in table %s", name, table.Name)
}
selects = append(selects, colIndex)
default:
panic("unreachable")
}
}
return selects, nil
}
开发者ID:ninqing,项目名称:vitess,代码行数:26,代码来源:select.go
示例2: buildIndexPlan
func buildIndexPlan(ins *sqlparser.Insert, tablename string, index *Index, plan *Plan) error {
pos := -1
for i, column := range ins.Columns {
if index.Column == sqlparser.GetColName(column.(*sqlparser.NonStarExpr).Expr) {
pos = i
break
}
}
if pos == -1 && index.Owner == tablename && index.IsAutoInc {
pos = len(ins.Columns)
ins.Columns = append(ins.Columns, &sqlparser.NonStarExpr{Expr: &sqlparser.ColName{Name: []byte(index.Column)}})
ins.Rows.(sqlparser.Values)[0] = append(ins.Rows.(sqlparser.Values)[0].(sqlparser.ValTuple), &sqlparser.NullVal{})
}
if pos == -1 {
return fmt.Errorf("must supply value for indexed column: %s", index.Column)
}
row := ins.Rows.(sqlparser.Values)[0].(sqlparser.ValTuple)
val, err := sqlparser.AsInterface(row[pos])
if err != nil {
return fmt.Errorf("could not convert val: %s, pos: %d", row[pos], pos)
}
plan.Values = append(plan.Values.([]interface{}), val)
if index.Owner == tablename && index.IsAutoInc {
row[pos] = sqlparser.ValArg([]byte(fmt.Sprintf(":_%s", index.Column)))
}
return nil
}
开发者ID:plobsing,项目名称:vitess,代码行数:27,代码来源:insert.go
示例3: findOrInsertPos
func findOrInsertPos(ins *sqlparser.Insert, col string) (row sqlparser.ValTuple, pos int) {
pos = -1
for i, column := range ins.Columns {
if col == sqlparser.GetColName(column.(*sqlparser.NonStarExpr).Expr) {
pos = i
break
}
}
if pos == -1 {
pos = len(ins.Columns)
ins.Columns = append(ins.Columns, &sqlparser.NonStarExpr{Expr: &sqlparser.ColName{Name: sqlparser.SQLName(col)}})
ins.Rows.(sqlparser.Values)[0] = append(ins.Rows.(sqlparser.Values)[0].(sqlparser.ValTuple), &sqlparser.NullVal{})
}
return ins.Rows.(sqlparser.Values)[0].(sqlparser.ValTuple), pos
}
开发者ID:aaijazi,项目名称:vitess,代码行数:15,代码来源:insert.go
示例4: getInsertPKColumns
func getInsertPKColumns(columns sqlparser.Columns, tableInfo *schema.Table) (pkColumnNumbers []int) {
if len(columns) == 0 {
return tableInfo.PKColumns
}
pkIndex := tableInfo.Indexes[0]
pkColumnNumbers = make([]int, len(pkIndex.Columns))
for i := range pkColumnNumbers {
pkColumnNumbers[i] = -1
}
for i, column := range columns {
index := pkIndex.FindColumn(sqlparser.GetColName(column.(*sqlparser.NonStarExpr).Expr))
if index == -1 {
continue
}
pkColumnNumbers[index] = i
}
return pkColumnNumbers
}
开发者ID:littleyang,项目名称:vitess,代码行数:18,代码来源:dml.go
示例5: analyzeUpdateExpressions
func analyzeUpdateExpressions(exprs sqlparser.UpdateExprs, pkIndex *schema.Index) (pkValues []interface{}, err error) {
for _, expr := range exprs {
index := pkIndex.FindColumn(sqlparser.GetColName(expr.Name))
if index == -1 {
continue
}
if !sqlparser.IsValue(expr.Expr) {
log.Warningf("expression is too complex %v", expr)
return nil, ErrTooComplex
}
if pkValues == nil {
pkValues = make([]interface{}, len(pkIndex.Columns))
}
var err error
pkValues[index], err = sqlparser.AsInterface(expr.Expr)
if err != nil {
return nil, err
}
}
return pkValues, nil
}
开发者ID:littleyang,项目名称:vitess,代码行数:21,代码来源:dml.go
示例6: buildIndexPlan
func buildIndexPlan(ins *sqlparser.Insert, tablename string, colVindex *ColVindex, plan *Plan) error {
pos := -1
for i, column := range ins.Columns {
if colVindex.Col == sqlparser.GetColName(column.(*sqlparser.NonStarExpr).Expr) {
pos = i
break
}
}
if pos == -1 {
pos = len(ins.Columns)
ins.Columns = append(ins.Columns, &sqlparser.NonStarExpr{Expr: &sqlparser.ColName{Name: sqlparser.SQLName(colVindex.Col)}})
ins.Rows.(sqlparser.Values)[0] = append(ins.Rows.(sqlparser.Values)[0].(sqlparser.ValTuple), &sqlparser.NullVal{})
}
row := ins.Rows.(sqlparser.Values)[0].(sqlparser.ValTuple)
val, err := asInterface(row[pos])
if err != nil {
return fmt.Errorf("could not convert val: %s, pos: %d: %v", sqlparser.String(row[pos]), pos, err)
}
plan.Values = append(plan.Values.([]interface{}), val)
row[pos] = sqlparser.ValArg([]byte(fmt.Sprintf(":_%s", colVindex.Col)))
return nil
}
开发者ID:littleyang,项目名称:vitess,代码行数:22,代码来源:insert.go
示例7: Fuzz
func Fuzz(data []byte) int {
stmt, err := sqlparser.Parse(string(data))
if err != nil {
if stmt != nil {
panic("stmt is not nil on error")
}
return 0
}
if true {
data1 := sqlparser.String(stmt)
stmt1, err := sqlparser.Parse(data1)
if err != nil {
fmt.Printf("data0: %q\n", data)
fmt.Printf("data1: %q\n", data1)
panic(err)
}
if !fuzz.DeepEqual(stmt, stmt1) {
fmt.Printf("data0: %q\n", data)
fmt.Printf("data1: %q\n", data1)
panic("not equal")
}
} else {
sqlparser.String(stmt)
}
if sel, ok := stmt.(*sqlparser.Select); ok {
var nodes []sqlparser.SQLNode
for _, x := range sel.From {
nodes = append(nodes, x)
}
for _, x := range sel.From {
nodes = append(nodes, x)
}
for _, x := range sel.SelectExprs {
nodes = append(nodes, x)
}
for _, x := range sel.GroupBy {
nodes = append(nodes, x)
}
for _, x := range sel.OrderBy {
nodes = append(nodes, x)
}
nodes = append(nodes, sel.Where)
nodes = append(nodes, sel.Having)
nodes = append(nodes, sel.Limit)
for _, n := range nodes {
if n == nil {
continue
}
if x, ok := n.(sqlparser.SimpleTableExpr); ok {
sqlparser.GetTableName(x)
}
if x, ok := n.(sqlparser.Expr); ok {
sqlparser.GetColName(x)
}
if x, ok := n.(sqlparser.ValExpr); ok {
sqlparser.IsValue(x)
}
if x, ok := n.(sqlparser.ValExpr); ok {
sqlparser.IsColName(x)
}
if x, ok := n.(sqlparser.ValExpr); ok {
sqlparser.IsSimpleTuple(x)
}
if x, ok := n.(sqlparser.ValExpr); ok {
sqlparser.AsInterface(x)
}
if x, ok := n.(sqlparser.BoolExpr); ok {
sqlparser.HasINClause([]sqlparser.BoolExpr{x})
}
}
}
buf := sqlparser.NewTrackedBuffer(nil)
stmt.Format(buf)
pq := buf.ParsedQuery()
vars := map[string]interface{}{
"A": 42,
"B": 123123123,
"C": "",
"D": "a",
"E": "foobar",
"F": 1.1,
}
pq.GenerateQuery(vars)
return 1
}
开发者ID:roger2000hk,项目名称:go-fuzz,代码行数:85,代码来源:main.go
注:本文中的github.com/youtube/vitess/go/vt/sqlparser.GetColName函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论