本文整理汇总了Golang中github.com/pingcap/tidb/util/types.Datum.SetMysqlTime方法的典型用法代码示例。如果您正苦于以下问题:Golang Datum.SetMysqlTime方法的具体用法?Golang Datum.SetMysqlTime怎么用?Golang Datum.SetMysqlTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/util/types.Datum
的用法示例。
在下文中一共展示了Datum.SetMysqlTime方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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 types.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 := types.Duration{Duration: time.Duration(datum.GetInt64())}
datum.SetValue(dur)
return datum, nil
case mysql.TypeEnum:
enum, err := types.ParseEnumValue(ft.Elems, datum.GetUint64())
if err != nil {
return datum, errors.Trace(err)
}
datum.SetValue(enum)
return datum, nil
case mysql.TypeSet:
set, err := types.ParseSetValue(ft.Elems, datum.GetUint64())
if err != nil {
return datum, errors.Trace(err)
}
datum.SetValue(set)
return datum, nil
case mysql.TypeBit:
bit := types.Bit{Value: datum.GetUint64(), Width: ft.Flen}
datum.SetValue(bit)
return datum, nil
}
return datum, nil
}
示例2: builtinStrToDate
// See https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date
func builtinStrToDate(args []types.Datum, _ context.Context) (types.Datum, error) {
date := args[0].GetString()
format := args[1].GetString()
var (
d types.Datum
t types.Time
)
succ := t.StrToDate(date, format)
if !succ {
d.SetNull()
return d, nil
}
d.SetMysqlTime(t)
return d, nil
}
示例3: getZeroValue
func getZeroValue(col *model.ColumnInfo) types.Datum {
var d types.Datum
switch col.Tp {
case mysql.TypeTiny, mysql.TypeInt24, mysql.TypeShort, mysql.TypeLong, mysql.TypeLonglong, mysql.TypeYear:
if mysql.HasUnsignedFlag(col.Flag) {
d.SetUint64(0)
} else {
d.SetInt64(0)
}
case mysql.TypeFloat:
d.SetFloat32(0)
case mysql.TypeDouble:
d.SetFloat64(0)
case mysql.TypeNewDecimal:
d.SetMysqlDecimal(mysql.NewDecimalFromInt(0, 0))
case mysql.TypeString, mysql.TypeVarString, mysql.TypeVarchar:
d.SetString("")
case mysql.TypeBlob, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob:
d.SetBytes([]byte{})
case mysql.TypeDuration:
d.SetMysqlDuration(mysql.ZeroDuration)
case mysql.TypeDate, mysql.TypeNewDate:
d.SetMysqlTime(mysql.ZeroDate)
case mysql.TypeTimestamp:
d.SetMysqlTime(mysql.ZeroTimestamp)
case mysql.TypeDatetime:
d.SetMysqlTime(mysql.ZeroDatetime)
case mysql.TypeBit:
d.SetMysqlBit(mysql.Bit{Value: 0, Width: mysql.MinBitWidth})
case mysql.TypeSet:
d.SetMysqlSet(mysql.Set{})
}
return d
}
示例4: unflatten
// unflatten converts a raw datum to a column datum.
func unflatten(datum types.Datum, ft *types.FieldType) (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
err := t.Unmarshal(datum.GetBytes())
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.TypeNewDecimal:
if datum.Kind() == types.KindMysqlDecimal {
if ft.Decimal >= 0 {
dec := datum.GetMysqlDecimal().Truncate(int32(ft.Decimal))
datum.SetMysqlDecimal(dec)
}
return datum, nil
}
dec, err := mysql.ParseDecimal(datum.GetString())
if err != nil {
return datum, errors.Trace(err)
}
if ft.Decimal >= 0 {
dec = dec.Truncate(int32(ft.Decimal))
}
datum.SetValue(dec)
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
}