mysql

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryRow

type BinaryRow struct {
	Values []*proto.Value
	// contains filtered or unexported fields
}

func (BinaryRow) Columns added in v0.4.0

func (row BinaryRow) Columns() []string

func (BinaryRow) Data added in v0.4.0

func (row BinaryRow) Data() []byte

func (*BinaryRow) Decode

func (row *BinaryRow) Decode() ([]*proto.Value, error)

func (BinaryRow) Fields added in v0.4.0

func (row BinaryRow) Fields() []proto.Field

type Conn

type Conn struct {
	ReadTimeout  time.Duration // I/O read timeout
	WriteTimeout time.Duration // I/O write timeout
	// contains filtered or unexported fields
}

Conn is a connection between a client and a server, using the MySQL binary protocol. It is built on top of an existing net.Conn, that has already been established.

Use Connect on the client side to create a connection. Use NewListener to create a server side and listen for connections.

func NewConn

func NewConn(conn net.Conn) *Conn

NewConn is an internal method to create a Conn. Used by client and server side for common creation code.

func (*Conn) Close

func (c *Conn) Close()

Close closes the connection. It can be called from a different go routine to interrupt the current connection.

func (*Conn) DrainResults added in v0.4.0

func (c *Conn) DrainResults() error

DrainResults will read all packets for a result set and ignore them.

func (*Conn) EndWriterBuffering

func (c *Conn) EndWriterBuffering() error

EndWriterBuffering must be called to terminate startWriteBuffering.

func (*Conn) GetTLSClientCerts

func (c *Conn) GetTLSClientCerts() []*x509.Certificate

GetTLSClientCerts gets TLS certificates.

func (*Conn) ID

func (c *Conn) ID() uint32

ID returns the MySQL connection ID for this connection.

func (*Conn) IsClosed

func (c *Conn) IsClosed() bool

IsClosed returns true if this connection was ever closed by the Close() method. Note if the other side closes the connection, but Close() wasn't called, this will return false.

func (*Conn) ParseRow added in v0.4.0

func (c *Conn) ParseRow(ctx context.Context, data []byte, fields []*Field) (proto.Row, error)

ParseRow parses an individual row. Returns a SQLError.

func (*Conn) ReadEphemeralPacket

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

ReadEphemeralPacket attempts to read a packet into buffer. Do not use this method if the contents of the packet needs to be kept after the next ReadEphemeralPacket.

Note if the connection is closed already, an error will be returned, and it may not be io.EOF. If the connection closes while we are stuck waiting for Content, an error will also be returned, and it most likely will be io.EOF.

func (*Conn) ReadEphemeralPacketDirect

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

ReadEphemeralPacketDirect attempts to read a packet from the socket directly. It needs to be used for the first handshake packet the server receives, so we do't buffer the SSL negotiation packet. As a shortcut, only packets smaller than MaxPacketSize can be read here. This function usually shouldn't be used - use ReadEphemeralPacket.

func (*Conn) ReadOnePacket

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

ReadOnePacket reads a single packet into a newly allocated buffer.

func (*Conn) ReadPacket

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

ReadPacket reads a packet from the underlying connection. It re-assembles packets that span more than one message. This method returns a generic error, not a SQLError.

func (*Conn) ReadPacketFacade

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

ReadPacketFacade reads a packet from the underlying connection. it is the public API version, that returns a SQLError. The memory for the packet is always allocated, and it is owned by the caller after this function returns.

func (*Conn) RecycleReadPacket

func (c *Conn) RecycleReadPacket()

RecycleReadPacket recycles the read packet. It needs to be called after ReadEphemeralPacket was called.

func (*Conn) RecycleWritePacket

func (c *Conn) RecycleWritePacket()

RecycleWritePacket recycles the write packet. It needs to be called after WriteEphemeralPacket was called.

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr returns the underlying socket RemoteAddr().

func (*Conn) ResetSequence

func (c *Conn) ResetSequence()

func (*Conn) SetConnectionID added in v0.2.0

func (c *Conn) SetConnectionID(connectionID uint32)

func (*Conn) SetReadTimeout added in v0.5.0

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

func (*Conn) SetUserName added in v0.2.0

func (c *Conn) SetUserName(userName string)

func (*Conn) SetWriteTimeout added in v0.5.0

func (c *Conn) SetWriteTimeout(writeTimeout time.Duration)

func (*Conn) StartEphemeralPacket

func (c *Conn) StartEphemeralPacket(length int) []byte

func (*Conn) StartWriterBuffering

func (c *Conn) StartWriterBuffering()

StartWriterBuffering starts using buffered writes. This should be terminated by a call to endWriteBuffering.

func (*Conn) StatusFlags

func (c *Conn) StatusFlags() uint16

func (*Conn) String

func (c *Conn) String() string

Ident returns a useful identification string for error logging

func (*Conn) UserName added in v0.2.0

func (c *Conn) UserName() string

func (*Conn) WriteBinaryRows

func (c *Conn) WriteBinaryRows(result *Result) error

func (*Conn) WriteEOFPacket

func (c *Conn) WriteEOFPacket(flags uint16, warnings uint16) error

WriteEOFPacket writes an EOF packet, through the buffer, and doesn't flush (as it is used as part of a query result).

func (*Conn) WriteEndResult

func (c *Conn) WriteEndResult(capabilities uint32, more bool, affectedRows, lastInsertID uint64, warnings uint16) error

WriteEndResult concludes the sending of a Result. if more is set to true, then it means there are more results afterwords

func (*Conn) WriteEphemeralPacket

func (c *Conn) WriteEphemeralPacket() error

WriteEphemeralPacket writes the packet that was allocated by StartEphemeralPacket.

func (*Conn) WriteErrorPacket

func (c *Conn) WriteErrorPacket(errorCode uint16, sqlState string, format string, args ...interface{}) error

WriteErrorPacket writes an error packet. Server -> Client. This method returns a generic error, not a SQLError.

func (*Conn) WriteErrorPacketFromError

func (c *Conn) WriteErrorPacketFromError(err error) error

WriteErrorPacketFromError writes an error packet, from a regular error. See WriteErrorPacket for other info.

func (*Conn) WriteFields

func (c *Conn) WriteFields(capabilities uint32, fields []*Field) error

WriteFields writes the fields of a Result. It should be called only if there are valid Columns in the result.

func (*Conn) WriteOKPacket

func (c *Conn) WriteOKPacket(affectedRows, lastInsertID uint64, flags uint16, warnings uint16) error

WriteOKPacket writes an OK packet. Server -> Client. This method returns a generic error, not a SQLError.

func (*Conn) WriteOKPacketWithEOFHeader

func (c *Conn) WriteOKPacketWithEOFHeader(affectedRows, lastInsertID uint64, flags uint16, warnings uint16) error

WriteOKPacketWithEOFHeader writes an OK packet with an EOF header. This is used at the end of a result set if CapabilityClientDeprecateEOF is set. Server -> Client. This method returns a generic error, not a SQLError.

func (*Conn) WritePacket

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

WritePacket writes a packet, possibly cutting it into multiple chunks. Note this is not very efficient, as the client probably has to build the []byte and that makes a memory copy. Try to use StartEphemeralPacket/WriteEphemeralPacket instead.

This method returns a generic error, not a SQLError.

func (*Conn) WritePrepare

func (c *Conn) WritePrepare(capabilities uint32, prepare *proto.Stmt) error

WritePrepare writes a prepare query response to the wire.

func (*Conn) WriteRows

func (c *Conn) WriteRows(result *Result) error

func (*Conn) WriteTextRows added in v0.3.0

func (c *Conn) WriteTextRows(result *Result) error

WriteTextRows sends the rows of a Result.

type Field

type Field struct {
	Table        string
	OrgTable     string
	Database     string
	Name         string
	OrgName      string
	Length       uint32
	Flags        uint
	FieldType    constant.FieldType
	Decimals     byte
	CharSet      uint16
	ColumnLength uint32

	DefaultValueLength uint64
	DefaultValue       []byte
}

func (*Field) DataBaseName

func (mf *Field) DataBaseName() string

func (*Field) FiledName

func (mf *Field) FiledName() string

func (*Field) TableName

func (mf *Field) TableName() string

func (*Field) TypeDatabaseName

func (mf *Field) TypeDatabaseName() string

type Result

type Result struct {
	Fields       []*Field // Columns information
	AffectedRows uint64
	InsertId     uint64
	Rows         []proto.Row
}

func (*Result) LastInsertId

func (res *Result) LastInsertId() (uint64, error)

func (*Result) RowsAffected

func (res *Result) RowsAffected() (uint64, error)

type ResultSet

type ResultSet struct {
	Columns     []*Field
	ColumnNames []string
}

type TextRow

type TextRow struct {
	Values []*proto.Value
	// contains filtered or unexported fields
}

func (TextRow) Columns added in v0.4.0

func (row TextRow) Columns() []string

func (TextRow) Data added in v0.4.0

func (row TextRow) Data() []byte

func (*TextRow) Decode

func (row *TextRow) Decode() ([]*proto.Value, error)

func (TextRow) Fields added in v0.4.0

func (row TextRow) Fields() []proto.Field

Jump to

Keyboard shortcuts

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