Esempio n. 1
0
func (d *Datum) compareString(s string) (int, error) {
	switch d.k {
	case KindNull, KindMinNotNull:
		return -1, nil
	case KindMaxValue:
		return 1, nil
	case KindString, KindBytes:
		return CompareString(d.GetString(), s), nil
	case KindMysqlDecimal:
		dec := new(mysql.MyDecimal)
		err := dec.FromString([]byte(s))
		return d.GetMysqlDecimal().Compare(dec), err
	case KindMysqlTime:
		dt, err := mysql.ParseDatetime(s)
		return d.GetMysqlTime().Compare(dt), err
	case KindMysqlDuration:
		dur, err := mysql.ParseDuration(s, mysql.MaxFsp)
		return d.GetMysqlDuration().Compare(dur), err
	case KindMysqlBit:
		return CompareString(d.GetMysqlBit().ToString(), s), nil
	case KindMysqlHex:
		return CompareString(d.GetMysqlHex().ToString(), s), nil
	case KindMysqlSet:
		return CompareString(d.GetMysqlSet().String(), s), nil
	case KindMysqlEnum:
		return CompareString(d.GetMysqlEnum().String(), s), nil
	default:
		fVal, err := StrToFloat(s)
		if err != nil {
			return 0, err
		}
		return d.compareFloat64(fVal)
	}
}
Esempio n. 2
0
func (d *Datum) compareMysqlTime(time mysql.Time) (int, error) {
	switch d.k {
	case KindString, KindBytes:
		dt, err := mysql.ParseDatetime(d.GetString())
		return dt.Compare(time), err
	case KindMysqlTime:
		return d.GetMysqlTime().Compare(time), nil
	default:
		fVal, _ := time.ToNumber().ToFloat64()
		return d.compareFloat64(fVal)
	}
}
Esempio n. 3
0
func (s *testUtilSuite) TestDumpBinaryTime(c *C) {
	t, err := mysql.ParseTimestamp("0000-00-00 00:00:00.0000000")
	c.Assert(err, IsNil)
	d := dumpBinaryDateTime(t, nil)
	c.Assert(d, DeepEquals, []byte{11, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0})
	t, err = mysql.ParseDatetime("0000-00-00 00:00:00.0000000")
	c.Assert(err, IsNil)
	d = dumpBinaryDateTime(t, nil)
	c.Assert(d, DeepEquals, []byte{11, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0})

	t, err = mysql.ParseDate("0000-00-00")
	c.Assert(err, IsNil)
	d = dumpBinaryDateTime(t, nil)
	c.Assert(d, DeepEquals, []byte{4, 1, 0, 1, 1})

	myDuration, err := mysql.ParseDuration("0000-00-00 00:00:00.0000000", 6)
	c.Assert(err, IsNil)
	d = dumpBinaryTime(myDuration.Duration)
	c.Assert(d, DeepEquals, []byte{0})
}