Version: v1.0.0 Latest Latest

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

Go to latest
Published: May 11, 2021 License: BSD-3-Clause Imports: 8 Imported by: 10




View Source
const (
	// DefaultAuthPluginName is the default plugin name.
	DefaultAuthPluginName = "mysql_native_password"

	// DefaultServerCapability is the default server capability.
	DefaultServerCapability = sqldb.CLIENT_LONG_PASSWORD |
		sqldb.CLIENT_PROTOCOL_41 |

		// DefaultClientCapability is the default client capability.
	DefaultClientCapability = sqldb.CLIENT_LONG_PASSWORD |
		sqldb.CLIENT_PROTOCOL_41 |
View Source
const (
	// EOF_PACKET is the EOF packet.
	EOF_PACKET byte = 0xfe
View Source
const (
	// ERR_PACKET is the error packet byte.
	ERR_PACKET byte = 0xff
View Source
const (
	// OK_PACKET is the OK byte.
	OK_PACKET byte = 0x00


View Source
var (
	// DefaultSalt is the default salt bytes.
	DefaultSalt = []byte{
		0x77, 0x63, 0x6a, 0x6d, 0x61, 0x22, 0x23, 0x27,
		0x38, 0x26, 0x55, 0x58, 0x3b, 0x5d, 0x44, 0x78, 0x53, 0x73, 0x6b, 0x41}


func ColumnCount

func ColumnCount(payload []byte) (count uint64, err error)

ColumnCount returns the column count.

func PackColumn

func PackColumn(field *querypb.Field) []byte

PackColumn used to pack the column packet.

func PackEOF

func PackEOF(e *EOF) []byte

PackEOF used to pack the EOF packet.

func PackERR

func PackERR(e *ERR) []byte

PackERR used to pack the error packet.

func PackOK

func PackOK(o *OK) []byte

PackOK used to pack the OK packet.

func PackStatementExecute

func PackStatementExecute(stmtID uint32, parameters []sqltypes.Value) ([]byte, error)

PackStatementExecute -- used to pack the stmt execute packet from the client.

func PackStatementPrepare

func PackStatementPrepare(stmt *Statement) []byte

PackStatementPrepare -- used to pack the stmt prepare resp packet.

func UnPackERR

func UnPackERR(data []byte) error

UnPackERR parses the error packet and returns a sqldb.SQLError.

func UnPackStatementExecute

func UnPackStatementExecute(data []byte, prepare *Statement, parseValueFn func(*common.Buffer, querypb.Type) (interface{}, error)) error

UnPackStatementExecute -- unpack the stmt-execute packet from client.

func UnpackColumn

func UnpackColumn(payload []byte) (*querypb.Field, error)

UnpackColumn used to unpack the column packet.


type Auth

type Auth struct {
	// contains filtered or unexported fields

Auth packet.

func NewAuth

func NewAuth() *Auth

NewAuth creates new Auth.

func (*Auth) AuthResponse

func (a *Auth) AuthResponse() []byte

AuthResponse returns the auth response.

func (*Auth) Charset

func (a *Auth) Charset() uint8

Charset returns the charset.

func (*Auth) CleanAuthResponse

func (a *Auth) CleanAuthResponse()

CleanAuthResponse used to set the authResponse to nil. To improve the heap gc cost.

func (*Auth) ClientFlags

func (a *Auth) ClientFlags() uint32

ClientFlags returns the client flags.

func (*Auth) Database

func (a *Auth) Database() string

Database returns the database.

func (*Auth) Pack

func (a *Auth) Pack(capabilityFlags uint32, charset uint8, username string, password string, salt []byte, database string) []byte

Pack used to pack a HandshakeResponse41 packet.

func (*Auth) UnPack

func (a *Auth) UnPack(payload []byte) error

UnPack parses the handshake sent by the client.

func (*Auth) User

func (a *Auth) User() string

User returns the user.

type EOF

type EOF struct {
	Header      byte // 0x00
	Warnings    uint16
	StatusFlags uint16

EOF used for EOF packet.

func UnPackEOF

func UnPackEOF(data []byte) (*EOF, error)

UnPackEOF used to unpack the EOF packet. This method unsed.

type ERR

type ERR struct {
	Header       byte // always 0xff
	ErrorCode    uint16
	SQLState     string
	ErrorMessage string

ERR is the error packet.

type Greeting

type Greeting struct {
	Charset uint8

	// Capabilities is the current set of features this connection
	// is using.  It is the features that are both supported by
	// the client and the server, and currently in use.
	// It is set after the initial handshake.
	Capability   uint32
	ConnectionID uint32

	Salt []byte
	// contains filtered or unexported fields

Greeting used for greeting packet.

func NewGreeting

func NewGreeting(connectionID uint32, serverVersion string) *Greeting

NewGreeting creates a new Greeting.

func (*Greeting) Pack

func (g *Greeting) Pack() []byte

Pack used to pack the greeting packet.

func (*Greeting) Status

func (g *Greeting) Status() uint16

Status returns status of greeting.

func (*Greeting) UnPack

func (g *Greeting) UnPack(payload []byte) error

UnPack used to unpack the greeting packet.

type OK

type OK struct {
	Header       byte // 0x00
	AffectedRows uint64
	LastInsertID uint64
	StatusFlags  uint16
	Warnings     uint16

OK used for OK packet.

func UnPackOK

func UnPackOK(data []byte) (*OK, error)

UnPackOK used to unpack the OK packet.

type Statement

type Statement struct {
	Header      byte // 0x00
	ID          uint32
	ColumnCount uint16
	ParamCount  uint16
	Warnings    uint16
	ParamsType  []int32
	ColumnNames []string

	BindVars map[string]*querypb.BindVariable

Statement -- stmt struct.

func UnPackStatementPrepare

func UnPackStatementPrepare(data []byte) (*Statement, error)

UnPackStatementPrepare -- used to unpack the stmt-prepare-response packet.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL