本文整理匯總了Golang中github.com/cockroachdb/cockroach/sql/parser.ContainsVars函數的典型用法代碼示例。如果您正苦於以下問題:Golang ContainsVars函數的具體用法?Golang ContainsVars怎麽用?Golang ContainsVars使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ContainsVars函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: limit
// limit constructs a limitNode based on the LIMIT and OFFSET clauses.
func (p *planner) limit(n *parser.Select, plan planNode) (planNode, error) {
if n.Limit == nil {
return plan, nil
}
var count, offset int64
data := []struct {
name string
src parser.Expr
dst *int64
defaultVal int64
}{
{"LIMIT", n.Limit.Count, &count, math.MaxInt64},
{"OFFSET", n.Limit.Offset, &offset, 0},
}
for _, datum := range data {
if datum.src == nil {
*datum.dst = datum.defaultVal
} else {
if parser.ContainsVars(datum.src) {
return nil, util.Errorf("argument of %s must not contain variables", datum.name)
}
normalized, err := p.parser.NormalizeExpr(p.evalCtx, datum.src)
if err != nil {
return nil, err
}
dstDatum, err := normalized.Eval(p.evalCtx)
if err != nil {
return nil, err
}
if dstDatum == parser.DNull {
*datum.dst = datum.defaultVal
continue
}
if dstDInt, ok := dstDatum.(parser.DInt); ok {
*datum.dst = int64(dstDInt)
continue
}
return nil, fmt.Errorf("argument of %s must be type %s, not type %s", datum.name, parser.DummyInt.Type(), dstDatum.Type())
}
}
if count != math.MaxInt64 {
plan.SetLimitHint(offset + count)
}
return &limitNode{planNode: plan, count: count, offset: offset}, nil
}
示例2: SanitizeDefaultExpr
// SanitizeDefaultExpr verifies a default expression is valid and has the
// correct type.
func SanitizeDefaultExpr(expr parser.Expr, colDatumType parser.Datum) error {
typedExpr, err := parser.TypeCheck(expr, nil, colDatumType)
if err != nil {
return err
}
if defaultType := typedExpr.ReturnType(); !colDatumType.TypeEqual(defaultType) {
return incompatibleColumnDefaultTypeError(colDatumType, defaultType)
}
if parser.ContainsVars(typedExpr) {
return defaultContainsPlaceholdersError(typedExpr)
}
return nil
}
示例3: SanitizeVarFreeExpr
// SanitizeVarFreeExpr verifies a default expression is valid, has the
// correct type and contains no variable expressions.
func SanitizeVarFreeExpr(expr parser.Expr, expectedType parser.Datum, context string) error {
if parser.ContainsVars(expr) {
return exprContainsVarsError(context, expr)
}
typedExpr, err := parser.TypeCheck(expr, nil, expectedType)
if err != nil {
return err
}
if defaultType := typedExpr.ReturnType(); !expectedType.TypeEqual(defaultType) {
return incompatibleExprTypeError(context, expectedType, defaultType)
}
return nil
}
示例4: makeDefaultExprs
func makeDefaultExprs(
cols []sqlbase.ColumnDescriptor, parse *parser.Parser, evalCtx parser.EvalContext,
) ([]parser.TypedExpr, error) {
// Check to see if any of the columns have DEFAULT expressions. If there
// are no DEFAULT expressions, we don't bother with constructing the
// defaults map as the defaults are all NULL.
haveDefaults := false
for _, col := range cols {
if col.DefaultExpr != nil {
haveDefaults = true
break
}
}
if !haveDefaults {
return nil, nil
}
// Build the default expressions map from the parsed SELECT statement.
defaultExprs := make([]parser.TypedExpr, 0, len(cols))
for _, col := range cols {
if col.DefaultExpr == nil {
defaultExprs = append(defaultExprs, parser.DNull)
continue
}
expr, err := parser.ParseExprTraditional(*col.DefaultExpr)
if err != nil {
return nil, err
}
typedExpr, err := parser.TypeCheck(expr, nil, col.Type.ToDatumType())
if err != nil {
return nil, err
}
if typedExpr, err = parse.NormalizeExpr(evalCtx, typedExpr); err != nil {
return nil, err
}
if parser.ContainsVars(typedExpr) {
return nil, util.Errorf("default expression contains variables")
}
defaultExprs = append(defaultExprs, typedExpr)
}
return defaultExprs, nil
}
示例5: makeDefaultExprs
func (p *planner) makeDefaultExprs(cols []ColumnDescriptor) ([]parser.Expr, error) {
// Check to see if any of the columns have DEFAULT expressions. If there are
// no DEFAULT expressions, we don't bother with constructing the defaults map
// as the defaults are all NULL.
haveDefaults := false
for _, col := range cols {
if col.DefaultExpr != nil {
haveDefaults = true
break
}
}
if !haveDefaults {
return nil, nil
}
// Build the default expressions map from the parsed SELECT statement.
defaultExprs := make([]parser.Expr, 0, len(cols))
for _, col := range cols {
if col.DefaultExpr == nil {
defaultExprs = append(defaultExprs, parser.DNull)
continue
}
expr, err := parser.ParseExprTraditional(*col.DefaultExpr)
if err != nil {
return nil, err
}
expr, err = p.parser.NormalizeExpr(p.evalCtx, expr)
if err != nil {
return nil, err
}
if parser.ContainsVars(expr) {
return nil, util.Errorf("default expression contains variables")
}
defaultExprs = append(defaultExprs, expr)
}
return defaultExprs, nil
}