本文整理匯總了Golang中github.com/youtube/vitess/go/sqltypes.Value.ParseFloat64方法的典型用法代碼示例。如果您正苦於以下問題:Golang Value.ParseFloat64方法的具體用法?Golang Value.ParseFloat64怎麽用?Golang Value.ParseFloat64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/youtube/vitess/go/sqltypes.Value
的用法示例。
在下文中一共展示了Value.ParseFloat64方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: valueToBigRat
// valueToBigRat converts a numeric 'value' into a big.Rat object.
func valueToBigRat(value sqltypes.Value) (*big.Rat, error) {
switch {
case value.IsUnsigned():
nativeValue, err := value.ParseUint64()
if err != nil {
return nil, err
}
return uint64ToBigRat(nativeValue), nil
case value.IsSigned():
nativeValue, err := value.ParseInt64()
if err != nil {
return nil, err
}
return int64ToBigRat(nativeValue), nil
case value.IsFloat():
nativeValue, err := value.ParseFloat64()
if err != nil {
return nil, err
}
return float64ToBigRat(nativeValue), nil
default:
panic(fmt.Sprintf("got value with a non numeric type: %v", value))
}
}
示例2: getWhereClause
// getWhereClause returns a whereClause based on desired upper and lower
// bounds for primary key.
func (qs *QuerySplitter) getWhereClause(whereClause *sqlparser.Where, bindVars map[string]interface{}, start, end sqltypes.Value) *sqlparser.Where {
var startClause *sqlparser.ComparisonExpr
var endClause *sqlparser.ComparisonExpr
var clauses sqlparser.BoolExpr
// No upper or lower bound, just return the where clause of original query
if start.IsNull() && end.IsNull() {
return whereClause
}
pk := &sqlparser.ColName{
Name: sqlparser.SQLName(qs.splitColumn),
}
if !start.IsNull() {
startClause = &sqlparser.ComparisonExpr{
Operator: sqlparser.GreaterEqualStr,
Left: pk,
Right: sqlparser.ValArg([]byte(":" + startBindVarName)),
}
if start.IsNumeric() {
v, _ := start.ParseInt64()
bindVars[startBindVarName] = v
} else if start.IsString() {
bindVars[startBindVarName] = start.Raw()
} else if start.IsFractional() {
v, _ := start.ParseFloat64()
bindVars[startBindVarName] = v
}
}
// splitColumn < end
if !end.IsNull() {
endClause = &sqlparser.ComparisonExpr{
Operator: sqlparser.LessThanStr,
Left: pk,
Right: sqlparser.ValArg([]byte(":" + endBindVarName)),
}
if end.IsNumeric() {
v, _ := end.ParseInt64()
bindVars[endBindVarName] = v
} else if end.IsString() {
bindVars[endBindVarName] = end.Raw()
} else if end.IsFractional() {
v, _ := end.ParseFloat64()
bindVars[endBindVarName] = v
}
}
if startClause == nil {
clauses = endClause
} else {
if endClause == nil {
clauses = startClause
} else {
// splitColumn >= start AND splitColumn < end
clauses = &sqlparser.AndExpr{
Left: startClause,
Right: endClause,
}
}
}
if whereClause != nil {
clauses = &sqlparser.AndExpr{
Left: &sqlparser.ParenBoolExpr{Expr: whereClause.Expr},
Right: &sqlparser.ParenBoolExpr{Expr: clauses},
}
}
return &sqlparser.Where{
Type: sqlparser.WhereStr,
Expr: clauses,
}
}