本文整理汇总了Golang中github.com/pingcap/tidb/util/types.DefaultTypeForValue函数的典型用法代码示例。如果您正苦于以下问题:Golang DefaultTypeForValue函数的具体用法?Golang DefaultTypeForValue怎么用?Golang DefaultTypeForValue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DefaultTypeForValue函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewValueExpr
// NewValueExpr creates a ValueExpr with value, and sets default field type.
func NewValueExpr(value interface{}) *ValueExpr {
if ve, ok := value.(*ValueExpr); ok {
return ve
}
ve := &ValueExpr{}
ve.SetValue(value)
ve.Type = types.DefaultTypeForValue(value)
return ve
}
示例2: NewValueExpr
// NewValueExpr creates a ValueExpr with value, and sets default field type.
func NewValueExpr(value interface{}) *ValueExpr {
ve := &ValueExpr{}
ve.Data = types.RawData(value)
if _, ok := value.(UnquoteString); ok {
ve.Type = types.NewFieldType(mysql.TypeVarchar)
ve.Type.Charset = mysql.DefaultCharset
ve.Type.Collate = mysql.DefaultCollationName
return ve
}
ve.Type = types.DefaultTypeForValue(value)
return ve
}
示例3: Leave
func (v *typeInferrer) Leave(in ast.Node) (out ast.Node, ok bool) {
switch x := in.(type) {
case *ast.ColumnNameExpr:
x.SetType(&x.Refer.Column.FieldType)
case *ast.FuncCastExpr:
x.SetType(x.Tp)
case *ast.SelectStmt:
v.selectStmt(x)
case *ast.ParamMarkerExpr:
x.SetType(types.DefaultTypeForValue(x.GetValue()))
case *ast.BinaryOperationExpr:
v.binaryOperation(x)
case *ast.UnaryOperationExpr:
v.unaryOperation(x)
case *ast.BetweenExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.CompareSubqueryExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.ExistsSubqueryExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.PatternInExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.PatternLikeExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.PatternRegexpExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.IsNullExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.IsTruthExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
case *ast.ParenthesesExpr:
x.SetType(x.Expr.GetType())
case *ast.AggregateFuncExpr:
v.aggregateFunc(x)
// TODO: handle all expression types.
}
return in, true
}
示例4: Leave
func (v *typeInferrer) Leave(in ast.Node) (out ast.Node, ok bool) {
switch x := in.(type) {
case *ast.AggregateFuncExpr:
v.aggregateFunc(x)
case *ast.BetweenExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
x.Type.Charset = charset.CharsetBin
x.Type.Collate = charset.CollationBin
case *ast.BinaryOperationExpr:
v.binaryOperation(x)
case *ast.CaseExpr:
v.handleCaseExpr(x)
case *ast.ColumnNameExpr:
x.SetType(&x.Refer.Column.FieldType)
case *ast.CompareSubqueryExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
x.Type.Charset = charset.CharsetBin
x.Type.Collate = charset.CollationBin
case *ast.ExistsSubqueryExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
x.Type.Charset = charset.CharsetBin
x.Type.Collate = charset.CollationBin
case *ast.FuncCallExpr:
v.handleFuncCallExpr(x)
case *ast.FuncCastExpr:
x.SetType(x.Tp)
if len(x.Type.Charset) == 0 {
x.Type.Charset, x.Type.Collate = types.DefaultCharsetForType(x.Type.Tp)
}
case *ast.IsNullExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
x.Type.Charset = charset.CharsetBin
x.Type.Collate = charset.CollationBin
case *ast.IsTruthExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
x.Type.Charset = charset.CharsetBin
x.Type.Collate = charset.CollationBin
case *ast.ParamMarkerExpr:
x.SetType(types.DefaultTypeForValue(x.GetValue()))
case *ast.ParenthesesExpr:
x.SetType(x.Expr.GetType())
case *ast.PatternInExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
x.Type.Charset = charset.CharsetBin
x.Type.Collate = charset.CollationBin
case *ast.PatternLikeExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
x.Type.Charset = charset.CharsetBin
x.Type.Collate = charset.CollationBin
case *ast.PatternRegexpExpr:
x.SetType(types.NewFieldType(mysql.TypeLonglong))
x.Type.Charset = charset.CharsetBin
x.Type.Collate = charset.CollationBin
case *ast.SelectStmt:
v.selectStmt(x)
case *ast.UnaryOperationExpr:
v.unaryOperation(x)
case *ast.ValueExpr:
v.handleValueExpr(x)
case *ast.VariableExpr:
x.SetType(types.NewFieldType(mysql.TypeVarString))
x.Type.Charset = v.defaultCharset
cln, err := charset.GetDefaultCollation(v.defaultCharset)
if err != nil {
v.err = err
}
x.Type.Collate = cln
// TODO: handle all expression types.
}
return in, true
}
示例5: handleValueExpr
func (v *typeInferrer) handleValueExpr(x *ast.ValueExpr) {
tp := types.DefaultTypeForValue(x.GetValue())
// Set charset and collation
x.SetType(tp)
}
示例6: handleValueExpr
func (v *typeInferrer) handleValueExpr(x *ast.ValueExpr) {
types.DefaultTypeForValue(x.GetValue(), x.GetType())
}