proxy

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StartTransaction    = "START TRANSACTION" // Query to start a transaction
	CommitTransaction   = "COMMIT"            // Query to commit a transaction
	RollbackTransaction = "ROLLBACK"          // Query to rollback a transaction
	DummyPreparedStmt   = "SELECT ? AS no_op" // Dummy query used for no-op statements
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DBConnection

type DBConnection interface {
	Execute(query string, args ...interface{}) (*mysql.Result, error)
	Prepare(query string) (DBStatement, error)
	FieldList(table, fieldWildcard string) ([]*mysql.Field, error)
}

DBConnection represents a generic database connection.

func NewMySQLConnWrapper

func NewMySQLConnWrapper(conn *client.Conn) DBConnection

NewMySQLConnWrapper creates mysql connection wrapper.

type DBStatement

type DBStatement interface {
	Execute(args ...interface{}) (*mysql.Result, error)
	Close() error
	ParamNum() int
	ColumnNum() int
}

DBStatement represents a prepared statement.

type EmptyReplicationHandler

type EmptyReplicationHandler struct{ TC9Proxy }

EmptyReplicationHandler is a no-op handler for replication commands.

func (*EmptyReplicationHandler) HandleBinlogDump

HandleBinlogDump returns an error for unsupported binlog dump.

func (*EmptyReplicationHandler) HandleBinlogDumpGTID

HandleBinlogDumpGTID returns an error for unsupported binlog dump with GTID.

func (*EmptyReplicationHandler) HandleRegisterSlave

func (h *EmptyReplicationHandler) HandleRegisterSlave([]byte) error

HandleRegisterSlave returns an error for unsupported slave registration.

type MySQLConnWrapper

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

MySQLConnWrapper wraps a real MySQL client connection.

func (*MySQLConnWrapper) Execute

func (c *MySQLConnWrapper) Execute(query string, args ...interface{}) (*mysql.Result, error)

Execute executes a query.

func (*MySQLConnWrapper) FieldList

func (c *MySQLConnWrapper) FieldList(table, fieldWildcard string) ([]*mysql.Field, error)

FieldList retrieves field list metadata.

func (*MySQLConnWrapper) Prepare

func (c *MySQLConnWrapper) Prepare(query string) (DBStatement, error)

Prepare prepares a statement.

type MySQLStmtWrapper

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

MySQLStmtWrapper wraps a real MySQL client statement.

func (*MySQLStmtWrapper) Close

func (s *MySQLStmtWrapper) Close() error

Close closes the statement.

func (*MySQLStmtWrapper) ColumnNum

func (s *MySQLStmtWrapper) ColumnNum() int

ColumnNum returns the number of columns.

func (*MySQLStmtWrapper) Execute

func (s *MySQLStmtWrapper) Execute(args ...interface{}) (*mysql.Result, error)

Execute executes a prepared statement.

func (*MySQLStmtWrapper) ParamNum

func (s *MySQLStmtWrapper) ParamNum() int

ParamNum returns the number of parameters.

type StmtWithParsedDataContext

type StmtWithParsedDataContext struct {
	Stmts      map[uint32]DBStatement    // Mapped by realm ID
	GuidFinder *sqlparser.CharGUIDFinder // Helper to extract GUIDs from queries
	IsDummy    bool                      // Flag indicating if it's a dummy statement
}

StmtWithParsedDataContext holds data related to prepared statements and GUIDs for each statement context.

type TC9Proxy

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

TC9Proxy represents the proxy for handling database connections and transaction state.

func NewTC9Proxy

func NewTC9Proxy(clientID int, connections map[uint32]DBConnection, parser *parser.Parser) *TC9Proxy

NewTC9Proxy creates a new instance of TC9Proxy.

func (*TC9Proxy) ConnByRealm

func (p *TC9Proxy) ConnByRealm(realmID uint32) DBConnection

ConnByRealm retrieves the connection for a given realm ID, or a fallback connection.

func (*TC9Proxy) HandleFieldList

func (p *TC9Proxy) HandleFieldList(table string, fieldWildcard string) ([]*mysql.Field, error)

HandleFieldList retrieves a list of fields for a given table.

func (*TC9Proxy) HandleOtherCommand

func (p *TC9Proxy) HandleOtherCommand(cmd byte, data []byte) error

HandleOtherCommand processes unsupported commands and returns an error.

func (*TC9Proxy) HandleQuery

func (p *TC9Proxy) HandleQuery(query string) (*mysql.Result, error)

HandleQuery processes a query, handles transactions, and executes the query.

func (*TC9Proxy) HandleStmtClose

func (p *TC9Proxy) HandleStmtClose(context interface{}) error

HandleStmtClose closes a prepared statement.

func (*TC9Proxy) HandleStmtExecute

func (p *TC9Proxy) HandleStmtExecute(ctx interface{}, query string, args []interface{}) (*mysql.Result, error)

HandleStmtExecute executes a prepared statement with given arguments.

func (*TC9Proxy) HandleStmtPrepare

func (p *TC9Proxy) HandleStmtPrepare(query string) (int, int, interface{}, error)

HandleStmtPrepare prepares a statement by parsing the query and extracting GUIDs.

func (*TC9Proxy) RunOnEveryConn

func (p *TC9Proxy) RunOnEveryConn(f func(db DBConnection))

RunOnEveryConn runs a function on every database connection.

func (*TC9Proxy) UseDB

func (p *TC9Proxy) UseDB(string) error

UseDB sets the database to use (does nothing here).

type TransactionState

type TransactionState uint8

TransactionState represents the state of a transaction.

const (
	TransactionNone       TransactionState = iota // No transaction in progress
	TransactionRequested                          // Transaction has been requested (but not started)
	TransactionInProgress                         // Transaction is in progress
)

Jump to

Keyboard shortcuts

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