mconn

package
v0.0.0-...-1609ee8 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldTypeDecimal = iota
	FieldTypeTiny
	FieldTypeShort
	FieldTypeLong
	FieldTypeFloat
	FieldTypeDouble
	FieldTypeNull
	FieldTypeTimestamp
	FieldTypeLongLong
	FieldTypeInt24
	FieldTypeDate
	FieldTypeTime
	FieldTypeDateTime
	FieldTypeYear
	FieldTypeNewDate
	FieldTypeVarChar
	FieldTypeBit
	FieldTypeTimestamp2
	FieldTypeDateTime2
	FieldTypeTime2
)

FieldType is type of mysql field

View Source
const (
	FieldTypeJSON = 0xf5 + iota
	FieldTypeNewDecimal
	FieldTypeEnum
	FieldTypeSet
	FieldTypeTinyBlob
	FieldTypeMediumBlob
	FieldTypeLongBlob
	FieldTypeBlob
	FieldTypeVarString
	FieldTypeString
	FieldTypeGeometry
)

FieldType is type of mysql field

View Source
const (
	PacketHeaderOK          = 0x00
	PacketHeaderEOF         = 0xfe
	PacketHeaderLocalInFile = 0xfb
	PacketHeaderERR         = 0xff
)
View Source
const (
	CharsetBig5ChineseCI      // 1
	CharsetLatin2CzechCS      // 2
	CharsetDec8SwedishCI      // 3
	CharsetCp850GeneralCI     // 4
	CharsetGerman1CI          // 5
	CharsetHp8EnglishCI       // 6
	CharsetKoi8rGeneralCI     // 7
	CharsetLatin1SwedishCI    // 8
	CharsetLatin2GeneralCI    // 9
	CharsetSwe7SwedishCI      // 10
	CharsetAsciiGeneralCI     // 11
	CharsetUjisJapaneseCI     // 12
	CharsetSjisJapaneseCI     // 13
	CharsetCp1251BulgarianCI  // 14
	CharsetLatin1DanishCI     // 15
	CharsetHebrewGeneralCI    // 16
	CharsetMissing1           // 17
	CharsetTis620ThaiCI       // 18
	CharsetEuckrKoreanCI      // 19
	CharsetLatin7EstonianCS   // 20
	CharsetLatin2HungarianCI  // 21
	CharsetKoi8uGeneralCI     // 22
	CharsetCp1251UkrainianCI  // 23
	CharsetGb2312ChineseCI    // 24
	CharsetGreekGeneralCI     // 25
	CharsetCp1250GeneralCI    // 26
	CharsetLatin2CroatianCI   // 27
	CharsetGbkChineseCI       // 28
	CharsetCp1257LithuanianCI // 29
	CharsetLatin5KurkishCI    // 30
	CharsetLatin1German2CI    // 31
	CharsetArmscii8GeneralCI  // 32
	CharsetUtf8GeneralCI      // 33
)

Charset SELECT id, collation_name FROM information_schema.collations ORDER BY id; https://dev.mysql.com/doc/internals/en/character-set.html#packet-Protocol::CharacterSet Not all charset ...

View Source
const (
	// MySQLNativePasswordPlugin is the mysql native password auth type
	MySQLNativePasswordPlugin = "mysql_native_password"
)

Variables

View Source
var (
	// ErrNoData no datas in the result set
	ErrNoData = errors.New("No data in the result set")
	// ErrColumnOutOfRange represent the index if out of column count
	ErrColumnOutOfRange = errors.New("Index out of column range")
	// ErrInvalidConn returns when connection is invalid
	ErrInvalidConn = errors.New("Invalid conn")
	// ErrRowNotFree represents the connection has a query and not closed
	ErrRowNotFree = errors.New("Query row not free")
	// ErrWrongFieldType returns when get field data with wrong type
	ErrWrongFieldType = errors.New("Wrong field type")
)
View Source
var (
	// ErrMalformPacket represents a response with the unknown header
	ErrMalformPacket = errors.New("Malform packet format")
)

Functions

This section is empty.

Types

type Conn

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

Conn is a connection communicate with the mysql server

func (*Conn) Close

func (c *Conn) Close()

Close the connection

func (*Conn) Connect

func (c *Conn) Connect(ds *DataSource, database string) error

Connect connects to the mysql server

func (*Conn) Exec

func (c *Conn) Exec(command string, args ...interface{}) (*PacketOK, error)

Exec execute the text-query command or bingding data command

func (*Conn) GetHandshakeInfo

func (c *Conn) GetHandshakeInfo(si *HandshakeInfo)

GetHandshakeInfo get the server information by handshake

func (*Conn) GetStatus

func (c *Conn) GetStatus() int64

GetStatus returns the status of the connection

func (*Conn) Read

func (c *Conn) Read(p []byte) (n int, err error)

Read implement io.Reader interface

func (*Conn) ReadPacket

func (c *Conn) ReadPacket() ([]byte, error)

ReadPacket reads the full packet from mysql

func (*Conn) RegisterSlave

func (c *Conn) RegisterSlave(rc *ReplicationConfig) error

RegisterSlave register the connection as a slave connection

func (*Conn) SetKeepalive

func (c *Conn) SetKeepalive(d time.Duration) bool

SetKeepalive enables the tcp keepalive

func (*Conn) SetReadTimeout

func (c *Conn) SetReadTimeout(dura time.Duration)

SetReadTimeout set the read timeout duration

func (*Conn) StartDumpBinlog

func (c *Conn) StartDumpBinlog(pos ReplicationPoint) error

StartDumpBinlog start dump binlog from master

func (*Conn) WritePacket

func (c *Conn) WritePacket(data []byte) error

WritePacket writes the packet to mysql, data must has 4 bytes unused in head

type DBConfig

type DBConfig struct {
	Type     string `json:"type" toml:"type"`
	Host     string `json:"host" toml:"host"`
	Port     uint16 `json:"port" toml:"port"`
	Username string `json:"username" toml:"username"`
	Password string `json:"password" toml:"password"`
	Charset  string `json:"charset" toml:"charset"`
}

DBConfig is the connection information to db server

type DataSource

type DataSource struct {
	Host     string `json:"host" toml:"host"`
	Port     uint16 `json:"port" toml:"port"`
	Username string `json:"username" toml:"username"`
	Password string `json:"password" toml:"password"`
}

DataSource is a mysql instance to pull binlog stream

func (*DataSource) Address

func (s *DataSource) Address() string

Address returns the address of the data source

type Field

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

Field is a mysql field

type HandshakeInfo

type HandshakeInfo struct {
	ProtoVersion  byte
	ServerVersion string
	ConnectionID  uint32
}

HandshakeInfo represents the mysql server information returned by handshake

func (*HandshakeInfo) String

func (i *HandshakeInfo) String() string

type LenencInt

type LenencInt struct {
	Flag  uint8
	Value uint64
	EOF   bool
}

LenencInt is a length encoded integer type https://dev.mysql.com/doc/internals/en/integer.html#length-encoded-integer

func (*LenencInt) FromData

func (i *LenencInt) FromData(data []byte) int

FromData reads value from a binary data

func (*LenencInt) Get

func (i *LenencInt) Get() uint64

Get gets the lenenc int number as normal number

func (*LenencInt) Set

func (i *LenencInt) Set(v uint64)

Set stores normal number in lenenc number format

type LenencString

type LenencString struct {
	Len   LenencInt
	Value string
	EOF   bool
}

LenencString is a length prefixed string

func (*LenencString) FromData

func (s *LenencString) FromData(data []byte) int

FromData parse binary data to lenenc string

type PacketBinlogDump

type PacketBinlogDump struct {
	BinlogPos  uint32
	Flags      uint16
	ServerID   uint32
	BinlogFile string
}

PacketBinlogDump to enable replication

func (*PacketBinlogDump) Encode

func (p *PacketBinlogDump) Encode() ([]byte, error)

Encode encodes the packet to binary data

type PacketComStr

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

PacketComStr is used to send the server a text-based query that is executed immediately

func (*PacketComStr) Encode

func (p *PacketComStr) Encode() ([]byte, error)

Encode encodes the packet to binary data

type PacketEOF

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

PacketEOF represents the eof of packets

func (*PacketEOF) Decode

func (p *PacketEOF) Decode(data []byte) error

Decode decodes binary data to mysql packet

type PacketErr

type PacketErr struct {
	Header uint8
	// ERR packet fields
	ErrorCode    uint16
	State        string
	ErrorMessage string
	// contains filtered or unexported fields
}

PacketErr parses mysql OK_Packet https://dev.mysql.com/doc/internals/en/packet-ERR_Packet.html

func (*PacketErr) Decode

func (p *PacketErr) Decode(data []byte) error

Decode decodes binary data to mysql packet

type PacketHandshake

type PacketHandshake struct {
	ProtocolVersion    uint8
	ServerVersion      string
	ConnectionID       uint32
	AuthPluginDataPart []byte
	Filter             uint8
	CapabilityFlags    uint32
	CharacterSet       uint8
	StatusFlags        uint16
	AuthPluginName     string
}

PacketHandshake is handshake packet sending from server

func (*PacketHandshake) Decode

func (p *PacketHandshake) Decode(data []byte) error

Decode read binary data into handshake packet https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake

type PacketHandshakeResponse

type PacketHandshakeResponse struct {
	CapabilityFlags uint32
	MaxPacketSize   uint32
	Charset         uint8
	// Reserved        [23]byte not used
	Username string // string[null]
	Password string

	AuthResponseLength LenencInt
	Database           string
	// Decode part
	AuthPluginData []byte
	// contains filtered or unexported fields
}

PacketHandshakeResponse responses the handshake packet to server https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse

func (*PacketHandshakeResponse) Encode

func (p *PacketHandshakeResponse) Encode() []byte

Encode serialize the handshake response

type PacketHeader

type PacketHeader [4]byte

PacketHeader is the header of the mysql packet to read the packet length and sequence

func (*PacketHeader) GetLength

func (p *PacketHeader) GetLength() int

GetLength returns the header length

func (*PacketHeader) GetSequence

func (p *PacketHeader) GetSequence() uint8

GetSequence returns the header sequence

func (*PacketHeader) SetLength

func (p *PacketHeader) SetLength(v int)

SetLength set the length into underlying array

func (*PacketHeader) SetSequence

func (p *PacketHeader) SetSequence(v uint8)

SetSequence sets the packet sequence

func (*PacketHeader) ToSlice

func (p *PacketHeader) ToSlice() []byte

ToSlice returns a slice reference to the underlying array

type PacketMySQL

type PacketMySQL interface {
	Encode() ([]byte, error)
	Decode([]byte) error
}

PacketMySQL defines mysql packet interface

type PacketOK

type PacketOK struct {
	Header uint8
	// OK packet fields
	AffectedRows uint64
	LastInsertID uint64
	StatusFlags  uint16 // StatusFlags has value : client protocol 41 or client transactions
	Warnings     uint16
	// EOF
	EOF bool
	// Result set
	ColumnCount LenencInt
	Results     *ResultSet
	// contains filtered or unexported fields
}

PacketOK parses mysql OK_Packet https://dev.mysql.com/doc/internals/en/packet-OK_Packet.html

func (*PacketOK) Decode

func (p *PacketOK) Decode(data []byte) error

Decode decodes binary data to mysql packet

type PacketRegisterSlave

type PacketRegisterSlave struct {
	ServerID uint32
	Hostname string
	User     string
	Password string
	Port     uint16
	Rank     uint32
	MasterID uint32
}

PacketRegisterSlave register slave to master https://dev.mysql.com/doc/internals/en/com-register-slave.html

func (*PacketRegisterSlave) Encode

func (p *PacketRegisterSlave) Encode() ([]byte, error)

Encode encodes the packet to binary data

type ReplicationConfig

type ReplicationConfig struct {
	SlaveID uint32 `json:"slave-id" toml:"slave-id"`
	//Pos             Position `json:"position" toml:"position"`
	EnableGtid      bool `json:"enable-gtid" toml:"enable-gtid"`
	EventBufferSize int  `json:"event-buffer-size" toml:"event-buffer-size"`
	KeepAlivePeriod int  `json:"keepalive-period" toml:"keepalive-period"`
}

ReplicationConfig specify the master information

type ReplicationPoint

type ReplicationPoint struct {
	Filename string
	Offset   uint32
	Gtid     string
}

Position represents a binlog replication position, slave can start sync with the position

type ResultSet

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

ResultSet contains all column field

func (*ResultSet) Close

func (s *ResultSet) Close() error

Close close the result set

func (*ResultSet) Columns

func (s *ResultSet) Columns() int

Columns get the column count

func (*ResultSet) GetAt

func (s *ResultSet) GetAt(i int) (interface{}, error)

GetAt get the value of index i

func (*ResultSet) GetAtString

func (s *ResultSet) GetAtString(i int) (string, error)

GetAtString get the value of index i as string

func (*ResultSet) Next

func (s *ResultSet) Next() error

Next get the next row data If eof, io.ErrEOF will be returned

Jump to

Keyboard shortcuts

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