(loc *time.Location, data types.Datum, ret *types.Datum)
| 397 | } |
| 398 | |
| 399 | func flatten(loc *time.Location, data types.Datum, ret *types.Datum) error { |
| 400 | switch data.Kind() { |
| 401 | case types.KindMysqlTime: |
| 402 | // for mysql datetime, timestamp and date type |
| 403 | t := data.GetMysqlTime() |
| 404 | if t.Type() == mysql.TypeTimestamp && loc != nil && loc != time.UTC { |
| 405 | err := t.ConvertTimeZone(loc, time.UTC) |
| 406 | if err != nil { |
| 407 | return errors.Trace(err) |
| 408 | } |
| 409 | } |
| 410 | v, err := t.ToPackedUint() |
| 411 | ret.SetUint64(v) |
| 412 | return errors.Trace(err) |
| 413 | case types.KindMysqlDuration: |
| 414 | // for mysql time type |
| 415 | ret.SetInt64(int64(data.GetMysqlDuration().Duration)) |
| 416 | return nil |
| 417 | case types.KindMysqlEnum: |
| 418 | ret.SetUint64(data.GetMysqlEnum().Value) |
| 419 | return nil |
| 420 | case types.KindMysqlSet: |
| 421 | ret.SetUint64(data.GetMysqlSet().Value) |
| 422 | return nil |
| 423 | case types.KindBinaryLiteral, types.KindMysqlBit: |
| 424 | // We don't need to handle errors here since the literal is ensured to be able to store in uint64 in convertToMysqlBit. |
| 425 | val, err := data.GetBinaryLiteral().ToInt(types.StrictContext) |
| 426 | if err != nil { |
| 427 | return errors.Trace(err) |
| 428 | } |
| 429 | ret.SetUint64(val) |
| 430 | return nil |
| 431 | default: |
| 432 | *ret = data |
| 433 | return nil |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | // DecodeColumnValue decodes data to a Datum according to the column info. |
| 438 | func DecodeColumnValue(data []byte, ft *types.FieldType, loc *time.Location) (types.Datum, error) { |
no test coverage detected
searching dependent graphs…