Documentation
¶
Overview ¶
The package asetypes contains code to link, convert, and work with golang and their respective ASE data types.
Index ¶
- Constants
- Variables
- type DataType
- func (t DataType) ByteSize() int
- func (t DataType) Bytes(endian binary.ByteOrder, value interface{}, length int64) ([]byte, error)
- func (t DataType) GoReflectType() reflect.Type
- func (t DataType) GoValue(endian binary.ByteOrder, bs []byte) (interface{}, error)
- func (t DataType) LengthBytes() int
- func (t DataType) NullableType() (DataType, error)
- func (i DataType) String() string
- type Decimal
- func (dec Decimal) ByteSize() int
- func (dec Decimal) Bytes() []byte
- func (dec Decimal) Cmp(other Decimal) bool
- func (dec Decimal) Int() *big.Int
- func (dec Decimal) IsNegative() bool
- func (dec *Decimal) Negate()
- func (dec *Decimal) SetBytes(b []byte)
- func (dec *Decimal) SetInt64(i int64)
- func (dec *Decimal) SetString(s string) error
- func (dec *Decimal) String() string
- type NullBinary
- type NullDecimal
- type NullFloat32
- type NullInt16
- type NullUint16
- type NullUint32
- type NullUint64
- type NullUint8
- type ValueConverter
Constants ¶
const ( ASEDecimalDefaultPrecision = 18 ASEDecimalDefaultScale = 0 ASEMoneyPrecision = 20 ASEMoneyScale = 4 ASEShortMoneyPrecision = 10 ASEShortMoneyScale = 4 )
Default properties for ASE data type 'decimal'.
Variables ¶
var ( ErrDecimalPrecisionTooHigh = fmt.Errorf("precision is set to more than %d digits", aseMaxDecimalDigits) ErrDecimalPrecisionTooLow = fmt.Errorf("precision is set to less than 0 digits") ErrDecimalScaleTooHigh = fmt.Errorf("scale is set to more than %d digits", aseMaxDecimalDigits) ErrDecimalScaleBiggerThanPrecision = fmt.Errorf("scale is bigger then precision") )
Errors of ASE data type 'decimal' operations.
var ByteSizes = map[DataType]int{
BIT: 1,
DATE: 4,
DATETIME: 8,
FLT4: 4,
FLT8: 8,
INT1: 1,
INT2: 2,
INT4: 4,
INT8: 8,
INTERVAL: 8,
SINT1: 1,
MONEY: 8,
SHORTDATE: 4,
SHORTMONEY: 4,
TIME: 4,
UINT2: 2,
UINT4: 4,
UINT8: 8,
}
ByteSizes maps a DataType to the length of their byte representation. Only fixed-length DataTypes are listed. Fixed-length DataTypes that are nullable are not listed.
var LengthBytes = map[DataType]int{
BIGDATETIMEN: 1,
BIGTIMEN: 1,
BINARY: 1,
BOUNDARY: 1,
CHAR: 1,
DATEN: 1,
DATETIMEN: 1,
DECN: 1,
FLTN: 1,
IMAGE: 4,
INTN: 1,
LONGBINARY: 4,
LONGCHAR: 4,
MONEYN: 1,
NUMN: 1,
SENSITIVITY: 1,
TEXT: 4,
TIMEN: 1,
UINTN: 1,
UNITEXT: 4,
VARBINARY: 1,
VARCHAR: 1,
XML: 4,
}
LengthBytes maps a DataType to number of bytes in their length property. Only non-fixed-length or nullable DataTypes are listed.
var ReflectTypes = map[DataType]reflect.Type{ BIGDATETIMEN: reflect.TypeOf(time.Time{}), BIGTIMEN: reflect.TypeOf(time.Time{}), BINARY: reflect.SliceOf(reflect.TypeOf(byte(0))), BIT: reflect.TypeOf(bool(false)), BLOB: reflect.SliceOf(reflect.TypeOf(byte(0))), BOUNDARY: nil, CHAR: reflect.TypeOf(string("")), DATE: reflect.TypeOf(time.Time{}), DATEN: reflect.TypeOf(time.Time{}), DATETIME: reflect.TypeOf(time.Time{}), DATETIMEN: reflect.TypeOf(time.Time{}), DECN: reflect.TypeOf(&Decimal{}), FLT4: reflect.TypeOf(float32(0)), FLT8: reflect.TypeOf(float64(0)), FLTN: reflect.TypeOf(float64(0)), IMAGE: reflect.SliceOf(reflect.TypeOf(byte(0))), INT1: reflect.TypeOf(uint8(0)), INT2: reflect.TypeOf(int16(0)), INT4: reflect.TypeOf(int32(0)), INT8: reflect.TypeOf(int64(0)), INTN: reflect.TypeOf(int64(0)), LONGBINARY: reflect.SliceOf(reflect.TypeOf(byte(0))), LONGCHAR: reflect.TypeOf(string("")), MONEY: reflect.TypeOf(&Decimal{}), MONEYN: reflect.TypeOf(&Decimal{}), NUMN: reflect.TypeOf(&Decimal{}), SENSITIVITY: nil, SHORTDATE: reflect.TypeOf(time.Time{}), SHORTMONEY: reflect.TypeOf(&Decimal{}), TEXT: reflect.TypeOf(string("")), TIME: reflect.TypeOf(time.Time{}), TIMEN: reflect.TypeOf(time.Time{}), UINT2: reflect.TypeOf(uint16(0)), UINT4: reflect.TypeOf(uint32(0)), UINT8: reflect.TypeOf(uint64(0)), UINTN: reflect.TypeOf(uint64(0)), UNITEXT: reflect.TypeOf(string("")), VARBINARY: reflect.SliceOf(reflect.TypeOf(byte(0))), VARCHAR: reflect.TypeOf(string("")), VOID: nil, XML: reflect.SliceOf(reflect.TypeOf(byte(0))), INTERVAL: nil, SINT1: nil, USER_TEXT: nil, USER_IMAGE: nil, USER_UNITEXT: nil, }
ReflectTypes maps the golang data type for the respective ASE data type.
Functions ¶
This section is empty.
Types ¶
type DataType ¶
type DataType byte
DataType is the type for valuemask values of a data type valuemask.
const ( BIGDATETIMEN DataType = 0xBB BIGTIMEN DataType = 0xBC BINARY DataType = 0x2D BIT DataType = 0x32 BLOB DataType = 0x24 BOUNDARY DataType = 0x68 CHAR DataType = 0x2F DATE DataType = 0x31 DATEN DataType = 0x7B DATETIME DataType = 0x3D DATETIMEN DataType = 0x6f DECN DataType = 0x6A FLT4 DataType = 0x3B FLT8 DataType = 0x3E FLTN DataType = 0x6D IMAGE DataType = 0x22 INT1 DataType = 0x30 INT2 DataType = 0x34 INT4 DataType = 0x38 INT8 DataType = 0xBF INTN DataType = 0x26 LONGBINARY DataType = 0xE1 LONGCHAR DataType = 0xAF MONEY DataType = 0x3C MONEYN DataType = 0x6E NUMN DataType = 0x6C SENSITIVITY DataType = 0x67 SHORTDATE DataType = 0x3A SHORTMONEY DataType = 0x7A TEXT DataType = 0x23 TIME DataType = 0x33 TIMEN DataType = 0x93 UINT2 DataType = 0x41 UINT4 DataType = 0x42 UINT8 DataType = 0x43 UINTN DataType = 0x44 UNITEXT DataType = 0xAE VARBINARY DataType = 0x25 VARCHAR DataType = 0x27 VOID DataType = 0x1f XML DataType = 0xA3 // Missing in tdspublic.h INTERVAL DataType = 0x2e SINT1 DataType = 0xb0 // TDS usertypes USER_TEXT DataType = 0x19 USER_IMAGE DataType = 0x20 USER_UNITEXT DataType = 0x36 )
ASE data types in a TDS-based application.
func (DataType) ByteSize ¶
ByteSize returns the length of the DataTypes byte representation. Non-fixed-length and nullable data types return -1.
func (DataType) Bytes ¶
Bytes returns a byte slice based on a given value-interface and depending on the ASE data type. TODO: Instead of parameter 'length', one could use a struct to store additional optional parameters, e.g. 'length', 'datastatus', ... (Problem: golang mod import cycle)
func (DataType) GoReflectType ¶
GoReflectType returns the respective golang data type for given t ASE data type.
func (DataType) GoValue ¶
GoValue returns a value-interface based on a given byte slice and depending on the ASE data type.
func (DataType) LengthBytes ¶
LengthBytes returns the number of bytes in the length property of the data type. For fixed-length data types -1 is returned.
func (DataType) NullableType ¶
NullableType returns the respective nullable type of t, according to the NullableTypes map.
type Decimal ¶
type Decimal struct {
Precision, Scale int
// contains filtered or unexported fields
}
Decimal only carries the information of Decimal, Numeric and Money ASE datatypes. This is only sufficient for displaying, not calculations.
func NewDecimal ¶
NewDecimal creates a new decimal with the passed precision and scale and returns it. An error is returned if the precision/scale combination is not valid.
func NewDecimalString ¶
NewDecimalString creates a new decimal based on the passed string. If the string contains an invalid precision/scale combination an error is returned.
func (Decimal) IsNegative ¶
IsNegative returns true if dec is negative.
func (*Decimal) Negate ¶
func (dec *Decimal) Negate()
Negate sets dec to the value of it with its sign negated.
func (*Decimal) SetBytes ¶
SetBytes interprets b as the bytes of a big-endian unsigned integer and sets dec to that values.
type NullBinary ¶
func (*NullBinary) Scan ¶
func (nb *NullBinary) Scan(value interface{}) error
Scan implements the Scanner interface.
type NullDecimal ¶
func (*NullDecimal) Scan ¶
func (nd *NullDecimal) Scan(value interface{}) error
Scan implements the Scanner interface.
type NullFloat32 ¶
func (*NullFloat32) Scan ¶
func (nf *NullFloat32) Scan(value interface{}) error
Scan implements the Scanner interface.
type NullUint16 ¶
func (*NullUint16) Scan ¶
func (nu *NullUint16) Scan(value interface{}) error
Scan implements the Scanner interface.
type NullUint32 ¶
func (*NullUint32) Scan ¶
func (nu *NullUint32) Scan(value interface{}) error
Scan implements the Scanner interface.
type NullUint64 ¶
func (*NullUint64) Scan ¶
func (nu *NullUint64) Scan(value interface{}) error
Scan implements the Scanner interface.
type ValueConverter ¶
type ValueConverter struct{}
ValueConverter implements the driver.types.ValueConverter interface.
var DefaultValueConverter ValueConverter
DefaultValueConverter implements the driver.types.ValueConverter interface.
func (ValueConverter) ConvertValue ¶
func (conv ValueConverter) ConvertValue(v interface{}) (driver.Value, error)
ConvertValue implements the driver.types.ValueConverter interface.