本文整理汇总了Golang中github.com/pingcap/tidb/util/types.Datum.GetMysqlSet方法的典型用法代码示例。如果您正苦于以下问题:Golang Datum.GetMysqlSet方法的具体用法?Golang Datum.GetMysqlSet怎么用?Golang Datum.GetMysqlSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/util/types.Datum
的用法示例。
在下文中一共展示了Datum.GetMysqlSet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: flatten
func flatten(data types.Datum) (types.Datum, error) {
switch data.Kind() {
case types.KindMysqlTime:
// for mysql datetime, timestamp and date type
v, err := data.GetMysqlTime().ToPackedUint()
return types.NewUintDatum(v), errors.Trace(err)
case types.KindMysqlDuration:
// for mysql time type
data.SetInt64(int64(data.GetMysqlDuration().Duration))
return data, nil
case types.KindMysqlEnum:
data.SetUint64(data.GetMysqlEnum().Value)
return data, nil
case types.KindMysqlSet:
data.SetUint64(data.GetMysqlSet().Value)
return data, nil
case types.KindMysqlBit:
data.SetUint64(data.GetMysqlBit().Value)
return data, nil
case types.KindMysqlHex:
data.SetInt64(data.GetMysqlHex().Value)
return data, nil
default:
return data, nil
}
}
示例2: flatten
func flatten(data types.Datum) (types.Datum, error) {
switch data.Kind() {
case types.KindMysqlTime:
// for mysql datetime, timestamp and date type
b, err := data.GetMysqlTime().Marshal()
if err != nil {
return types.NewDatum(nil), errors.Trace(err)
}
return types.NewDatum(b), nil
case types.KindMysqlDuration:
// for mysql time type
data.SetInt64(int64(data.GetMysqlDuration().Duration))
return data, nil
case types.KindMysqlDecimal:
data.SetString(data.GetMysqlDecimal().String())
return data, nil
case types.KindMysqlEnum:
data.SetUint64(data.GetMysqlEnum().Value)
return data, nil
case types.KindMysqlSet:
data.SetUint64(data.GetMysqlSet().Value)
return data, nil
case types.KindMysqlBit:
data.SetUint64(data.GetMysqlBit().Value)
return data, nil
case types.KindMysqlHex:
data.SetInt64(data.GetMysqlHex().Value)
return data, nil
default:
return data, nil
}
}
示例3: dumpTextValue
func dumpTextValue(mysqlType uint8, value types.Datum) ([]byte, error) {
switch value.Kind() {
case types.KindInt64:
return strconv.AppendInt(nil, value.GetInt64(), 10), nil
case types.KindUint64:
return strconv.AppendUint(nil, value.GetUint64(), 10), nil
case types.KindFloat32:
return strconv.AppendFloat(nil, value.GetFloat64(), 'f', -1, 32), nil
case types.KindFloat64:
return strconv.AppendFloat(nil, value.GetFloat64(), 'f', -1, 64), nil
case types.KindString, types.KindBytes:
return value.GetBytes(), nil
case types.KindMysqlTime:
return hack.Slice(value.GetMysqlTime().String()), nil
case types.KindMysqlDuration:
return hack.Slice(value.GetMysqlDuration().String()), nil
case types.KindMysqlDecimal:
return hack.Slice(value.GetMysqlDecimal().String()), nil
case types.KindMysqlEnum:
return hack.Slice(value.GetMysqlEnum().String()), nil
case types.KindMysqlSet:
return hack.Slice(value.GetMysqlSet().String()), nil
case types.KindMysqlBit:
return hack.Slice(value.GetMysqlBit().ToString()), nil
case types.KindMysqlHex:
return hack.Slice(value.GetMysqlHex().ToString()), nil
default:
return nil, errInvalidType.Gen("invalid type %T", value)
}
}
示例4: coerceArithmetic
func coerceArithmetic(a types.Datum) (d types.Datum, err error) {
switch a.Kind() {
case types.KindString, types.KindBytes:
// MySQL will convert string to float for arithmetic operation
f, err := types.StrToFloat(a.GetString())
if err != nil {
return d, errors.Trace(err)
}
d.SetFloat64(f)
return d, errors.Trace(err)
case types.KindMysqlTime:
// if time has no precision, return int64
t := a.GetMysqlTime()
de := t.ToNumber()
if t.Fsp == 0 {
d.SetInt64(de.IntPart())
return d, nil
}
d.SetMysqlDecimal(de)
return d, nil
case types.KindMysqlDuration:
// if duration has no precision, return int64
du := a.GetMysqlDuration()
de := du.ToNumber()
if du.Fsp == 0 {
d.SetInt64(de.IntPart())
return d, nil
}
d.SetMysqlDecimal(de)
return d, nil
case types.KindMysqlHex:
d.SetFloat64(a.GetMysqlHex().ToNumber())
return d, nil
case types.KindMysqlBit:
d.SetFloat64(a.GetMysqlBit().ToNumber())
return d, nil
case types.KindMysqlEnum:
d.SetFloat64(a.GetMysqlEnum().ToNumber())
return d, nil
case types.KindMysqlSet:
d.SetFloat64(a.GetMysqlSet().ToNumber())
return d, nil
default:
return a, nil
}
}