本文整理汇总了Golang中github.com/pingcap/tidb/util/types.Datum.SetMysqlDuration方法的典型用法代码示例。如果您正苦于以下问题:Golang Datum.SetMysqlDuration方法的具体用法?Golang Datum.SetMysqlDuration怎么用?Golang Datum.SetMysqlDuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/util/types.Datum
的用法示例。
在下文中一共展示了Datum.SetMysqlDuration方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: evalDuration
func (e *Evaluator) evalDuration(val []byte) (types.Datum, error) {
var d types.Datum
_, i, err := codec.DecodeInt(val)
if err != nil {
return d, ErrInvalid.Gen("invalid duration %d", i)
}
d.SetMysqlDuration(mysql.Duration{Duration: time.Duration(i), Fsp: mysql.MaxFsp})
return d, nil
}
示例3: convertDateFormat
func convertDateFormat(ctx context.Context, arg types.Datum, b byte) (types.Datum, error) {
var d types.Datum
var err error
switch b {
case 'b':
d, err = builtinMonthName([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(d.GetString()[:3])
}
case 'M':
d, err = builtinMonthName([]types.Datum{arg}, ctx)
case 'm':
d, err = builtinMonth([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'c':
d, err = builtinMonth([]types.Datum{arg}, ctx)
case 'D':
d, err = abbrDayOfMonth(arg, ctx)
case 'd':
d, err = builtinDayOfMonth([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'e':
d, err = builtinDayOfMonth([]types.Datum{arg}, ctx)
case 'j':
d, err = builtinDayOfYear([]types.Datum{arg}, ctx)
if err == nil {
d.SetString(fmt.Sprintf("%03d", d.GetInt64()))
}
case 'H', 'k':
d, err = builtinHour([]types.Datum{arg}, ctx)
if err == nil && b == 'H' && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'h', 'I', 'l':
d, err = builtinHour([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
if d.GetInt64() > 12 {
d.SetInt64(d.GetInt64() - 12)
} else if d.GetInt64() == 0 {
d.SetInt64(12)
}
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'i':
d, err = builtinMinute([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'p':
d, err = builtinHour([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
if d.GetInt64() < 12 {
d.SetString("AM")
break
}
d.SetString("PM")
}
case 'r':
d, err = to12Hour(arg, ctx)
case 'T':
d, err = builtinTime([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
duration := types.Duration{
Duration: d.GetMysqlDuration().Duration,
Fsp: 0}
d.SetMysqlDuration(duration)
}
case 'S', 's':
d, err = builtinSecond([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'f':
d, err = builtinMicroSecond([]types.Datum{arg}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%06d", d.GetInt64()))
}
case 'U':
d, err = builtinWeek([]types.Datum{arg, types.NewIntDatum(0)}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'u':
d, err = builtinWeek([]types.Datum{arg, types.NewIntDatum(1)}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'V':
d, err = builtinWeek([]types.Datum{arg, types.NewIntDatum(2)}, ctx)
if err == nil && !d.IsNull() {
d.SetString(fmt.Sprintf("%02d", d.GetInt64()))
}
case 'v':
d, err = builtinWeek([]types.Datum{arg, types.NewIntDatum(3)}, ctx)
if err == nil && !d.IsNull() {
//.........这里部分代码省略.........