本文整理汇总了Golang中github.com/pingcap/tidb/ast.BinaryOperationExpr.Type方法的典型用法代码示例。如果您正苦于以下问题:Golang BinaryOperationExpr.Type方法的具体用法?Golang BinaryOperationExpr.Type怎么用?Golang BinaryOperationExpr.Type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/ast.BinaryOperationExpr
的用法示例。
在下文中一共展示了BinaryOperationExpr.Type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: binaryOperation
func (v *typeInferrer) binaryOperation(x *ast.BinaryOperationExpr) {
switch x.Op {
case opcode.AndAnd, opcode.OrOr, opcode.LogicXor:
x.Type = types.NewFieldType(mysql.TypeLonglong)
case opcode.LT, opcode.LE, opcode.GE, opcode.GT, opcode.EQ, opcode.NE, opcode.NullEQ:
x.Type = types.NewFieldType(mysql.TypeLonglong)
case opcode.RightShift, opcode.LeftShift, opcode.And, opcode.Or, opcode.Xor:
x.Type = types.NewFieldType(mysql.TypeLonglong)
x.Type.Flag |= mysql.UnsignedFlag
case opcode.IntDiv:
x.Type = types.NewFieldType(mysql.TypeLonglong)
case opcode.Plus, opcode.Minus, opcode.Mul, opcode.Mod:
if x.L.GetType() != nil && x.R.GetType() != nil {
xTp := mergeArithType(x.L.GetType().Tp, x.R.GetType().Tp)
x.Type = types.NewFieldType(xTp)
leftUnsigned := x.L.GetType().Flag & mysql.UnsignedFlag
rightUnsigned := x.R.GetType().Flag & mysql.UnsignedFlag
// If both operands are unsigned, result is unsigned.
x.Type.Flag |= (leftUnsigned & rightUnsigned)
}
case opcode.Div:
if x.L.GetType() != nil && x.R.GetType() != nil {
xTp := mergeArithType(x.L.GetType().Tp, x.R.GetType().Tp)
if xTp == mysql.TypeLonglong {
xTp = mysql.TypeDecimal
}
x.Type = types.NewFieldType(xTp)
}
}
x.Type.Charset = charset.CharsetBin
x.Type.Collate = charset.CollationBin
}