driver

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseRows

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

BaseRows --

func (*BaseRows) Bytes

func (r *BaseRows) Bytes() int

Bytes returns all the memory usage which read by this row cursor.

func (*BaseRows) Close

func (r *BaseRows) Close() error

Close drain the rest packets and check the error.

func (*BaseRows) Datas

func (r *BaseRows) Datas() []byte

Datas implements the Rows interface.

func (*BaseRows) Fields

func (r *BaseRows) Fields() []*querypb.Field

Fields implements the Rows interface.

func (*BaseRows) LastError

func (r *BaseRows) LastError() error

LastError implements the Rows interface.

func (*BaseRows) LastInsertID

func (r *BaseRows) LastInsertID() uint64

LastInsertID implements the Rows interface.

func (*BaseRows) Next

func (r *BaseRows) Next() bool

Next implements the Rows interface. http://dev.mysql.com/doc/internals/en/com-query-response.html#packet-ProtocolText::ResultsetRow

func (*BaseRows) RowValues

func (r *BaseRows) RowValues() ([]sqltypes.Value, error)

RowValues implements the Rows interface. https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-ProtocolText::ResultsetRow

func (*BaseRows) RowsAffected

func (r *BaseRows) RowsAffected() uint64

RowsAffected implements the Rows interface.

type BinaryRows

type BinaryRows struct {
	BaseRows
}

BinaryRows presents binary row tuple.

func NewBinaryRows

func NewBinaryRows(c Conn) *BinaryRows

NewBinaryRows creates BinaryRows.

func (*BinaryRows) RowValues

func (r *BinaryRows) RowValues() ([]sqltypes.Value, error)

RowValues implements the Rows interface. https://dev.mysql.com/doc/internals/en/binary-protocol-resultset-row.html

type Cond

type Cond struct {
	// Cond type.
	Type CondType

	// Query string
	Query string

	// Query results
	Result *sqltypes.Result

	// Panic or Not
	Panic bool

	// Return Error if Error is not nil
	Error error

	// Delay(ms) for results return
	Delay int
}

Cond presents a condition tuple.

type CondList

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

CondList presents a list of Cond.

type CondType

type CondType int

CondType used for Condition type.

const (
	// COND_NORMAL enum.
	COND_NORMAL CondType = iota
	// COND_DELAY enum.
	COND_DELAY
	// COND_ERROR enum.
	COND_ERROR
	// COND_PANIC enum.
	COND_PANIC
	// COND_STREAM enum.
	COND_STREAM
)

type Conn

type Conn interface {
	Ping() error
	Quit()
	Close() error
	Closed() bool
	Cleanup()
	NextPacket() ([]byte, error)

	// ConnectionID is the connection id at greeting.
	ConnectionID() uint32

	InitDB(db string) error
	Command(command byte) error
	Query(sql string) (Rows, error)
	Exec(sql string) error
	FetchAll(sql string, maxrows int) (*sqltypes.Result, error)
	FetchAllWithFunc(sql string, maxrows int, fn Func) (*sqltypes.Result, error)
	ComStatementPrepare(sql string) (*Statement, error)
}

Conn interface.

func NewConn

func NewConn(username, password, address, database, charset string) (Conn, error)

NewConn used to create a new client connection. The timeout is 30 seconds.

type Func

type Func func(rows Rows) error

Func calls on every rows.Next. If func returns error, the row.Next() is interrupted and the error is return.

type Handler

type Handler interface {
	ServerVersion() string
	SetServerVersion()
	NewSession(session *Session)
	SessionInc(session *Session)
	SessionDec(session *Session)
	SessionClosed(session *Session)
	SessionCheck(session *Session) error
	AuthCheck(session *Session) error
	ComInitDB(session *Session, database string) error
	ComQuery(session *Session, query string, bindVariables map[string]*querypb.BindVariable, callback func(*sqltypes.Result) error) error
}

Handler interface.

type Listener

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

Listener is a connection handler.

func MockMysqlServer

func MockMysqlServer(log *xlog.Log, h Handler) (svr *Listener, err error)

MockMysqlServer creates a new mock mysql server.

func MockMysqlServerWithPort

func MockMysqlServerWithPort(log *xlog.Log, port int, h Handler) (svr *Listener, err error)

MockMysqlServerWithPort creates a new mock mysql server with port.

func NewListener

func NewListener(log *xlog.Log, address string, handler Handler) (*Listener, error)

NewListener creates a new Listener.

func (*Listener) Accept

func (l *Listener) Accept()

Accept runs an accept loop until the listener is closed.

func (*Listener) Addr

func (l *Listener) Addr() string

Addr returns the client address.

func (*Listener) Close

func (l *Listener) Close()

Close close the listener and all connections.

type RowMode

type RowMode int
const (
	TextRowMode RowMode = iota
	BinaryRowMode
)

type Rows

type Rows interface {
	Next() bool
	Close() error
	Datas() []byte
	Bytes() int
	RowsAffected() uint64
	LastInsertID() uint64
	LastError() error
	Fields() []*querypb.Field
	RowValues() ([]sqltypes.Value, error)
}

Rows presents row cursor interface.

type Session

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

Session is a client connection with greeting and auth.

func (*Session) Addr

func (s *Session) Addr() string

Addr returns the remote address.

func (*Session) Charset

func (s *Session) Charset() uint8

Charset returns the charset of auth.

func (*Session) Close

func (s *Session) Close()

Close used to close the connection.

func (*Session) ID

func (s *Session) ID() uint32

ID returns the connection ID.

func (*Session) LastQueryTime

func (s *Session) LastQueryTime() time.Time

LastQueryTime returns the lastQueryTime.

func (*Session) Salt

func (s *Session) Salt() []byte

Salt returns the salt of greeting.

func (*Session) Schema

func (s *Session) Schema() string

Schema returns the schema.

func (*Session) Scramble

func (s *Session) Scramble() []byte

Scramble returns the scramble of auth.

func (*Session) SetSchema

func (s *Session) SetSchema(schema string)

SetSchema used to set the schema.

func (*Session) User

func (s *Session) User() string

User returns the user of auth.

type SessionTuple

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

SessionTuple presents a session tuple.

type Statement

type Statement struct {
	ID          uint32
	ParamCount  uint16
	PrepareStmt string
	ParamsType  []int32
	ColumnNames []string
	BindVars    map[string]*querypb.BindVariable
	// contains filtered or unexported fields
}

Statement --

func (*Statement) ComStatementClose

func (s *Statement) ComStatementClose() error

ComStatementClose -- close the stmt.

func (*Statement) ComStatementExecute

func (s *Statement) ComStatementExecute(parameters []sqltypes.Value) error

ComStatementExecute -- statement execute write.

func (*Statement) ComStatementQuery

func (s *Statement) ComStatementQuery(parameters []sqltypes.Value) (*sqltypes.Result, error)

ComStatementExecute -- statement execute write.

func (*Statement) ComStatementReset

func (s *Statement) ComStatementReset() error

ComStatementReset -- reset the stmt.

type TestHandler

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

TestHandler is the handler for testing.

func NewTestHandler

func NewTestHandler(log *xlog.Log) *TestHandler

NewTestHandler creates new Handler.

func (*TestHandler) AddQuery

func (th *TestHandler) AddQuery(query string, result *sqltypes.Result)

AddQuery used to add a query and its expected result.

func (*TestHandler) AddQueryDelay

func (th *TestHandler) AddQueryDelay(query string, result *sqltypes.Result, delayMs int)

AddQueryDelay used to add a query and returns the expected result after delay_ms.

func (*TestHandler) AddQueryError

func (th *TestHandler) AddQueryError(query string, err error)

AddQueryError used to add a query which will be rejected by a error.

func (*TestHandler) AddQueryErrorPattern

func (th *TestHandler) AddQueryErrorPattern(queryPattern string, err error)

AddQueryErrorPattern used to add an query pattern with errors.

func (*TestHandler) AddQueryPanic

func (th *TestHandler) AddQueryPanic(query string)

AddQueryPanic used to add query but underflying blackhearted.

func (*TestHandler) AddQueryPattern

func (th *TestHandler) AddQueryPattern(queryPattern string, expectedResult *sqltypes.Result)

AddQueryPattern adds an expected result for a set of queries. These patterns are checked if no exact matches from AddQuery() are found. This function forces the addition of begin/end anchors (^$) and turns on case-insensitive matching mode. This code was derived from https://github.com/youtube/vitess.

func (*TestHandler) AddQueryStream

func (th *TestHandler) AddQueryStream(query string, result *sqltypes.Result)

AddQueryStream used to add a stream query.

func (*TestHandler) AddQuerys

func (th *TestHandler) AddQuerys(query string, results ...*sqltypes.Result)

AddQuerys used to add new query rule.

func (*TestHandler) AuthCheck

func (th *TestHandler) AuthCheck(s *Session) error

AuthCheck implements the interface.

func (*TestHandler) ComInitDB

func (th *TestHandler) ComInitDB(s *Session, db string) error

ComInitDB implements the interface.

func (*TestHandler) ComQuery

func (th *TestHandler) ComQuery(s *Session, query string, bindVariables map[string]*querypb.BindVariable, callback func(qr *sqltypes.Result) error) error

ComQuery implements the interface.

func (*TestHandler) GetQueryCalledNum

func (th *TestHandler) GetQueryCalledNum(query string) int

GetQueryCalledNum returns how many times db executes a certain query. This code was derived from https://github.com/youtube/vitess.

func (*TestHandler) NewSession

func (th *TestHandler) NewSession(s *Session)

NewSession implements the interface.

func (*TestHandler) ResetAll

func (th *TestHandler) ResetAll()

ResetAll resets all querys.

func (*TestHandler) ResetErrors

func (th *TestHandler) ResetErrors()

ResetErrors used to reset all the errors.

func (*TestHandler) ResetPatternErrors

func (th *TestHandler) ResetPatternErrors()

ResetPatternErrors used to reset all the errors pattern.

func (*TestHandler) ServerVersion

func (th *TestHandler) ServerVersion() string

ServerVersion implements the interface.

func (*TestHandler) SessionCheck

func (th *TestHandler) SessionCheck(s *Session) error

SessionCheck implements the interface.

func (*TestHandler) SessionClosed

func (th *TestHandler) SessionClosed(s *Session)

SessionClosed implements the interface.

func (*TestHandler) SessionDec

func (th *TestHandler) SessionDec(s *Session)

SessionDec implements the interface.

func (*TestHandler) SessionInc

func (th *TestHandler) SessionInc(s *Session)

SessionInc implements the interface.

func (*TestHandler) SetServerVersion

func (th *TestHandler) SetServerVersion()

SetServerVersion implements the interface.

type TextRows

type TextRows struct {
	BaseRows
}

TextRows presents row tuple.

func NewTextRows

func NewTextRows(c Conn) *TextRows

NewTextRows creates TextRows.

Jump to

Keyboard shortcuts

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