asetypes

package
v0.0.0-...-b779cef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2023 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Overview

The package asetypes contains code to link, convert, and work with golang and their respective ASE data types.

Index

Constants

View Source
const (
	ASEDecimalDefaultPrecision = 18
	ASEDecimalDefaultScale     = 0

	ASEMoneyPrecision = 20
	ASEMoneyScale     = 4

	ASEShortMoneyPrecision = 10
	ASEShortMoneyScale     = 4
)

Default properties for ASE data type 'decimal'.

Variables

View Source
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.

View Source
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.

View Source
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.

View Source
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

func (t DataType) ByteSize() int

ByteSize returns the length of the DataTypes byte representation. Non-fixed-length and nullable data types return -1.

func (DataType) Bytes

func (t DataType) Bytes(endian binary.ByteOrder, value interface{}, length int64) ([]byte, error)

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

func (t DataType) GoReflectType() reflect.Type

GoReflectType returns the respective golang data type for given t ASE data type.

func (DataType) GoValue

func (t DataType) GoValue(endian binary.ByteOrder, bs []byte) (interface{}, error)

GoValue returns a value-interface based on a given byte slice and depending on the ASE data type.

func (DataType) LengthBytes

func (t DataType) LengthBytes() int

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

func (t DataType) NullableType() (DataType, error)

NullableType returns the respective nullable type of t, according to the NullableTypes map.

func (DataType) String

func (i DataType) String() string

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

func NewDecimal(precision, scale int) (*Decimal, error)

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

func NewDecimalString(precision, scale int, s string) (*Decimal, error)

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) ByteSize

func (dec Decimal) ByteSize() int

ByteSize calls DecimalByteSize.

func (Decimal) Bytes

func (dec Decimal) Bytes() []byte

Bytes returns the byte-slice of dec.

func (Decimal) Cmp

func (dec Decimal) Cmp(other Decimal) bool

Cmp compares precision, scale, and value between two decimals.

func (Decimal) Int

func (dec Decimal) Int() *big.Int

Int returns a copy of the underlying big.Int.

func (Decimal) IsNegative

func (dec Decimal) IsNegative() bool

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

func (dec *Decimal) SetBytes(b []byte)

SetBytes interprets b as the bytes of a big-endian unsigned integer and sets dec to that values.

func (*Decimal) SetInt64

func (dec *Decimal) SetInt64(i int64)

SetInt64 sets dec.i to i.

func (*Decimal) SetString

func (dec *Decimal) SetString(s string) error

Set decimal to the passed string value. Precision and scale are untouched.

If an error is returned dec is untouched.

func (*Decimal) String

func (dec *Decimal) String() string

type NullBinary

type NullBinary struct {
	ByteSlice []byte
	Valid     bool
}

func (*NullBinary) Scan

func (nb *NullBinary) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullBinary) Value

func (nb NullBinary) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullDecimal

type NullDecimal struct {
	Dec   *Decimal
	Valid bool
}

func (*NullDecimal) Scan

func (nd *NullDecimal) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullDecimal) Value

func (nd NullDecimal) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullFloat32

type NullFloat32 struct {
	Float32 float32
	Valid   bool
}

func (*NullFloat32) Scan

func (nf *NullFloat32) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullFloat32) Value

func (nf NullFloat32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullInt16

type NullInt16 struct {
	Int16 int16
	Valid bool
}

func (*NullInt16) Scan

func (ni *NullInt16) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullInt16) Value

func (ni NullInt16) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullUint16

type NullUint16 struct {
	Uint16 uint16
	Valid  bool
}

func (*NullUint16) Scan

func (nu *NullUint16) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullUint16) Value

func (ni NullUint16) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullUint32

type NullUint32 struct {
	Uint32 uint32
	Valid  bool
}

func (*NullUint32) Scan

func (nu *NullUint32) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullUint32) Value

func (ni NullUint32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullUint64

type NullUint64 struct {
	Uint64 uint64
	Valid  bool
}

func (*NullUint64) Scan

func (nu *NullUint64) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullUint64) Value

func (ni NullUint64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullUint8

type NullUint8 struct {
	Uint8 uint8
	Valid bool
}

func (*NullUint8) Scan

func (nu *NullUint8) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullUint8) Value

func (nu NullUint8) Value() (driver.Value, error)

Value implements the driver Valuer 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL