本文整理匯總了Golang中github.com/pingcap/tidb/ast.BinaryOperationExpr.SetNull方法的典型用法代碼示例。如果您正苦於以下問題:Golang BinaryOperationExpr.SetNull方法的具體用法?Golang BinaryOperationExpr.SetNull怎麽用?Golang BinaryOperationExpr.SetNull使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/ast.BinaryOperationExpr
的用法示例。
在下文中一共展示了BinaryOperationExpr.SetNull方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleOrOr
func (e *Evaluator) handleOrOr(o *ast.BinaryOperationExpr) bool {
leftDatum := o.L.GetDatum()
if !leftDatum.IsNull() {
x, err := leftDatum.ToBool(e.sc)
if err != nil {
e.err = errors.Trace(err)
return false
} else if x == 1 {
// true || any other types is true.
o.SetInt64(x)
return true
}
}
righDatum := o.R.GetDatum()
if !righDatum.IsNull() {
y, err := righDatum.ToBool(e.sc)
if err != nil {
e.err = errors.Trace(err)
return false
} else if y == 1 {
o.SetInt64(y)
return true
}
}
if leftDatum.IsNull() || righDatum.IsNull() {
o.SetNull()
return true
}
o.SetInt64(int64(0))
return true
}
示例2: handleXor
func (e *Evaluator) handleXor(o *ast.BinaryOperationExpr) bool {
leftDatum := o.L.GetDatum()
righDatum := o.R.GetDatum()
if leftDatum.IsNull() || righDatum.IsNull() {
o.SetNull()
return true
}
x, err := leftDatum.ToBool(e.sc)
if err != nil {
e.err = errors.Trace(err)
return false
}
y, err := righDatum.ToBool(e.sc)
if err != nil {
e.err = errors.Trace(err)
return false
}
if x == y {
o.SetInt64(int64(0))
} else {
o.SetInt64(int64(1))
}
return true
}
示例3: handleAndAnd
func (e *Evaluator) handleAndAnd(o *ast.BinaryOperationExpr) bool {
leftDatum := o.L.GetDatum()
rightDatum := o.R.GetDatum()
if leftDatum.Kind() != types.KindNull {
x, err := leftDatum.ToBool()
if err != nil {
e.err = errors.Trace(err)
return false
} else if x == 0 {
// false && any other types is false
o.SetInt64(x)
return true
}
}
if rightDatum.Kind() != types.KindNull {
y, err := rightDatum.ToBool()
if err != nil {
e.err = errors.Trace(err)
return false
} else if y == 0 {
o.SetInt64(y)
return true
}
}
if leftDatum.Kind() == types.KindNull || rightDatum.Kind() == types.KindNull {
o.SetNull()
return true
}
o.SetInt64(int64(1))
return true
}
示例4: handleComparisonOp
func (e *Evaluator) handleComparisonOp(o *ast.BinaryOperationExpr) bool {
var a, b = *o.L.GetDatum(), *o.R.GetDatum()
var err error
if o.Op != opcode.NullEQ {
a, b, err = types.CoerceDatum(e.sc, *o.L.GetDatum(), *o.R.GetDatum())
if err != nil {
e.err = errors.Trace(err)
return false
}
}
if a.IsNull() || b.IsNull() {
// for <=>, if a and b are both nil, return true.
// if a or b is nil, return false.
if o.Op == opcode.NullEQ {
if a.IsNull() && b.IsNull() {
o.SetInt64(oneI64)
} else {
o.SetInt64(zeroI64)
}
} else {
o.SetNull()
}
return true
}
n, err := a.CompareDatum(e.sc, b)
if err != nil {
e.err = errors.Trace(err)
return false
}
r, err := getCompResult(o.Op, n)
if err != nil {
e.err = errors.Trace(err)
return false
}
if r {
o.SetInt64(oneI64)
} else {
o.SetInt64(zeroI64)
}
return true
}
示例5: handleArithmeticOp
func (e *Evaluator) handleArithmeticOp(o *ast.BinaryOperationExpr) bool {
a, err := types.CoerceArithmetic(e.sc, *o.L.GetDatum())
if err != nil {
e.err = errors.Trace(err)
return false
}
b, err := types.CoerceArithmetic(e.sc, *o.R.GetDatum())
if err != nil {
e.err = errors.Trace(err)
return false
}
a, b, err = types.CoerceDatum(e.sc, a, b)
if err != nil {
e.err = errors.Trace(err)
return false
}
if a.IsNull() || b.IsNull() {
o.SetNull()
return true
}
var result types.Datum
switch o.Op {
case opcode.Plus:
result, e.err = types.ComputePlus(a, b)
case opcode.Minus:
result, e.err = types.ComputeMinus(a, b)
case opcode.Mul:
result, e.err = types.ComputeMul(a, b)
case opcode.Div:
result, e.err = types.ComputeDiv(e.sc, a, b)
case opcode.Mod:
result, e.err = types.ComputeMod(e.sc, a, b)
case opcode.IntDiv:
result, e.err = types.ComputeIntDiv(e.sc, a, b)
default:
e.err = ErrInvalidOperation.Gen("invalid op %v in arithmetic operation", o.Op)
return false
}
o.SetDatum(result)
return e.err == nil
}
示例6: handleBitOp
func (e *Evaluator) handleBitOp(o *ast.BinaryOperationExpr) bool {
a, b, err := types.CoerceDatum(e.sc, *o.L.GetDatum(), *o.R.GetDatum())
if err != nil {
e.err = errors.Trace(err)
return false
}
if a.IsNull() || b.IsNull() {
o.SetNull()
return true
}
x, err := a.ToInt64(e.sc)
if err != nil {
e.err = errors.Trace(err)
return false
}
y, err := b.ToInt64(e.sc)
if err != nil {
e.err = errors.Trace(err)
return false
}
// use a int64 for bit operator, return uint64
switch o.Op {
case opcode.And:
o.SetUint64(uint64(x & y))
case opcode.Or:
o.SetUint64(uint64(x | y))
case opcode.Xor:
o.SetUint64(uint64(x ^ y))
case opcode.RightShift:
o.SetUint64(uint64(x) >> uint64(y))
case opcode.LeftShift:
o.SetUint64(uint64(x) << uint64(y))
default:
e.err = ErrInvalidOperation.Gen("invalid op %v in bit operation", o.Op)
return false
}
return true
}