本文整理匯總了Golang中github.com/pingcap/tidb/ast.UnaryOperationExpr.SetFloat64方法的典型用法代碼示例。如果您正苦於以下問題:Golang UnaryOperationExpr.SetFloat64方法的具體用法?Golang UnaryOperationExpr.SetFloat64怎麽用?Golang UnaryOperationExpr.SetFloat64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/ast.UnaryOperationExpr
的用法示例。
在下文中一共展示了UnaryOperationExpr.SetFloat64方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: unaryOperation
func (e *Evaluator) unaryOperation(u *ast.UnaryOperationExpr) bool {
defer func() {
if er := recover(); er != nil {
e.err = errors.Errorf("%v", er)
}
}()
aDatum := u.V.GetDatum()
if aDatum.IsNull() {
u.SetNull()
return true
}
switch op := u.Op; op {
case opcode.Not:
n, err := aDatum.ToBool()
if err != nil {
e.err = errors.Trace(err)
} else if n == 0 {
u.SetInt64(1)
} else {
u.SetInt64(0)
}
case opcode.BitNeg:
// for bit operation, we will use int64 first, then return uint64
n, err := aDatum.ToInt64()
if err != nil {
e.err = errors.Trace(err)
return false
}
u.SetUint64(uint64(^n))
case opcode.Plus:
switch aDatum.Kind() {
case types.KindInt64,
types.KindUint64,
types.KindFloat64,
types.KindFloat32,
types.KindMysqlDuration,
types.KindMysqlTime,
types.KindString,
types.KindMysqlDecimal,
types.KindBytes,
types.KindMysqlHex,
types.KindMysqlBit,
types.KindMysqlEnum,
types.KindMysqlSet:
u.SetDatum(*aDatum)
default:
e.err = ErrInvalidOperation
return false
}
case opcode.Minus:
switch aDatum.Kind() {
case types.KindInt64:
u.SetInt64(-aDatum.GetInt64())
case types.KindUint64:
u.SetInt64(-int64(aDatum.GetUint64()))
case types.KindFloat64:
u.SetFloat64(-aDatum.GetFloat64())
case types.KindFloat32:
u.SetFloat32(-aDatum.GetFloat32())
case types.KindMysqlDuration:
var to = new(mysql.MyDecimal)
var zero mysql.MyDecimal
mysql.DecimalSub(&zero, aDatum.GetMysqlDuration().ToNumber(), to)
u.SetMysqlDecimal(to)
case types.KindMysqlTime:
dec := aDatum.GetMysqlTime().ToNumber()
var zero, to mysql.MyDecimal
mysql.DecimalSub(&zero, dec, &to)
u.SetMysqlDecimal(&to)
case types.KindString, types.KindBytes:
f, err := types.StrToFloat(aDatum.GetString())
e.err = errors.Trace(err)
u.SetFloat64(-f)
case types.KindMysqlDecimal:
dec := aDatum.GetMysqlDecimal()
var zero, to mysql.MyDecimal
mysql.DecimalSub(&zero, dec, &to)
u.SetMysqlDecimal(&to)
case types.KindMysqlHex:
u.SetFloat64(-aDatum.GetMysqlHex().ToNumber())
case types.KindMysqlBit:
u.SetFloat64(-aDatum.GetMysqlBit().ToNumber())
case types.KindMysqlEnum:
u.SetFloat64(-aDatum.GetMysqlEnum().ToNumber())
case types.KindMysqlSet:
u.SetFloat64(-aDatum.GetMysqlSet().ToNumber())
default:
e.err = ErrInvalidOperation
return false
}
default:
e.err = ErrInvalidOperation
return false
}
return true
}