1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package types
- import (
- "database/sql/driver"
- )
- // IntNull is an implementation of a int for the MySQL type int/tinyint ....
- type IntNull int
- // Value implements the driver.Valuer interface,
- // and turns the bytes into a integer for MySQL storage.
- func (n IntNull) Value() (driver.Value, error) {
- return IntNull(n), nil
- }
- // Scan implements the sql.Scanner interface,
- // and turns the bytes incoming from MySQL into a integer
- func (n *IntNull) Scan(src interface{}) error {
- if src != nil {
- v, ok := src.(int64)
- if !ok {
- *n = IntNull(0)
- return nil
- //return errors.New("bad []byte type assertion")
- }
- *n = IntNull(v)
- return nil
- }
- *n = IntNull(0)
- return nil
- }
- // FloatNull is an implementation of a int for the MySQL type numeric ....
- type FloatNull float64
- // Value implements the driver.Valuer interface,
- // and turns the bytes into a integer for MySQL storage.
- func (n FloatNull) Value() (driver.Value, error) {
- return FloatNull(n), nil
- }
- // Scan implements the sql.Scanner interface,
- // and turns the bytes incoming from MySQL into a numeric
- func (n *FloatNull) Scan(src interface{}) error {
- if src != nil {
- v, ok := src.(float64)
- if !ok {
- *n = FloatNull(0)
- return nil
- //return errors.New("bad []byte type assertion (not float64)")
- }
- *n = FloatNull(v)
- return nil
- }
- *n = FloatNull(0)
- return nil
- }
|