mysql

package
v0.0.0-...-aec2e1a Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: Unlicense Imports: 16 Imported by: 0

Documentation

Overview

Package query provides functions to transform queries.

Index

Constants

View Source
const (
	UNKOWNSTATUS = iota
	SERVERHELLO
	CLIENTHEELO
	SERVERSWITCHREQUEST
	CLIENTSWITCHRESPONSE
	STATUSOK
)
View Source
const (
	OK_HEADER          byte = 0x00
	ERR_HEADER         byte = 0xff
	EOF_HEADER         byte = 0xfe
	LocalInFile_HEADER byte = 0xfb
)
View Source
const (
	CLIENT_CONNECT_WITH_DB                = 1 << 3
	CLIENT_SECURE_CONNECTION              = 1 << 15
	CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA = 1 << 21
)
View Source
const (
	COM_SLEEP byte = iota
	COM_QUIT
	COM_INIT_DB
	COM_QUERY
	COM_FIELD_LIST
	COM_CREATE_DB
	COM_DROP_DB
	COM_REFRESH
	COM_SHUTDOWN
	COM_STATISTICS
	COM_PROCESS_INFO
	COM_CONNECT
	COM_PROCESS_KILL
	COM_DEBUG
	COM_PING
	COM_TIME
	COM_DELAYED_INSERT
	COM_CHANGE_USER
	COM_BINLOG_DUMP
	COM_TABLE_DUMP
	COM_CONNECT_OUT
	COM_REGISTER_SLAVE
	COM_STMT_PREPARE
	COM_STMT_EXECUTE
	COM_STMT_SEND_LONG_DATA
	COM_STMT_CLOSE
	COM_STMT_RESET
	COM_SET_OPTION
	COM_STMT_FETCH
	COM_DAEMON
	COM_BINLOG_DUMP_GTID
	COM_RESET_CONNECTION
)
View Source
const (
	TYPE_NO = iota
	TYPE_ALLOWED
	TYPE_DENIED
	TYPE_UNKNOWN
)
View Source
const (
	OP_UNKNOWN
	OP_UNION
	OP_SELECT
	OP_STREAM
	OP_VSTREAM
	OP_INSERT
	OP_UPDATE
	OP_DELETE
	OP_SET
	OP_SET_TRANSACTION
	OP_DROP_DATABASE
	OP_FLUSH
	OP_SHOW
	OP_USE
	OP_BEGIN
	OP_COMMIT
	OP_ROLLBACK
	OP_SROLLBACK
	OP_SAVEPOINT
	OP_RELEASE
	OP_OTHER_READ
	OP_OTHER_ADMIN = 22

	OP_LOAD
	OP_CREATE_DATABASE
	OP_ALTER_DATABASE
	OP_CREATE_TABLE
	OP_CREATE_VIEW
	OP_ALTER_VIEW
	OP_LOCK_TABLES
	OP_UNLOCK_TABLES
	OP_ALTER_TABLE
	OP_ALTER_VSCHEMA
	OP_ALTER_MIGRATION
	OP_REVERT_MIGRATION
	OP_SHOW_MIGRATIONLOGS
	OP_DROP_TABLE
	OP_DROP_VIEW
	OP_TRUNCATE_TABLE
	OP_RENAME_TABLE
	OP_CALLPROC
	OP_ANALYZE = 41

	OP_EXPLAIN
	OP_OTHER

	OP_DO

	OP_LOCK
	OP_UNLOCK
	OP_CALL
	OP_REVERT
)
View Source
const (
	PARSE_UNKNOWN = iota
	PARSE_OK
	PARSE_ERROR
)
View Source
const (
	MATCH_UNKNOWN = iota
	MATCH_STRING
	MATCH_REGEXP
)

Variables

View Source
var Debug bool = false

Debug prints very verbose tracing information to STDOUT.

View Source
var ReplaceNumbersInWords = false

ReplaceNumbersInWords enables replacing numbers in words. For example: `SELECT c FROM org235.t` -> `SELECT c FROM org?.t`. For more examples look at test query_test.go/TestFingerprintWithNumberInDbName.

Functions

func BuildCharacterFromSQL

func BuildCharacterFromSQL(sql string) []int

func GetFingerprint

func GetFingerprint(q string) string

Fingerprint returns the canonical form of q. The primary transformations are:

  • Replace values with ?
  • Collapse whitespace
  • Remove comments
  • Lowercase everything

Additional trasnformations are performed which change the syntax of the original query without affecting its performance characteristics. For example, "ORDER BY col ASC" is the same as "ORDER BY col", so "ASC" in the fingerprint is removed.

func GetMd5

func GetMd5(fingerPrint string) string

GetMd5 returns the MD5 checksum of fingerprint.

func Id

func Id(fingerprint string) string

func ParserSqlRules

func ParserSqlRules() error

func ProcessClient

func ProcessClient(session interface{}, data []byte) error

func ProcessServer

func ProcessServer(session interface{}, data []byte) error

Types

type MysqlInfo

type MysqlInfo struct {
	Data     []byte
	PacketNo uint8
	Status   int

	Transaction string
	Src, Dst    string
	Protocol    byte
	Version     string
	Capability  uint32
	User        string
	Db          string
	Cmd         byte
	FingerPrint string
	Sql         string
	Op          int

	Queue queue.Queue
}

type RulesConfig

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

type SqlConfig

type SqlConfig struct {
	Id   uint
	Name string
	Type int

	Ip           string
	User         string
	Db           string
	Op           int
	Match        int
	Alert        int
	MatchContext interface{}
	FingerPrint  string

	Rows   int
	Status int
}

Jump to

Keyboard shortcuts

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