mysql

package
v2.3.0-beta5 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package mysql in models provides realted structs for mysql protocol

Index

Constants

View Source
const (
	OK  byte = 0x00
	ERR byte = 0xff
	EOF byte = 0xfe
)

Basic Response Packet Status

View Source
const (
	AuthSwitchRequest byte = 0xfe
	AuthMoreData      byte = 0x01
	AuthNextFactor    byte = 0x02
	HandshakeV10      byte = 0x0a
)

Auth Packet Status

View Source
const (
	HandshakeResponse41 = "HandshakeResponse41"
	COM_STMT_PREPARE_OK = "COM_STMT_PREPARE_OK"
)

Some constants for MySQL

View Source
const (
	CLIENT_LONG_PASSWORD uint32 = 1 << iota
	CLIENT_FOUND_ROWS
	CLIENT_LONG_FLAG
	CLIENT_CONNECT_WITH_DB
	CLIENT_NO_SCHEMA
	CLIENT_COMPRESS
	CLIENT_ODBC
	CLIENT_LOCAL_FILES
	CLIENT_IGNORE_SPACE
	CLIENT_PROTOCOL_41
	CLIENT_INTERACTIVE
	CLIENT_SSL
	CLIENT_IGNORE_SIGPIPE
	CLIENT_TRANSACTIONS
	CLIENT_RESERVED
	CLIENT_SECURE_CONNECTION
	CLIENT_MULTI_STATEMENTS
	CLIENT_MULTI_RESULTS
	CLIENT_PS_MULTI_RESULTS
	CLIENT_PLUGIN_AUTH
	CLIENT_CONNECT_ATTRS
	CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA
	CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS
	CLIENT_SESSION_TRACK
	CLIENT_DEPRECATE_EOF
	CLIENT_OPTIONAL_RESULTSET_METADATA
	CLIENT_ZSTD_COMPRESSION_ALGORITHM
	CLIENT_QUERY_ATTRIBUTES
	MULTI_FACTOR_AUTHENTICATION
	CLIENT_CAPABILITY_EXTENSION
	CLIENT_SSL_VERIFY_SERVER_CERT
	CLIENT_REMEMBER_OPTIONS
)

Client Capability Flags

View Source
const (
	NOT_NULL_FLAG       = 1
	PRI_KEY_FLAG        = 2
	UNIQUE_KEY_FLAG     = 4
	BLOB_FLAG           = 16
	UNSIGNED_FLAG       = 32
	ZEROFILL_FLAG       = 64
	BINARY_FLAG         = 128
	ENUM_FLAG           = 256
	AUTO_INCREMENT_FLAG = 512
	TIMESTAMP_FLAG      = 1024
	SET_FLAG            = 2048
	NUM_FLAG            = 32768
	PART_KEY_FLAG       = 16384
	GROUP_FLAG          = 32768
	UNIQUE_FLAG         = 65536
)

Field Flags

View Source
const (
	COM_QUIT             byte = 0x01
	COM_INIT_DB          byte = 0x02
	COM_FIELD_LIST       byte = 0x04
	COM_STATISTICS       byte = 0x08
	COM_DEBUG            byte = 0x0d
	COM_PING             byte = 0x0e
	COM_CHANGE_USER      byte = 0x11
	COM_RESET_CONNECTION byte = 0x1f
)

Utility command Packet Status

View Source
const (
	COM_QUERY        byte = 0x03
	COM_STMT_PREPARE byte = 0x16
	COM_STMT_EXECUTE byte = 0x17
	// COM_STMT_FETCH          byte = 0x19
	COM_STMT_CLOSE          byte = 0x19
	COM_STMT_RESET          byte = 0x1a
	COM_STMT_SEND_LONG_DATA byte = 0x18
	COM_TIME                byte = 0x0f
)

Command Packet Status

View Source
const (
	EncryptedPassword = "encrypted_password"
)

Some constants for MySQL

View Source
const LocalInFile = 0xfb

LocalInFile Request packet type is not supported

Variables

This section is empty.

Functions

func AuthStatusToString

func AuthStatusToString(status byte) string

func CachingSha2PasswordToString

func CachingSha2PasswordToString(status CachingSha2Password) string

func CommandStatusToString

func CommandStatusToString(status byte) string

func StatusToString

func StatusToString(status byte) string

Types

type AuthMoreDataPacket

type AuthMoreDataPacket struct {
	StatusTag byte   `yaml:"status_tag"`
	Data      string `yaml:"data"`
}

AuthMoreDataPacket represents the packet sent by the server to the client to request additional data for authentication

type AuthNextFactorPacket

type AuthNextFactorPacket struct {
	PacketType byte   `yaml:"packet_type"`
	PluginName string `yaml:"plugin_name"`
	PluginData string `yaml:"plugin_data"`
}

AuthNextFactorPacket represents the packet sent by the server to the client to request the next factor for multi-factor authentication

type AuthPluginName

type AuthPluginName string
const (
	Native      AuthPluginName = "mysql_native_password"
	CachingSha2 AuthPluginName = "caching_sha2_password"
	Sha256      AuthPluginName = "sha256_password"
)

AuthPluginName constants

type AuthSwitchRequestPacket

type AuthSwitchRequestPacket struct {
	StatusTag  byte   `yaml:"status_tag"`
	PluginName string `yaml:"plugin_name"`
	PluginData string `yaml:"plugin_data"`
}

AuthSwitchRequestPacket represents the packet sent by the server to the client to switch to a different authentication method

type AuthSwitchResponsePacket

type AuthSwitchResponsePacket struct {
	Data string `yaml:"data"`
}

AuthSwitchResponsePacket represents the packet sent by the client to the server in response to an AuthSwitchRequestPacket. Note: If the server sends an AuthMoreDataPacket, the client will continue sending AuthSwitchResponsePackets until the server sends an OK packet or an ERR packet.

type BinaryProtocolResultSet

type BinaryProtocolResultSet struct {
	ColumnCount     uint64                `yaml:"columnCount"`
	Columns         []*ColumnDefinition41 `yaml:"columns"`
	EOFAfterColumns []byte                `yaml:"eofAfterColumns"`
	Rows            []*BinaryRow          `yaml:"rows"`
	FinalResponse   *GenericResponse      `yaml:"FinalResponse"`
}

BinaryProtocolResultSet is used as a response packet for COM_STMT_EXECUTE

type BinaryRow

type BinaryRow struct {
	Header        Header        `yaml:"header"`
	Values        []ColumnEntry `yaml:"values"`
	OkAfterRow    bool          `yaml:"okAfterRow"`
	RowNullBuffer []byte        `yaml:"rowNullBuffer"`
}

type CachingSha2Password

type CachingSha2Password byte
const (
	RequestPublicKey          CachingSha2Password = 2
	FastAuthSuccess           CachingSha2Password = 3
	PerformFullAuthentication CachingSha2Password = 4
)

CachingSha2Password constants

type ChangeUserPacket

type ChangeUserPacket struct {
	Command byte `yaml:"command"`
}

type ColumnCount

type ColumnCount struct {
	// Header    Header `yaml:"header"`
	Count uint64 `yaml:"count"`
}

type ColumnDefinition41

type ColumnDefinition41 struct {
	Header       Header `yaml:"header"`
	Catalog      string `yaml:"catalog"`
	Schema       string `yaml:"schema"`
	Table        string `yaml:"table"`
	OrgTable     string `yaml:"org_table"`
	Name         string `yaml:"name"`
	OrgName      string `yaml:"org_name"`
	FixedLength  byte   `yaml:"fixed_length"`
	CharacterSet uint16 `yaml:"character_set"`
	ColumnLength uint32 `yaml:"column_length"`
	Type         byte   `yaml:"type"`
	Flags        uint16 `yaml:"flags"`
	Decimals     byte   `yaml:"decimals"`
	Filler       []byte `yaml:"filler"`
	DefaultValue string `yaml:"defaultValue"`
}

type ColumnEntry

type ColumnEntry struct {
	Type     FieldType   `yaml:"type"`
	Name     string      `yaml:"name"`
	Value    interface{} `yaml:"value"`
	Unsigned bool        `yaml:"unsigned"`
}

type DebugPacket

type DebugPacket struct {
	Command byte `yaml:"command"`
}

type EOFPacket

type EOFPacket struct {
	Header      byte   `yaml:"header"`
	Warnings    uint16 `yaml:"warnings"`
	StatusFlags uint16 `yaml:"status_flags"`
}

EOFPacket represents the EOF packet sent by the server to the client, it represents the end of a query execution result

type ERRPacket

type ERRPacket struct {
	Header         byte   `yaml:"header"`
	ErrorCode      uint16 `yaml:"error_code"`
	SQLStateMarker string `yaml:"sql_state_marker"`
	SQLState       string `yaml:"sql_state"`
	ErrorMessage   string `yaml:"error_message"`
}

ERRPacket represents the ERR packet sent by the server to the client, it represents an error occurred during the execution of a command

type FieldType

type FieldType byte
const (
	FieldTypeDecimal FieldType = iota
	FieldTypeTiny
	FieldTypeShort
	FieldTypeLong
	FieldTypeFloat
	FieldTypeDouble
	FieldTypeNULL
	FieldTypeTimestamp
	FieldTypeLongLong
	FieldTypeInt24
	FieldTypeDate
	FieldTypeTime
	FieldTypeDateTime
	FieldTypeYear
	FieldTypeNewDate
	FieldTypeVarChar
	FieldTypeBit
)

Field Types

const (
	FieldTypeJSON FieldType = iota + 0xf5
	FieldTypeNewDecimal
	FieldTypeEnum
	FieldTypeSet
	FieldTypeTinyBLOB
	FieldTypeMediumBLOB
	FieldTypeLongBLOB
	FieldTypeBLOB
	FieldTypeVarString
	FieldTypeString
	FieldTypeGeometry
)

Additional Field Types

type GenericResponse

type GenericResponse struct {
	Data []byte `yaml:"data"`
	Type string `yaml:"type"`
}

type HandshakeResponse41Packet

type HandshakeResponse41Packet struct {
	CapabilityFlags      uint32            `yaml:"capability_flags"`
	MaxPacketSize        uint32            `yaml:"max_packet_size"`
	CharacterSet         uint8             `yaml:"character_set"`
	Filler               [23]byte          `yaml:"filler,omitempty,flow"`
	Username             string            `yaml:"username"`
	AuthResponse         []byte            `yaml:"auth_response,omitempty,flow"`
	Database             string            `yaml:"database"`
	AuthPluginName       string            `yaml:"auth_plugin_name"`
	ConnectionAttributes map[string]string `yaml:"connection_attributes,omitempty"`
	ZstdCompressionLevel byte              `yaml:"zstdcompressionlevel"`
}

HandshakeResponse41Packet represents the response packet sent by the client to the server after receiving the HandshakeV10Packet

type HandshakeV10Packet

type HandshakeV10Packet struct {
	ProtocolVersion uint8  `yaml:"protocol_version"`
	ServerVersion   string `yaml:"server_version"`
	ConnectionID    uint32 `yaml:"connection_id"`
	AuthPluginData  []byte `yaml:"auth_plugin_data,omitempty,flow"`
	Filler          byte   `yaml:"filler"`
	CapabilityFlags uint32 `yaml:"capability_flags"`
	CharacterSet    uint8  `yaml:"character_set"`
	StatusFlags     uint16 `yaml:"status_flags"`
	AuthPluginName  string `yaml:"auth_plugin_name"`
}

HandshakeV10Packet represents the initial handshake packet sent by the server to the client

type Header struct {
	PayloadLength uint32 `json:"payload_length" yaml:"payload_length"`
	SequenceID    uint8  `json:"sequence_id" yaml:"sequence_id"`
}

type InitDBPacket

type InitDBPacket struct {
	Command byte   `yaml:"command"`
	Schema  string `yaml:"schema"`
}

type LocalInFileRequestPacket

type LocalInFileRequestPacket struct {
	PacketType byte `yaml:"command"`
	Filename   string
}

LocalInFileRequestPacket is used to send local file request to server, currently not supported

type OKPacket

type OKPacket struct {
	Header       byte   `json:"header" yaml:"header"`
	AffectedRows uint64 `json:"affected_rows,omitempty" yaml:"affected_rows"`
	LastInsertID uint64 `json:"last_insert_id,omitempty" yaml:"last_insert_id"`
	StatusFlags  uint16 `json:"status_flags,omitempty" yaml:"status_flags"`
	Warnings     uint16 `json:"warnings,omitempty" yaml:"warnings"`
	Info         string `json:"info,omitempty" yaml:"info"`
}

OKPacket represents the OK packet sent by the server to the client, it represents a successful completion of a command

type Packet

type Packet struct {
	Header  Header `json:"header" yaml:"header"`
	Payload []byte `json:"payload,omitempty" yaml:"payload,omitempty"`
}

type PacketBundle

type PacketBundle struct {
	Header  *PacketInfo       `json:"header" yaml:"header"`
	Message interface{}       `json:"message" yaml:"message"`
	Meta    map[string]string `json:"meta,omitempty" yaml:"meta,omitempty"`
}

type PacketInfo

type PacketInfo struct {
	Header *Header `json:"header" yaml:"header"`
	Type   string  `json:"packet_type" yaml:"packet_type"`
}

type Parameter

type Parameter struct {
	Type     uint16 `yaml:"type"`
	Unsigned bool   `yaml:"unsigned"`
	Name     string `yaml:"name,omitempty"`
	Value    []byte `yaml:"value"`
}

type PingPacket

type PingPacket struct {
	Command byte `yaml:"command"`
}

type QueryPacket

type QueryPacket struct {
	Command byte   `yaml:"command"`
	Query   string `yaml:"query"`
}

type QuitPacket

type QuitPacket struct {
	Command byte `yaml:"command"`
}

type Request

type Request struct {
	PacketBundle `json:"packet_bundle" yaml:"packet_bundle"`
}

type RequestYaml

type RequestYaml struct {
	Header  *PacketInfo       `json:"header,omitempty" yaml:"header"`
	Meta    map[string]string `json:"meta,omitempty" yaml:"meta,omitempty"`
	Message yaml.Node         `json:"message,omitempty" yaml:"message"`
}

type ResetConnectionPacket

type ResetConnectionPacket struct {
	Command byte `yaml:"command"`
}

type Response

type Response struct {
	PacketBundle `json:"packet_bundle" yaml:"packet_bundle"`
	Payload      string `json:"payload,omitempty" yaml:"payload,omitempty"`
}

type ResponseYaml

type ResponseYaml struct {
	Header  *PacketInfo       `json:"header,omitempty" yaml:"header"`
	Meta    map[string]string `json:"meta,omitempty" yaml:"meta,omitempty"`
	Message yaml.Node         `json:"message,omitempty" yaml:"message"`
}

type ResultSet

type ResultSet string

ResultSet packets

const (
	Binary ResultSet = "BinaryProtocolResultSet"
	Text   ResultSet = "TextResultSet"
)

ResultSet types

type SetOptionPacket

type SetOptionPacket struct {
	Status byte   `yaml:"status"`
	Option uint16 `yaml:"option"`
}

type Spec

type Spec struct {
	Metadata         map[string]string `json:"metadata" yaml:"metadata"`
	Requests         []RequestYaml     `json:"requests" yaml:"requests"`
	Response         []ResponseYaml    `json:"responses" yaml:"responses"`
	CreatedAt        int64             `json:"created" yaml:"created,omitempty"`
	ReqTimestampMock time.Time         `json:"ReqTimestampMock,omitempty"`
	ResTimestampMock time.Time         `json:"ResTimestampMock,omitempty"`
}

type StatisticsPacket

type StatisticsPacket struct {
	Command byte `yaml:"command"`
}

type StmtClosePacket

type StmtClosePacket struct {
	Status      byte   `yaml:"status"`
	StatementID uint32 `yaml:"statement_id"`
}

type StmtExecutePacket

type StmtExecutePacket struct {
	Status            byte        `yaml:"status"`
	StatementID       uint32      `yaml:"statement_id"`
	Flags             byte        `yaml:"flags"`
	IterationCount    uint32      `yaml:"iteration_count"`
	ParameterCount    int         `yaml:"parameter_count"`
	NullBitmap        []byte      `yaml:"null_bitmap"`
	NewParamsBindFlag byte        `yaml:"new_params_bind_flag"`
	Parameters        []Parameter `yaml:"parameters"`
}

type StmtFetchPacket

type StmtFetchPacket struct {
	Status      byte   `yaml:"status"`
	StatementID uint32 `yaml:"statement_id"`
	NumRows     uint32 `yaml:"num_rows"`
}

type StmtPrepareOkPacket

type StmtPrepareOkPacket struct {
	Status       byte   `yaml:"status"`
	StatementID  uint32 `yaml:"statement_id"`
	NumColumns   uint16 `yaml:"num_columns"`
	NumParams    uint16 `yaml:"num_params"`
	Filler       byte   `yaml:"filler"`
	WarningCount uint16 `yaml:"warning_count"`

	ParamDefs          []*ColumnDefinition41 `yaml:"param_definitions"`
	EOFAfterParamDefs  []byte                `yaml:"eofAfterParamDefs"`
	ColumnDefs         []*ColumnDefinition41 `yaml:"column_definitions"`
	EOFAfterColumnDefs []byte                `yaml:"eofAfterColumnDefs"`
}

type StmtPreparePacket

type StmtPreparePacket struct {
	Command byte   `yaml:"command"`
	Query   string `yaml:"query"`
}

type StmtResetPacket

type StmtResetPacket struct {
	Status      byte   `yaml:"status"`
	StatementID uint32 `yaml:"statement_id"`
}

type StmtSendLongDataPacket

type StmtSendLongDataPacket struct {
	Status      byte   `yaml:"status"`
	StatementID uint32 `yaml:"statement_id"`
	ParameterID uint16 `yaml:"parameter_id"`
	Data        []byte `yaml:"data"`
}

type TextResultSet

type TextResultSet struct {
	ColumnCount     uint64                `yaml:"columnCount"`
	Columns         []*ColumnDefinition41 `yaml:"columns"`
	EOFAfterColumns []byte                `yaml:"eofAfterColumns"`
	Rows            []*TextRow            `yaml:"rows"`
	FinalResponse   *GenericResponse      `yaml:"FinalResponse"`
}

TextResultSet is used as a response packet for COM_QUERY

type TextRow

type TextRow struct {
	Header Header        `yaml:"header"`
	Values []ColumnEntry `yaml:"values"`
}

Jump to

Keyboard shortcuts

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