本文整理匯總了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
}