mysql

package
v0.0.0-...-3d45480 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SeqResetNone    uint8 = 0
	SeqResetOnRead  uint8 = 1
	SeqResetOnWrite uint8 = 2
	SeqResetBoth    uint8 = 3
)

Options to determine when the sequence number should be reset.

Packet constants.

View Source
const (
	HeaderOK  = 0x00
	HeaderEOF = 0xFE
	HeaderErr = 0xFF
)

OK packet constants.

View Source
const (
	ServerStatusInTrans            uint16 = 0x0001
	ServerStatusAutocommit         uint16 = 0x0002
	ServerMoreResultsExists        uint16 = 0x0008
	ServerStatusNoGoodIndexUsed    uint16 = 0x0010
	ServerStatusNoIndexUsed        uint16 = 0x0020
	ServerStatusCursorExists       uint16 = 0x0040
	ServerStatusLastRowSend        uint16 = 0x0080
	ServerStatusDBDropped          uint16 = 0x0100
	ServerStatusNoBackslashEscaped uint16 = 0x0200
	ServerStatusMetadataChanged    uint16 = 0x0400
	ServerStatusWasSlow            uint16 = 0x0800
	ServerPSOutParams              uint16 = 0x1000
	ServerStatusInTransReadonly    uint16 = 0x2000
	ServerSessionStateChanged      uint16 = 0x4000
)

Server information.

View Source
const (
	ClientLongPassword uint32 = 1 << iota
	ClientFoundRows
	ClientLongFlag
	ClientConnectWithDB
	ClientNoSchema
	ClientCompress
	ClientODBC
	ClientLocalFiles
	ClientIgnoreSpace
	ClientProtocol41
	ClientInteractive
	ClientSSL
	ClientIgnoreSigpipe
	ClientTransactions
	ClientReserved
	ClientSecureConnection
	ClientMultiStatements
	ClientMultiResults
	ClientPSMultiResults
	ClientPluginAuth
	ClientConnectAttrs
	ClientPluginAuthLenencClientData
	ClientCanHandleExpiredPasswords
	ClientSessionTrack
	ClientDeprecateEOF
)

Client information.

View Source
const (
	AuthInvalidMethod       = "invalid_dummy_method"
	AuthNativePassword      = "mysql_native_password" // #nosec G101
	AuthCachingSha2Password = "caching_sha2_password" // #nosec G101
	AuthSocket              = "auth_socket"
)

Auth name information.

View Source
const (
	ErrCodeUnknown = 1105
	UnknownState   = "08S01"
)
View Source
const (
	// MaxPayloadLen is the max packet payload length.
	MaxPayloadLen = 1<<24 - 1
)

Variables

View Source
var (
	ErrBadConn = errors.New("connection was bad")

	ErrMalformPacket = errors.New("malform packet")
)

Portable analogs of some common call errors.

View Source
var CollationNames = map[string]uint8{}/* 220 elements not displayed */

CollationNames maps MySQL collation name to its ID

View Source
var Collations = map[uint8]string{}/* 220 elements not displayed */

Collations maps MySQL collation ID to its name.

Functions

This section is empty.

Types

type Buffer

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

Buffer wraps bytes.Buffer for read/write mysql data types.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns the underlying bytes.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of bytes written to the buffer or left to read from the buffer

func (*Buffer) ReadByte

func (b *Buffer) ReadByte() (byte, error)

ReadByte reads a single byte.

func (*Buffer) ReadBytes

func (b *Buffer) ReadBytes(n int) ([]byte, error)

ReadBytes reads n bytes.

func (*Buffer) ReadLenencInt

func (b *Buffer) ReadLenencInt() (uint64, error)

ReadLenencInt reads a lenenc int.

func (*Buffer) ReadLenencString

func (b *Buffer) ReadLenencString() (string, error)

ReadLenencString reads a lenenc string.

func (*Buffer) ReadStringNull

func (b *Buffer) ReadStringNull() (string, error)

ReadStringNull reads a string followed by a null byte.

func (*Buffer) ReadUint16

func (b *Buffer) ReadUint16() (uint16, error)

ReadUint16 reads a uint16.

func (*Buffer) ReadUint24

func (b *Buffer) ReadUint24() (uint32, error)

ReadUint24 reads a uint24.

func (*Buffer) ReadUint32

func (b *Buffer) ReadUint32() (uint32, error)

ReadUint32 reads a uint32.

func (*Buffer) ReadUint64

func (b *Buffer) ReadUint64() (uint64, error)

ReadUint64 reads a uint64.

func (*Buffer) Skip

func (b *Buffer) Skip(n int) error

Skip skips n bytes for read.

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(by byte)

WriteByte writes a single byte.

func (*Buffer) WriteBytes

func (b *Buffer) WriteBytes(bys []byte)

WriteBytes writes bytes.

func (*Buffer) WriteLenencInt

func (b *Buffer) WriteLenencInt(n uint64)

WriteLenencInt writes a lenenc int.

func (*Buffer) WriteLenencString

func (b *Buffer) WriteLenencString(s string)

WriteLenencString writes a lenenc string.

func (*Buffer) WriteStringNull

func (b *Buffer) WriteStringNull(s string)

WriteString writes a string followed by a null byte.

func (*Buffer) WriteUint16

func (b *Buffer) WriteUint16(n uint16)

WriteUint16 writes a uint16.

func (*Buffer) WriteUint24

func (b *Buffer) WriteUint24(n uint32)

WriteUint24 writes a uint24.

func (*Buffer) WriteUint32

func (b *Buffer) WriteUint32(n uint32)

WriteUint32 writes a uint32.

func (*Buffer) WriteUint64

func (b *Buffer) WriteUint64(n uint64)

WriteUint64 writes a uint64.

type Compressor

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

Compressor wraps a Reader and a WriteFlusher for compression.

func NewCompressor

func NewCompressor(r io.Reader, w WriteFlusher) *Compressor

NewCompressor creates a new Compressor.

func (*Compressor) Flush

func (c *Compressor) Flush() error

Flush compress then flush the data to the underlying writer.

func (*Compressor) Read

func (c *Compressor) Read(p []byte) (int, error)

Read reads data from the underlying reader.

func (*Compressor) SetResetOption

func (c *Compressor) SetResetOption(opt uint8)

SetResetOption marks the sequence to be reset on next read or write.

func (*Compressor) Write

func (c *Compressor) Write(p []byte) (int, error)

Write writes data to the underlying writer. It works like bufio.Writer with compression.

type Conn

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

Conn wraps net.Conn for data read/write. MySQL Packets: https://dev.mysql.com/doc/internals/en/mysql-packet.html

func NewConn

func NewConn(conn net.Conn) *Conn

NewConn wraps a raw net.Conn into a Conn.

func (*Conn) Close

func (p *Conn) Close()

Close closes the connection.

func (*Conn) EnableCompression

func (c *Conn) EnableCompression()

EnableCompression wraps the underlying reader and writer to support compression.

func (*Conn) Flush

func (c *Conn) Flush() error

Flush flushes data to the underlying connection.

func (*Conn) RawConn

func (p *Conn) RawConn() net.Conn

RawConn returns the underlying net.Conn.

func (*Conn) ReadPacket

func (c *Conn) ReadPacket(b *bytes.Buffer) error

ReadPacket reads a complete MySQL packet.

func (*Conn) ReadPartialPacket

func (c *Conn) ReadPartialPacket(b *bytes.Buffer) (n int, err error)

ReadpartialPacket reads a MySQL wire packet. It may be part of a larger packet.

func (*Conn) RecvPacket

func (c *Conn) RecvPacket(pkg Packet) error

RecvPacket receives a MySQL packet.

func (*Conn) SendPacket

func (c *Conn) SendPacket(pkt Packet) error

SendPacket sends a MySQL packet.

func (*Conn) SetMaxAllowedPacket

func (c *Conn) SetMaxAllowedPacket(maxAllowedPacket uint64)

SetMaxAllowedPacket sets the maximum packet size.

func (*Conn) SetRawConn

func (c *Conn) SetRawConn(conn net.Conn)

SetRawConn resets the underlying net.Conn. Used for upgrading to TLS.

func (*Conn) SetReadTimeout

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

SetReadTimeout sets the read timeout for the connection.

func (*Conn) SetResetOption

func (c *Conn) SetResetOption(opt uint8)

SetResetOption marks the connection to reset sequence on next read/write.

func (*Conn) WritePacket

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

WritePacket writes data.

type Err

type Err struct {
	Header     byte
	Code       uint16
	State      string
	Message    string
	Capability uint32
}

Err represnets a MySQL packet that contains an error.

func (*Err) Read

func (e *Err) Read(b *Buffer) error

Read reads packet from a buffer.

func (*Err) Write

func (e *Err) Write(b *Buffer)

Write writes the packet to a buffer.

type Handshake

type Handshake struct {
	ProtocolVersion uint8
	ServerVersion   string
	ConnectionID    uint32
	AuthPluginData  []byte
	Capability      uint32
	CharacterSet    uint8
	StatusFlags     uint16
	AuthPluginName  string
}

Handshake is the initial handshake packet sent from server to client.

func (*Handshake) Read

func (s *Handshake) Read(b *Buffer) error

Read reads the packet from a buffer. Support V9 or V10.

func (*Handshake) Write

func (s *Handshake) Write(b *Buffer)

Write writes the packet to a buffer.

type HandshakeResponse

type HandshakeResponse struct {
	Capability    uint32
	MaxPacketSize uint32
	CharacterSet  byte
	UserName      string
	DBName        string
	Auth          []byte
	AuthPlugin    string
	Attrs         map[string]string
}

HandshakerResponse is the initial handshake response from the client.

func (*HandshakeResponse) Read

func (s *HandshakeResponse) Read(b *Buffer) error

Read reads the handshake response from the buffer.

func (*HandshakeResponse) Write

func (s *HandshakeResponse) Write(b *Buffer)

Write writes the handshake response to the buffer.

type Packet

type Packet interface {
	Write(b *Buffer)
	Read(b *Buffer) error
}

Packet is the interface for a MySQL packet.

type WriteFlusher

type WriteFlusher interface {
	io.Writer
	Flush() error
}

WriterFlusher represents a buffered writer. (like bufio.Writer)

Jump to

Keyboard shortcuts

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