mysql

package
v0.0.0-...-be37d25 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Timezone = time.UTC

Timezone is set for decoded datetime values.

Functions

func DecodeBit

func DecodeBit(data []byte, nbits int, length int) (v uint64, n int)

DecodeBit decodes a bit into not less than 8 bytes.

func DecodeDate

func DecodeDate(v uint32) string

DecodeDate ...

func DecodeDatetime

func DecodeDatetime(v uint64) string

DecodeDatetime ...

func DecodeDatetime2

func DecodeDatetime2(data []byte, dec uint16) (string, int)

DecodeDatetime2 ... Implementation borrowed from https://github.com/siddontang/go-mysql/

func DecodeFloat32

func DecodeFloat32(data []byte) float32

DecodeFloat32 decodes a float value into a float32.

func DecodeFloat64

func DecodeFloat64(data []byte) float64

DecodeFloat64 decodes a double value into a float64.

func DecodeJSON

func DecodeJSON(data []byte) ([]byte, error)

DecodeJSON decodes JSON into raw bytes. Implementation borrowed from https://github.com/siddontang/go-mysql/

func DecodeStringEOF

func DecodeStringEOF(data []byte) []byte

DecodeStringEOF copies given slice of bytes as a new string.

func DecodeStringLenEnc

func DecodeStringLenEnc(data []byte) (str []byte, size int)

DecodeStringLenEnc decodes a length-encoded string from a given slice of bytes.

func DecodeStringNullTerm

func DecodeStringNullTerm(data []byte) []byte

DecodeStringNullTerm decodes a null terminated string from a given slice of bytes.

func DecodeStringVarLen

func DecodeStringVarLen(data []byte, n int) []byte

DecodeStringVarLen decodes a varible-length string from a given slice of bytes.

func DecodeTime

func DecodeTime(v uint32) string

DecodeTime ...

func DecodeTime2

func DecodeTime2(data []byte, dec uint16) (string, int)

DecodeTime2 ... Implementation borrowed from https://github.com/siddontang/go-mysql/

func DecodeTimestamp2

func DecodeTimestamp2(data []byte, dec uint16) (string, int)

DecodeTimestamp2 ... Implementation borrowed from https://github.com/siddontang/go-mysql/

func DecodeUint16

func DecodeUint16(data []byte) uint16

DecodeUint16 decodes a uint16 value from a given slice of bytes.

func DecodeUint24

func DecodeUint24(data []byte) uint32

DecodeUint24 decodes 3 bytes as uint32 value from a given slice of bytes.

func DecodeUint32

func DecodeUint32(data []byte) uint32

DecodeUint32 decodes a uint32 value from a given slice of bytes.

func DecodeUint48

func DecodeUint48(data []byte) uint64

DecodeUint48 decodes 6 bytes as uint64 value from a given slice of bytes.

func DecodeUint64

func DecodeUint64(data []byte) uint64

DecodeUint64 decodes a uint64 value from a given slice of bytes.

func DecodeUint8

func DecodeUint8(data []byte) uint8

DecodeUint8 decodes a uint8 value from a given slice of bytes.

func DecodeUintLenEnc

func DecodeUintLenEnc(data []byte) (v uint64, isNull bool, size int)

DecodeUintLenEnc decodes a length-encoded integer from a given slice of bytes.

To convert a length-encoded integer into its numeric value, check the first byte: If it is < 0xFB, treat it as a 1-byte integer. If it is 0xFC, it is followed by a 2-byte integer. If it is 0xFD, it is followed by a 3-byte integer. If it is 0xFE, it is followed by a 8-byte integer. Depending on the context, the first byte may also have other meanings: If it is 0xFB, it is represents a NULL in a ProtocolText::ResultsetRow. If it is 0xFF and is the first byte of an ERR_Packet Caution: If the first byte of a packet is a length-encoded integer and its byte value is 0xFE, you must check the length of the packet to verify that it has enough space for a 8-byte integer. If not, it may be an EOF_Packet instead.

func DecodeVarLen64

func DecodeVarLen64(data []byte, s int) uint64

DecodeVarLen64 decodes a number of given size in bytes using Little Endian.

func DecodeVarLen64BigEndian

func DecodeVarLen64BigEndian(data []byte) uint64

DecodeVarLen64BigEndian decodes a number of given size in bytes using Big Endian.

func DecodeYear

func DecodeYear(v uint8) uint16

DecodeYear ...

func EncodeStringVarLen

func EncodeStringVarLen(data, str []byte)

EncodeStringVarLen encodes a variable-length string into a given slice of bytes.

func EncodeUint16

func EncodeUint16(data []byte, v uint16)

EncodeUint16 encodes given uint16 value into a slice of bytes.

func EncodeUint24

func EncodeUint24(data []byte, v uint32)

EncodeUint24 encodes given uint32 value as a 3-byte integer into a slice of bytes.

func EncodeUint32

func EncodeUint32(data []byte, v uint32)

EncodeUint32 encodes given uint32 value into a slice of bytes.

func EncodeUint48

func EncodeUint48(data []byte, v uint64)

EncodeUint48 encodes given uint64 value as a 6-byte integer into a slice of bytes.

func EncodeUint64

func EncodeUint64(data []byte, v uint64)

EncodeUint64 encodes given uint64 value into a slice of bytes.

func EncodeUint8

func EncodeUint8(data []byte, v uint8)

EncodeUint8 encodes given uint8 value into a slice of bytes.

func EncodeUintLenEnc

func EncodeUintLenEnc(data []byte, v uint64, isNull bool) (size int)

EncodeUintLenEnc writes a length-encoded integer into a given slice of bytes and returns the length of an encoded value.

To convert a number value into a length-encoded integer: If the value is < 251, it is stored as a 1-byte integer. If the value is ≥ 251 and < (2^16), it is stored as 0xFC + 2-byte integer. If the value is ≥ (2^16) and < (2^24), it is stored as 0xFD + 3-byte integer. If the value is ≥ (2^24) and < (2^64) it is stored as 0xFE + 8-byte integer. Note: up to MySQL 3.22, 0xFE was followed by a 4-byte integer.

func SignUint16

func SignUint16(v uint16) int16

SignUint16 converts uint16 into int16.

func SignUint24

func SignUint24(v uint32) int32

SignUint24 converts 3-byte uint32 into int32.

func SignUint32

func SignUint32(v uint32) int32

SignUint32 converts uint32 into int32.

func SignUint64

func SignUint64(v uint64) int64

SignUint64 converts uint64 into int64.

func SignUint8

func SignUint8(v uint8) int8

SignUint8 converts uint8 into int8.

Types

type ColumnType

type ColumnType byte

ColumnType represents MySQL column type.

const (
	ColumnTypeDecimal    ColumnType = 0x00
	ColumnTypeTiny       ColumnType = 0x01
	ColumnTypeShort      ColumnType = 0x02
	ColumnTypeLong       ColumnType = 0x03
	ColumnTypeFloat      ColumnType = 0x04
	ColumnTypeDouble     ColumnType = 0x05
	ColumnTypeNull       ColumnType = 0x06
	ColumnTypeTimestamp  ColumnType = 0x07
	ColumnTypeLonglong   ColumnType = 0x08
	ColumnTypeInt24      ColumnType = 0x09
	ColumnTypeDate       ColumnType = 0x0a
	ColumnTypeTime       ColumnType = 0x0b
	ColumnTypeDatetime   ColumnType = 0x0c
	ColumnTypeYear       ColumnType = 0x0d
	ColumnTypeNewDate    ColumnType = 0x0e // Internal
	ColumnTypeVarchar    ColumnType = 0x0f
	ColumnTypeBit        ColumnType = 0x10
	ColumnTypeTimestamp2 ColumnType = 0x11 // Internal
	ColumnTypeDatetime2  ColumnType = 0x12 // Internal
	ColumnTypeTime2      ColumnType = 0x13 // Internal

	ColumnTypeJSON       ColumnType = 0xF5
	ColumnTypeNewDecimal ColumnType = 0xF6
	ColumnTypeEnum       ColumnType = 0xF7
	ColumnTypeSet        ColumnType = 0xF8
	ColumnTypeTinyblob   ColumnType = 0xF9
	ColumnTypeMediumblob ColumnType = 0xFA
	ColumnTypeLongblob   ColumnType = 0xFB
	ColumnTypeBlob       ColumnType = 0xFC
	ColumnTypeVarstring  ColumnType = 0xFD
	ColumnTypeString     ColumnType = 0xFE
	ColumnTypeGeometry   ColumnType = 0xFF
)

Spec: https://dev.mysql.com/doc/internals/en/com-query-response.html#column-type

func (ColumnType) String

func (ct ColumnType) String() string

type Decimal

type Decimal struct {
	// contains filtered or unexported fields
}

Decimal represents a decimal type that retains precision until converted to a float. It is designed to be marshaled into JSON without losing precision.

func DecodeDecimal

func DecodeDecimal(data []byte, precision int, decimals int) (Decimal, int)

DecodeDecimal decodes a decimal value. Implementation borrowed from https://github.com/siddontang/go-mysql/

func NewDecimal

func NewDecimal(str string) Decimal

NewDecimal creates a new decimal with given value.

func (Decimal) Float64

func (d Decimal) Float64() float64

Float64 returns a float representation of the decimal. Precision could be lost.

func (Decimal) MarshalJSON

func (d Decimal) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the decimal.

func (Decimal) String

func (d Decimal) String() string

func (Decimal) Value

func (d Decimal) Value() (driver.Value, error)

Value returns a driver Value.

type FracTime

type FracTime struct {
	time.Time
	Dec int
}

FracTime is a help structure wrapping Golang Time.

func (FracTime) String

func (t FracTime) String() string

Jump to

Keyboard shortcuts

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