本文整理汇总了Golang中github.com/pingcap/tidb/mysql.ParseEnumValue函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseEnumValue函数的具体用法?Golang ParseEnumValue怎么用?Golang ParseEnumValue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParseEnumValue函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: unflatten
func (t *Table) unflatten(rec interface{}, col *column.Col) (interface{}, error) {
if rec == nil {
return nil, nil
}
switch col.Tp {
case mysql.TypeFloat:
return float32(rec.(float64)), nil
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeYear, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong,
mysql.TypeDouble, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeBlob, mysql.TypeLongBlob,
mysql.TypeVarchar, mysql.TypeString:
return rec, nil
case mysql.TypeDate, mysql.TypeDatetime, mysql.TypeTimestamp:
var t mysql.Time
t.Type = col.Tp
t.Fsp = col.Decimal
err := t.Unmarshal(rec.([]byte))
if err != nil {
return nil, errors.Trace(err)
}
return t, nil
case mysql.TypeDuration:
return mysql.Duration{Duration: time.Duration(rec.(int64)), Fsp: col.Decimal}, nil
case mysql.TypeNewDecimal, mysql.TypeDecimal:
return mysql.ParseDecimal(string(rec.([]byte)))
case mysql.TypeEnum:
return mysql.ParseEnumValue(col.Elems, rec.(uint64))
case mysql.TypeSet:
return mysql.ParseSetValue(col.Elems, rec.(uint64))
case mysql.TypeBit:
return mysql.Bit{Value: rec.(uint64), Width: col.Flen}, nil
}
log.Error(col.Tp, rec, reflect.TypeOf(rec))
return nil, nil
}
开发者ID:lovedboy,项目名称:tidb,代码行数:34,代码来源:tables.go
示例2: decodeValue
func decodeValue(data []byte, cols []*model.ColumnInfo) ([]interface{}, error) {
values, err := codec.Decode(data)
if err != nil {
return nil, errors.Trace(err)
}
if len(values) != len(cols) {
return nil, errors.Errorf("Column count does not match, expect %d, actual %d", len(cols), len(values))
}
var rvalues []interface{}
for i, col := range cols {
// TODO: support more types if we really need.
switch col.Tp {
case mysql.TypeString, mysql.TypeVarchar:
val := string(values[i].([]byte))
rvalues = append(rvalues, val)
case mysql.TypeEnum:
val, err := mysql.ParseEnumValue(col.Elems, values[i].(uint64))
if err != nil {
return nil, errors.Trace(err)
}
rvalues = append(rvalues, val.String())
}
}
return rvalues, nil
}
开发者ID:xudongQiu,项目名称:tidb,代码行数:27,代码来源:common.go
示例3: unflatten
func unflatten(datum types.Datum, tp *types.FieldType) (types.Datum, error) {
if datum.IsNull() {
return datum, nil
}
switch tp.Tp {
case mysql.TypeFloat:
datum.SetFloat32(float32(datum.GetFloat64()))
return datum, nil
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeYear, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong,
mysql.TypeDouble, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeBlob, mysql.TypeLongBlob,
mysql.TypeVarchar, mysql.TypeString:
return datum, nil
case mysql.TypeDate, mysql.TypeDatetime, mysql.TypeTimestamp:
var t mysql.Time
t.Type = tp.Tp
t.Fsp = tp.Decimal
err := t.Unmarshal(datum.GetBytes())
if err != nil {
return datum, errors.Trace(err)
}
datum.SetValue(t)
return datum, nil
case mysql.TypeDuration:
dur := mysql.Duration{Duration: time.Duration(datum.GetInt64())}
datum.SetValue(dur)
return datum, nil
case mysql.TypeNewDecimal, mysql.TypeDecimal:
dec, err := mysql.ParseDecimal(datum.GetString())
if err != nil {
return datum, errors.Trace(err)
}
if tp.Decimal >= 0 {
dec = dec.Truncate(int32(tp.Decimal))
}
datum.SetValue(dec)
return datum, nil
case mysql.TypeEnum:
enum, err := mysql.ParseEnumValue(tp.Elems, datum.GetUint64())
if err != nil {
return datum, errors.Trace(err)
}
datum.SetValue(enum)
return datum, nil
case mysql.TypeSet:
set, err := mysql.ParseSetValue(tp.Elems, datum.GetUint64())
if err != nil {
return datum, errors.Trace(err)
}
datum.SetValue(set)
return datum, nil
case mysql.TypeBit:
bit := mysql.Bit{Value: datum.GetUint64(), Width: tp.Flen}
datum.SetValue(bit)
return datum, nil
}
log.Error(tp.Tp, datum)
return datum, nil
}
开发者ID:anywhy,项目名称:tidb,代码行数:58,代码来源:tables.go
示例4: Unflatten
// Unflatten converts a raw datum to a column datum.
func Unflatten(datum types.Datum, ft *types.FieldType, inIndex bool) (types.Datum, error) {
if datum.IsNull() {
return datum, nil
}
switch ft.Tp {
case mysql.TypeFloat:
datum.SetFloat32(float32(datum.GetFloat64()))
return datum, nil
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeYear, mysql.TypeInt24,
mysql.TypeLong, mysql.TypeLonglong, mysql.TypeDouble, mysql.TypeTinyBlob,
mysql.TypeMediumBlob, mysql.TypeBlob, mysql.TypeLongBlob, mysql.TypeVarchar,
mysql.TypeString:
return datum, nil
case mysql.TypeDate, mysql.TypeDatetime, mysql.TypeTimestamp:
var t mysql.Time
t.Type = ft.Tp
t.Fsp = ft.Decimal
var err error
err = t.FromPackedUint(datum.GetUint64())
if err != nil {
return datum, errors.Trace(err)
}
datum.SetMysqlTime(t)
return datum, nil
case mysql.TypeDuration:
dur := mysql.Duration{Duration: time.Duration(datum.GetInt64())}
datum.SetValue(dur)
return datum, nil
case mysql.TypeEnum:
enum, err := mysql.ParseEnumValue(ft.Elems, datum.GetUint64())
if err != nil {
return datum, errors.Trace(err)
}
datum.SetValue(enum)
return datum, nil
case mysql.TypeSet:
set, err := mysql.ParseSetValue(ft.Elems, datum.GetUint64())
if err != nil {
return datum, errors.Trace(err)
}
datum.SetValue(set)
return datum, nil
case mysql.TypeBit:
bit := mysql.Bit{Value: datum.GetUint64(), Width: ft.Flen}
datum.SetValue(bit)
return datum, nil
}
return datum, nil
}
开发者ID:yangxuanjia,项目名称:tidb,代码行数:50,代码来源:tablecodec.go
示例5: convertToMysqlEnum
func (d *Datum) convertToMysqlEnum(target *FieldType) (Datum, error) {
var (
ret Datum
e mysql.Enum
err error
)
switch d.k {
case KindString, KindBytes:
e, err = mysql.ParseEnumName(target.Elems, d.GetString())
default:
var uintDatum Datum
uintDatum, err = d.convertToUint(target)
if err != nil {
return ret, errors.Trace(err)
}
e, err = mysql.ParseEnumValue(target.Elems, uintDatum.GetUint64())
}
if err != nil {
return invalidConv(d, target.Tp)
}
ret.SetValue(e)
return ret, nil
}
开发者ID:yangxuanjia,项目名称:tidb,代码行数:23,代码来源:datum.go
示例6: Convert
//.........这里部分代码省略.........
}
// check bit boundary, if bit has n width, the boundary is
// in [0, (1 << n) - 1]
width := target.Flen
if width == 0 || width == mysql.UnspecifiedBitWidth {
width = mysql.MinBitWidth
}
maxValue := uint64(1)<<uint64(width) - 1
if x > maxValue {
return maxValue, overflow(val, tp)
}
return mysql.Bit{Value: x, Width: width}, nil
case mysql.TypeDecimal, mysql.TypeNewDecimal:
x, err := ToDecimal(val)
if err != nil {
return invConv(val, tp)
}
if target.Decimal != UnspecifiedLength {
x = x.Round(int32(target.Decimal))
}
// TODO: check Flen
return x, nil
case mysql.TypeYear:
var (
intVal int64
err error
)
switch x := val.(type) {
case string:
intVal, err = StrToInt(x)
case mysql.Time:
return int64(x.Year()), nil
case mysql.Duration:
return int64(time.Now().Year()), nil
default:
intVal, err = ToInt64(x)
}
if err != nil {
return invConv(val, tp)
}
y, err := mysql.AdjustYear(int(intVal))
if err != nil {
return invConv(val, tp)
}
return int64(y), nil
case mysql.TypeEnum:
var (
e mysql.Enum
err error
)
switch x := val.(type) {
case string:
e, err = mysql.ParseEnumName(target.Elems, x)
case []byte:
e, err = mysql.ParseEnumName(target.Elems, string(x))
default:
var number uint64
number, err = ToUint64(x)
if err != nil {
return nil, errors.Trace(err)
}
e, err = mysql.ParseEnumValue(target.Elems, number)
}
if err != nil {
return invConv(val, tp)
}
return e, nil
case mysql.TypeSet:
var (
s mysql.Set
err error
)
switch x := val.(type) {
case string:
s, err = mysql.ParseSetName(target.Elems, x)
case []byte:
s, err = mysql.ParseSetName(target.Elems, string(x))
default:
var number uint64
number, err = ToUint64(x)
if err != nil {
return nil, errors.Trace(err)
}
s, err = mysql.ParseSetValue(target.Elems, number)
}
if err != nil {
return invConv(val, tp)
}
return s, nil
case mysql.TypeNull:
return nil, nil
default:
panic("should never happen")
}
}
开发者ID:js-for-kids,项目名称:tidb,代码行数:101,代码来源:convert.go
注:本文中的github.com/pingcap/tidb/mysql.ParseEnumValue函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论