Documentation
¶
Overview ¶
Package mysql provides a MySQL driver for Go's database/sql package.
The driver should be used via the database/sql package:
import "database/sql" import _ "github.com/go-sql-driver/mysql" db, err := sql.Open("mysql", "user:password@/dbname")
See https://github.com/go-sql-driver/mysql#usage for details
Index ¶
- Constants
- Variables
- func Check(fieldOrTableName string) bool
- func CheckAndReplace(fieldOrTableName string) string
- func CheckEscape(fieldOrTableName string) bool
- func DeleteBuildUndoSql(undoLog sqlUndoLog) string
- func DeregisterDialContext(net string)
- func DeregisterLocalFile(filePath string)
- func DeregisterReaderHandler(name string)
- func DeregisterServerPubKey(name string)
- func DeregisterTLSConfig(key string)
- func GetColumns(conn *mysqlConn, dbName, tableName string) ([]schema.ColumnMeta, error)
- func GetIndexes(conn *mysqlConn, dbName, tableName string) ([]schema.IndexMeta, error)
- func GetSqlDataType(dataType string) int32
- func InitTableMetaCache(dbName string)
- func InsertBuildUndoSql(undoLog sqlUndoLog) string
- func NewConnector(cfg *Config) (driver.Connector, error)
- func RegisterDial(network string, dial DialFunc)deprecated
- func RegisterDialContext(net string, dial DialContextFunc)
- func RegisterLocalFile(filePath string)
- func RegisterReaderHandler(name string, handler func() io.Reader)
- func RegisterResource(dsn string)
- func RegisterServerPubKey(name string, pubKey *rsa.PublicKey)
- func RegisterTLSConfig(key string, config *tls.Config) error
- func SetLogger(logger Logger) error
- func UpdateBuildUndoSql(undoLog sqlUndoLog) string
- type BuildUndoSql
- type Config
- type DataSourceManager
- func (resourceManager DataSourceManager) BranchCommit(ctx context.Context, request *apis.BranchCommitRequest) (*apis.BranchCommitResponse, error)
- func (resourceManager DataSourceManager) BranchRollback(ctx context.Context, request *apis.BranchRollbackRequest) (*apis.BranchRollbackResponse, error)
- func (resourceManager DataSourceManager) GetBranchType() apis.BranchSession_BranchType
- func (resourceManager DataSourceManager) GetConnection(resourceID string) *mysqlConn
- func (resourceManager DataSourceManager) RegisterResource(resource model.Resource)
- func (resourceManager DataSourceManager) UnregisterResource(resource model.Resource)
- type DialContextFunc
- type DialFuncdeprecated
- type Logger
- type MySQLDriver
- type MySQLError
- type MysqlUndoExecutor
- type MysqlUndoLogManager
- func (manager MysqlUndoLogManager) BatchDeleteUndoLog(conn *mysqlConn, xids []string, branchIDs []int64) error
- func (manager MysqlUndoLogManager) DeleteUndoLog(conn *mysqlConn, xid string, branchID int64) error
- func (manager MysqlUndoLogManager) DeleteUndoLogByLogCreated(conn *mysqlConn, logCreated time.Time, limitRows int) (sql.Result, error)
- func (manager MysqlUndoLogManager) FlushUndoLogs(conn *mysqlConn) error
- func (manager MysqlUndoLogManager) Undo(conn *mysqlConn, xid string, branchID int64, resourceID string) error
- type NopLogger
- type NullTimedeprecated
- type Option
- type PbBranchUndoLog
- func (*PbBranchUndoLog) Descriptor() ([]byte, []int)
- func (m *PbBranchUndoLog) GetBranchID() int64
- func (m *PbBranchUndoLog) GetSqlUndoLogs() []*PbSqlUndoLog
- func (m *PbBranchUndoLog) GetXid() string
- func (*PbBranchUndoLog) ProtoMessage()
- func (m *PbBranchUndoLog) Reset()
- func (m *PbBranchUndoLog) String() string
- func (m *PbBranchUndoLog) XXX_DiscardUnknown()
- func (m *PbBranchUndoLog) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *PbBranchUndoLog) XXX_Merge(src proto.Message)
- func (m *PbBranchUndoLog) XXX_Size() int
- func (m *PbBranchUndoLog) XXX_Unmarshal(b []byte) error
- type PbField
- func (*PbField) Descriptor() ([]byte, []int)
- func (m *PbField) GetKeyType() int32
- func (m *PbField) GetName() string
- func (m *PbField) GetType() int32
- func (m *PbField) GetValue() []byte
- func (*PbField) ProtoMessage()
- func (m *PbField) Reset()
- func (m *PbField) String() string
- func (m *PbField) XXX_DiscardUnknown()
- func (m *PbField) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *PbField) XXX_Merge(src proto.Message)
- func (m *PbField) XXX_Size() int
- func (m *PbField) XXX_Unmarshal(b []byte) error
- type PbRow
- func (*PbRow) Descriptor() ([]byte, []int)
- func (m *PbRow) GetFields() []*PbField
- func (*PbRow) ProtoMessage()
- func (m *PbRow) Reset()
- func (m *PbRow) String() string
- func (m *PbRow) XXX_DiscardUnknown()
- func (m *PbRow) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *PbRow) XXX_Merge(src proto.Message)
- func (m *PbRow) XXX_Size() int
- func (m *PbRow) XXX_Unmarshal(b []byte) error
- type PbSqlUndoLog
- func (*PbSqlUndoLog) Descriptor() ([]byte, []int)
- func (m *PbSqlUndoLog) GetAfterImage() *PbTableRecords
- func (m *PbSqlUndoLog) GetBeforeImage() *PbTableRecords
- func (m *PbSqlUndoLog) GetSqlType() int32
- func (m *PbSqlUndoLog) GetTableName() string
- func (*PbSqlUndoLog) ProtoMessage()
- func (m *PbSqlUndoLog) Reset()
- func (m *PbSqlUndoLog) String() string
- func (m *PbSqlUndoLog) XXX_DiscardUnknown()
- func (m *PbSqlUndoLog) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *PbSqlUndoLog) XXX_Merge(src proto.Message)
- func (m *PbSqlUndoLog) XXX_Size() int
- func (m *PbSqlUndoLog) XXX_Unmarshal(b []byte) error
- type PbTableRecords
- func (*PbTableRecords) Descriptor() ([]byte, []int)
- func (m *PbTableRecords) GetRows() []*PbRow
- func (m *PbTableRecords) GetTableName() string
- func (*PbTableRecords) ProtoMessage()
- func (m *PbTableRecords) Reset()
- func (m *PbTableRecords) String() string
- func (m *PbTableRecords) XXX_DiscardUnknown()
- func (m *PbTableRecords) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *PbTableRecords) XXX_Merge(src proto.Message)
- func (m *PbTableRecords) XXX_Size() int
- func (m *PbTableRecords) XXX_Unmarshal(b []byte) error
- type ProtoBufUndoLogParser
- type RawBytes
- type Result
- type SQLType
- type Scanner
- type SqlDataType
- type State
- type TableMetaCache
- func (cache *TableMetaCache) FetchSchema(conn *mysqlConn, tableName string) (schema.TableMeta, error)
- func (cache *TableMetaCache) GetCacheKey(tableName string) string
- func (cache *TableMetaCache) GetTableMeta(conn *mysqlConn, tableName string) (schema.TableMeta, error)
- func (cache *TableMetaCache) Refresh(conn *mysqlConn, resourceID string)
- type UndoLogParser
Constants ¶
const ( InsertSqlTemplate = "INSERT INTO %s (%s) VALUES (%s)" DeleteSqlTemplate = "DELETE FROM %s WHERE `%s` = ?" UpdateSqlTemplate = "UPDATE %s SET %s WHERE `%s` = ?" SelectSqlTemplate = "SELECT %s FROM %s WHERE `%s` IN %s" )
const ( DeleteUndoLogSql = "DELETE FROM undo_log WHERE xid = ? and branch_id = ?" DeleteUndoLogByCreateSql = "DELETE FROM undo_log WHERE log_created <= ? LIMIT ?" InsertUndoLogSql = `` /* 140-byte string literal not displayed */ SelectUndoLogSql = `SELECT branch_id, xid, context, rollback_info, log_status FROM undo_log WHERE xid = ? AND branch_id = ? FOR UPDATE` )
const ( BIT SqlDataType = -7 TINYINT = -6 SMALLINT = 5 INTEGER = 4 BIGINT = -5 FLOAT = 6 REAL = 7 DOUBLE = 8 NUMERIC = 2 DECIMAL = 3 CHAR = 1 VARCHAR = 12 LONGVARCHAR = -1 DATE = 91 TIME = 92 TIMESTAMP = 93 BINARY = -2 VARBINARY = -3 LONGVARBINARY = -4 NULL = 0 OTHER = 1111 JAVA_OBJECT = 2000 DISTINCT = 2001 STRUCT = 2002 ARRAY = 2003 BLOB = 2004 CLOB = 2005 REF = 2006 DATALINK = 70 BOOLEAN = 16 ROWID = -8 NCHAR = -15 NVARCHAR = -9 LONGNVARCHAR = -16 NCLOB = 2011 SQLXML = 2009 REF_CURSOR = 2012 TIME_WITH_TIMEZONE = 2013 TIMESTAMP_WITH_TIMEZONE = 2014 )
const GlobalLock = "GlobalLock"
const XID = "XID"
Variables ¶
var ( ErrInvalidConn = errors.New("invalid connection") ErrMalformPkt = errors.New("malformed packet") ErrNoTLS = errors.New("TLS requested but server does not support TLS") ErrCleartextPassword = errors.New("this user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN") ErrNativePassword = errors.New("this user requires mysql native password authentication") ErrOldPassword = errors.New("this user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords") ErrUnknownPlugin = errors.New("this authentication plugin is not supported") ErrOldProtocol = errors.New("MySQL server does not support required protocol 41+") ErrPktSync = errors.New("commands out of sync. You can't run this command now") ErrPktSyncMul = errors.New("commands out of sync. Did you run multiple statements at once?") ErrPktTooLarge = errors.New("packet for query is too large. Try adjusting the `Config.MaxAllowedPacket`") ErrBusyBuffer = errors.New("busy buffer") )
Various errors the driver might return. Can change between driver versions.
var EXPIRE_TIME = 15 * time.Minute
var MySQLKeyword = map[string]string{}/* 263 elements not displayed */
var SqlDataTypes = map[string]int32{
"BIT": -7,
"TINYINT": -6,
"SMALLINT": 5,
"INTEGER": 4,
"BIGINT": -5,
"FLOAT": 6,
"REAL": 7,
"DOUBLE": 8,
"NUMERIC": 2,
"DECIMAL": 3,
"CHAR": 1,
"VARCHAR": 12,
"LONGVARCHAR": -1,
"DATE": 91,
"TIME": 92,
"TIMESTAMP": 93,
"BINARY": -2,
"VARBINARY": -3,
"LONGVARBINARY": -4,
"NULL": 0,
"OTHER": 1111,
"JAVA_OBJECT": 2000,
"DISTINCT": 2001,
"STRUCT": 2002,
"ARRAY": 2003,
"BLOB": 2004,
"CLOB": 2005,
"REF": 2006,
"DATALINK": 70,
"BOOLEAN": 16,
"ROWID": -8,
"NCHAR": -15,
"NVARCHAR": -9,
"LONGNVARCHAR": -16,
"NCLOB": 2011,
"SQLXML": 2009,
"REF_CURSOR": 2012,
"TIME_WITH_TIMEZONE": 2013,
"TIMESTAMP_WITH_TIMEZONE": 2014,
}
Functions ¶
func CheckAndReplace ¶ added in v1.4.4
func CheckEscape ¶ added in v1.4.4
func DeleteBuildUndoSql ¶ added in v1.4.4
func DeleteBuildUndoSql(undoLog sqlUndoLog) string
func DeregisterDialContext ¶ added in v1.4.19
func DeregisterDialContext(net string)
DeregisterDialContext removes the custom dial function registered with the given net.
func DeregisterLocalFile ¶
func DeregisterLocalFile(filePath string)
DeregisterLocalFile removes the given filepath from the allowlist.
func DeregisterReaderHandler ¶
func DeregisterReaderHandler(name string)
DeregisterReaderHandler removes the ReaderHandler function with the given name from the registry.
func DeregisterServerPubKey ¶
func DeregisterServerPubKey(name string)
DeregisterServerPubKey removes the public key registered with the given name.
func DeregisterTLSConfig ¶
func DeregisterTLSConfig(key string)
DeregisterTLSConfig removes the tls.Config associated with key.
func GetColumns ¶ added in v1.4.4
func GetColumns(conn *mysqlConn, dbName, tableName string) ([]schema.ColumnMeta, error)
func GetIndexes ¶ added in v1.4.4
func GetSqlDataType ¶ added in v1.4.4
func InitTableMetaCache ¶ added in v1.4.4
func InitTableMetaCache(dbName string)
func InsertBuildUndoSql ¶ added in v1.4.4
func InsertBuildUndoSql(undoLog sqlUndoLog) string
func NewConnector ¶ added in v1.4.3
NewConnector returns new driver.Connector.
func RegisterDial
deprecated
RegisterDial registers a custom dial function. It can then be used by the network address mynet(addr), where mynet is the registered new network. addr is passed as a parameter to the dial function.
Deprecated: users should call RegisterDialContext instead
func RegisterDialContext ¶ added in v1.4.3
func RegisterDialContext(net string, dial DialContextFunc)
RegisterDialContext registers a custom dial function. It can then be used by the network address mynet(addr), where mynet is the registered new network. The current context for the connection and its address is passed to the dial function.
func RegisterLocalFile ¶
func RegisterLocalFile(filePath string)
RegisterLocalFile adds the given file to the file allowlist, so that it can be used by "LOAD DATA LOCAL INFILE <filepath>". Alternatively you can allow the use of all local files with the DSN parameter 'allowAllFiles=true'
filePath := "/home/gopher/data.csv" mysql.RegisterLocalFile(filePath) err := db.Exec("LOAD DATA LOCAL INFILE '" + filePath + "' INTO TABLE foo") if err != nil { ...
func RegisterReaderHandler ¶
RegisterReaderHandler registers a handler function which is used to receive a io.Reader. The Reader can be used by "LOAD DATA LOCAL INFILE Reader::<name>". If the handler returns a io.ReadCloser Close() is called when the request is finished.
mysql.RegisterReaderHandler("data", func() io.Reader { var csvReader io.Reader // Some Reader that returns CSV data ... // Open Reader here return csvReader }) err := db.Exec("LOAD DATA LOCAL INFILE 'Reader::data' INTO TABLE foo") if err != nil { ...
func RegisterResource ¶ added in v1.4.4
func RegisterResource(dsn string)
func RegisterServerPubKey ¶
RegisterServerPubKey registers a server RSA public key which can be used to send data in a secure manner to the server without receiving the public key in a potentially insecure way from the server first. Registered keys can afterwards be used adding serverPubKey=<name> to the DSN.
Note: The provided rsa.PublicKey instance is exclusively owned by the driver after registering it and may not be modified.
data, err := os.ReadFile("mykey.pem") if err != nil { log.Fatal(err) } block, _ := pem.Decode(data) if block == nil || block.Type != "PUBLIC KEY" { log.Fatal("failed to decode PEM block containing public key") } pub, err := x509.ParsePKIXPublicKey(block.Bytes) if err != nil { log.Fatal(err) } if rsaPubKey, ok := pub.(*rsa.PublicKey); ok { mysql.RegisterServerPubKey("mykey", rsaPubKey) } else { log.Fatal("not a RSA public key") }
func RegisterTLSConfig ¶
RegisterTLSConfig registers a custom tls.Config to be used with sql.Open. Use the key as a value in the DSN where tls=value.
Note: The provided tls.Config is exclusively owned by the driver after registering it.
rootCertPool := x509.NewCertPool() pem, err := os.ReadFile("/path/ca-cert.pem") if err != nil { log.Fatal(err) } if ok := rootCertPool.AppendCertsFromPEM(pem); !ok { log.Fatal("Failed to append PEM.") } clientCert := make([]tls.Certificate, 0, 1) certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem") if err != nil { log.Fatal(err) } clientCert = append(clientCert, certs) mysql.RegisterTLSConfig("custom", &tls.Config{ RootCAs: rootCertPool, Certificates: clientCert, }) db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom")
func SetLogger ¶
SetLogger is used to set the default logger for critical errors. The initial logger is os.Stderr.
func UpdateBuildUndoSql ¶ added in v1.4.4
func UpdateBuildUndoSql(undoLog sqlUndoLog) string
Types ¶
type BuildUndoSql ¶ added in v1.4.4
type BuildUndoSql func(undoLog sqlUndoLog) string
type Config ¶
type Config struct { User string // Username Passwd string // Password (requires User) Net string // Network (e.g. "tcp", "tcp6", "unix". default: "tcp") Addr string // Address (default: "127.0.0.1:3306" for "tcp" and "/tmp/mysql.sock" for "unix") DBName string // Database name Params map[string]string // Connection parameters ConnectionAttributes string // Connection Attributes, comma-delimited string of user-defined "key:value" pairs Collation string // Connection collation Loc *time.Location // Location for time.Time values MaxAllowedPacket int // Max packet size allowed ServerPubKey string // Server public key name TLSConfig string // TLS configuration name TLS *tls.Config // TLS configuration, its priority is higher than TLSConfig Timeout time.Duration // Dial timeout ReadTimeout time.Duration // I/O read timeout WriteTimeout time.Duration // I/O write timeout Logger Logger // Logger AllowAllFiles bool // Allow all files to be used with LOAD DATA LOCAL INFILE AllowCleartextPasswords bool // Allows the cleartext client side plugin AllowFallbackToPlaintext bool // Allows fallback to unencrypted connection if server does not support TLS AllowNativePasswords bool // Allows the native password authentication method AllowOldPasswords bool // Allows the old insecure password method CheckConnLiveness bool // Check connections for liveness before using them ClientFoundRows bool // Return number of matching rows instead of rows changed ColumnsWithAlias bool // Prepend table alias to column names InterpolateParams bool // Interpolate placeholders into query string MultiStatements bool // Allow multiple statements in one query ParseTime bool // Parse time values to time.Time RejectReadOnly bool // Reject read-only connections // contains filtered or unexported fields }
Config is a configuration parsed from a DSN string. If a new Config is created instead of being parsed from a DSN string, the NewConfig function should be used, which sets default values.
func (*Config) FormatDSN ¶
FormatDSN formats the given Config into a DSN string which can be passed to the driver.
Note: use NewConnector and database/sql.OpenDB to open a connection from a *Config.
type DataSourceManager ¶ added in v1.4.4
type DataSourceManager struct { ResourceCache map[string]*connector sync.Mutex // contains filtered or unexported fields }
func GetDataSourceManager ¶ added in v1.4.4
func GetDataSourceManager() DataSourceManager
func (DataSourceManager) BranchCommit ¶ added in v1.4.4
func (resourceManager DataSourceManager) BranchCommit(ctx context.Context, request *apis.BranchCommitRequest) (*apis.BranchCommitResponse, error)
func (DataSourceManager) BranchRollback ¶ added in v1.4.4
func (resourceManager DataSourceManager) BranchRollback(ctx context.Context, request *apis.BranchRollbackRequest) (*apis.BranchRollbackResponse, error)
func (DataSourceManager) GetBranchType ¶ added in v1.4.4
func (resourceManager DataSourceManager) GetBranchType() apis.BranchSession_BranchType
func (DataSourceManager) GetConnection ¶ added in v1.4.4
func (resourceManager DataSourceManager) GetConnection(resourceID string) *mysqlConn
func (DataSourceManager) RegisterResource ¶ added in v1.4.4
func (resourceManager DataSourceManager) RegisterResource(resource model.Resource)
func (DataSourceManager) UnregisterResource ¶ added in v1.4.4
func (resourceManager DataSourceManager) UnregisterResource(resource model.Resource)
type DialContextFunc ¶ added in v1.4.3
DialContextFunc is a function which can be used to establish the network connection. Custom dial functions must be registered with RegisterDialContext
type Logger ¶
type Logger interface {
Print(v ...any)
}
Logger is used to log critical error messages.
type MySQLDriver ¶
type MySQLDriver struct{}
MySQLDriver is exported to make the driver directly accessible. In general the driver is used via the database/sql package.
func (MySQLDriver) Open ¶
func (d MySQLDriver) Open(dsn string) (driver.Conn, error)
Open new Connection. See https://github.com/go-sql-driver/mysql#dsn-data-source-name for how the DSN string is formatted
func (MySQLDriver) OpenConnector ¶ added in v1.4.3
func (d MySQLDriver) OpenConnector(dsn string) (driver.Connector, error)
OpenConnector implements driver.DriverContext.
type MySQLError ¶
MySQLError is an error type which represents a single MySQL error
func (*MySQLError) Error ¶
func (me *MySQLError) Error() string
func (*MySQLError) Is ¶ added in v1.4.19
func (me *MySQLError) Is(err error) bool
type MysqlUndoExecutor ¶ added in v1.4.4
type MysqlUndoExecutor struct {
// contains filtered or unexported fields
}
func NewMysqlUndoExecutor ¶ added in v1.4.4
func NewMysqlUndoExecutor(undoLog sqlUndoLog) MysqlUndoExecutor
func (MysqlUndoExecutor) Execute ¶ added in v1.4.4
func (executor MysqlUndoExecutor) Execute(conn *mysqlConn) error
type MysqlUndoLogManager ¶ added in v1.4.4
type MysqlUndoLogManager struct { }
func GetUndoLogManager ¶ added in v1.4.4
func GetUndoLogManager() MysqlUndoLogManager
func (MysqlUndoLogManager) BatchDeleteUndoLog ¶ added in v1.4.4
func (manager MysqlUndoLogManager) BatchDeleteUndoLog(conn *mysqlConn, xids []string, branchIDs []int64) error
func (MysqlUndoLogManager) DeleteUndoLog ¶ added in v1.4.4
func (manager MysqlUndoLogManager) DeleteUndoLog(conn *mysqlConn, xid string, branchID int64) error
func (MysqlUndoLogManager) DeleteUndoLogByLogCreated ¶ added in v1.4.4
func (MysqlUndoLogManager) FlushUndoLogs ¶ added in v1.4.4
func (manager MysqlUndoLogManager) FlushUndoLogs(conn *mysqlConn) error
type NopLogger ¶ added in v1.4.19
type NopLogger struct{}
NopLogger is a nop implementation of the Logger interface.
type NullTime
deprecated
NullTime represents a time.Time that may be NULL. NullTime implements the Scanner interface so it can be used as a scan destination:
var nt NullTime err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt) ... if nt.Valid { // use nt.Time } else { // NULL value }
This NullTime implementation is not driver-specific ¶
Deprecated: NullTime doesn't honor the loc DSN parameter. NullTime.Scan interprets a time as UTC, not the loc DSN parameter. Use sql.NullTime instead.
type Option ¶ added in v1.4.19
Functional Options Pattern https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
func BeforeConnect ¶ added in v1.4.19
BeforeConnect sets the function to be invoked before a connection is established.
func TimeTruncate ¶ added in v1.4.19
TimeTruncate sets the time duration to truncate time.Time values in query parameters.
type PbBranchUndoLog ¶ added in v1.4.4
type PbBranchUndoLog struct { Xid string `protobuf:"bytes,1,opt,name=XID,proto3" json:"XID,omitempty"` BranchID int64 `protobuf:"varint,2,opt,name=BranchID,proto3" json:"BranchID,omitempty"` SqlUndoLogs []*PbSqlUndoLog `protobuf:"bytes,3,rep,name=SqlUndoLogs,proto3" json:"SqlUndoLogs,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*PbBranchUndoLog) Descriptor ¶ added in v1.4.4
func (*PbBranchUndoLog) Descriptor() ([]byte, []int)
func (*PbBranchUndoLog) GetBranchID ¶ added in v1.4.4
func (m *PbBranchUndoLog) GetBranchID() int64
func (*PbBranchUndoLog) GetSqlUndoLogs ¶ added in v1.4.4
func (m *PbBranchUndoLog) GetSqlUndoLogs() []*PbSqlUndoLog
func (*PbBranchUndoLog) GetXid ¶ added in v1.4.4
func (m *PbBranchUndoLog) GetXid() string
func (*PbBranchUndoLog) ProtoMessage ¶ added in v1.4.4
func (*PbBranchUndoLog) ProtoMessage()
func (*PbBranchUndoLog) Reset ¶ added in v1.4.4
func (m *PbBranchUndoLog) Reset()
func (*PbBranchUndoLog) String ¶ added in v1.4.4
func (m *PbBranchUndoLog) String() string
func (*PbBranchUndoLog) XXX_DiscardUnknown ¶ added in v1.4.4
func (m *PbBranchUndoLog) XXX_DiscardUnknown()
func (*PbBranchUndoLog) XXX_Marshal ¶ added in v1.4.4
func (m *PbBranchUndoLog) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*PbBranchUndoLog) XXX_Merge ¶ added in v1.4.4
func (m *PbBranchUndoLog) XXX_Merge(src proto.Message)
func (*PbBranchUndoLog) XXX_Size ¶ added in v1.4.4
func (m *PbBranchUndoLog) XXX_Size() int
func (*PbBranchUndoLog) XXX_Unmarshal ¶ added in v1.4.4
func (m *PbBranchUndoLog) XXX_Unmarshal(b []byte) error
type PbField ¶ added in v1.4.4
type PbField struct { Name string `protobuf:"bytes,1,opt,name=Name,proto3" json:"Name,omitempty"` KeyType int32 `protobuf:"varint,2,opt,name=KeyType,proto3" json:"KeyType,omitempty"` Type int32 `protobuf:"zigzag32,3,opt,name=Type,proto3" json:"Type,omitempty"` Value []byte `protobuf:"bytes,4,opt,name=Value,proto3" json:"Value,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*PbField) Descriptor ¶ added in v1.4.4
func (*PbField) GetKeyType ¶ added in v1.4.4
func (*PbField) ProtoMessage ¶ added in v1.4.4
func (*PbField) ProtoMessage()
func (*PbField) XXX_DiscardUnknown ¶ added in v1.4.4
func (m *PbField) XXX_DiscardUnknown()
func (*PbField) XXX_Marshal ¶ added in v1.4.4
func (*PbField) XXX_Unmarshal ¶ added in v1.4.4
type PbRow ¶ added in v1.4.4
type PbRow struct { Fields []*PbField `protobuf:"bytes,1,rep,name=Fields,proto3" json:"Fields,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*PbRow) Descriptor ¶ added in v1.4.4
func (*PbRow) ProtoMessage ¶ added in v1.4.4
func (*PbRow) ProtoMessage()
func (*PbRow) XXX_DiscardUnknown ¶ added in v1.4.4
func (m *PbRow) XXX_DiscardUnknown()
func (*PbRow) XXX_Marshal ¶ added in v1.4.4
func (*PbRow) XXX_Unmarshal ¶ added in v1.4.4
type PbSqlUndoLog ¶ added in v1.4.4
type PbSqlUndoLog struct { SqlType int32 `protobuf:"varint,1,opt,name=SqlType,proto3" json:"SqlType,omitempty"` TableName string `protobuf:"bytes,2,opt,name=TableName,proto3" json:"TableName,omitempty"` BeforeImage *PbTableRecords `protobuf:"bytes,3,opt,name=BeforeImage,proto3" json:"BeforeImage,omitempty"` AfterImage *PbTableRecords `protobuf:"bytes,4,opt,name=AfterImage,proto3" json:"AfterImage,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*PbSqlUndoLog) Descriptor ¶ added in v1.4.4
func (*PbSqlUndoLog) Descriptor() ([]byte, []int)
func (*PbSqlUndoLog) GetAfterImage ¶ added in v1.4.4
func (m *PbSqlUndoLog) GetAfterImage() *PbTableRecords
func (*PbSqlUndoLog) GetBeforeImage ¶ added in v1.4.4
func (m *PbSqlUndoLog) GetBeforeImage() *PbTableRecords
func (*PbSqlUndoLog) GetSqlType ¶ added in v1.4.4
func (m *PbSqlUndoLog) GetSqlType() int32
func (*PbSqlUndoLog) GetTableName ¶ added in v1.4.4
func (m *PbSqlUndoLog) GetTableName() string
func (*PbSqlUndoLog) ProtoMessage ¶ added in v1.4.4
func (*PbSqlUndoLog) ProtoMessage()
func (*PbSqlUndoLog) Reset ¶ added in v1.4.4
func (m *PbSqlUndoLog) Reset()
func (*PbSqlUndoLog) String ¶ added in v1.4.4
func (m *PbSqlUndoLog) String() string
func (*PbSqlUndoLog) XXX_DiscardUnknown ¶ added in v1.4.4
func (m *PbSqlUndoLog) XXX_DiscardUnknown()
func (*PbSqlUndoLog) XXX_Marshal ¶ added in v1.4.4
func (m *PbSqlUndoLog) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*PbSqlUndoLog) XXX_Merge ¶ added in v1.4.4
func (m *PbSqlUndoLog) XXX_Merge(src proto.Message)
func (*PbSqlUndoLog) XXX_Size ¶ added in v1.4.4
func (m *PbSqlUndoLog) XXX_Size() int
func (*PbSqlUndoLog) XXX_Unmarshal ¶ added in v1.4.4
func (m *PbSqlUndoLog) XXX_Unmarshal(b []byte) error
type PbTableRecords ¶ added in v1.4.4
type PbTableRecords struct { TableName string `protobuf:"bytes,1,opt,name=TableName,proto3" json:"TableName,omitempty"` Rows []*PbRow `protobuf:"bytes,2,rep,name=Rows,proto3" json:"Rows,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*PbTableRecords) Descriptor ¶ added in v1.4.4
func (*PbTableRecords) Descriptor() ([]byte, []int)
func (*PbTableRecords) GetRows ¶ added in v1.4.4
func (m *PbTableRecords) GetRows() []*PbRow
func (*PbTableRecords) GetTableName ¶ added in v1.4.4
func (m *PbTableRecords) GetTableName() string
func (*PbTableRecords) ProtoMessage ¶ added in v1.4.4
func (*PbTableRecords) ProtoMessage()
func (*PbTableRecords) Reset ¶ added in v1.4.4
func (m *PbTableRecords) Reset()
func (*PbTableRecords) String ¶ added in v1.4.4
func (m *PbTableRecords) String() string
func (*PbTableRecords) XXX_DiscardUnknown ¶ added in v1.4.4
func (m *PbTableRecords) XXX_DiscardUnknown()
func (*PbTableRecords) XXX_Marshal ¶ added in v1.4.4
func (m *PbTableRecords) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*PbTableRecords) XXX_Merge ¶ added in v1.4.4
func (m *PbTableRecords) XXX_Merge(src proto.Message)
func (*PbTableRecords) XXX_Size ¶ added in v1.4.4
func (m *PbTableRecords) XXX_Size() int
func (*PbTableRecords) XXX_Unmarshal ¶ added in v1.4.4
func (m *PbTableRecords) XXX_Unmarshal(b []byte) error
type ProtoBufUndoLogParser ¶ added in v1.4.4
type ProtoBufUndoLogParser struct { }
func (ProtoBufUndoLogParser) Decode ¶ added in v1.4.4
func (parser ProtoBufUndoLogParser) Decode(data []byte) *branchUndoLog
func (ProtoBufUndoLogParser) Encode ¶ added in v1.4.4
func (parser ProtoBufUndoLogParser) Encode(branchUndoLog *branchUndoLog) []byte
func (ProtoBufUndoLogParser) GetDefaultContent ¶ added in v1.4.4
func (parser ProtoBufUndoLogParser) GetDefaultContent() []byte
func (ProtoBufUndoLogParser) GetName ¶ added in v1.4.4
func (parser ProtoBufUndoLogParser) GetName() string
type Result ¶ added in v1.4.19
type Result interface { driver.Result // AllRowsAffected returns a slice containing the affected rows for each // executed statement. AllRowsAffected() []int64 // AllLastInsertIds returns a slice containing the last inserted ID for each // executed statement. AllLastInsertIds() []int64 }
Result exposes data not available through *connection.Result.
This is accessible by executing statements using sql.Conn.Raw() and downcasting the returned result:
res, err := rawConn.Exec(...) res.(mysql.Result).AllRowsAffected()
type SQLType ¶ added in v1.4.4
type SQLType byte
const ( SQLType_SELECT SQLType = iota SQLType_INSERT SQLType_UPDATE SQLType_DELETE SQLType_SELECT_FOR_UPDATE SQLType_REPLACE SQLType_TRUNCATE SQLType_CREATE SQLType_DROP SQLType_LOAD SQLType_MERGE SQLType_SHOW SQLType_ALTER SQLType_RENAME SQLType_DUMP SQLType_DEBUG SQLType_EXPLAIN SQLType_PROCEDURE SQLType_DESC SQLType_SET SQLType = 27 SQLType_RELOAD SQLType = 28 SQLType_SELECT_UNION SQLType = 29 SQLType_CREATE_TABLE SQLType = 30 SQLType_DROP_TABLE SQLType = 31 SQLType_ALTER_TABLE SQLType = 32 SQLType_SAVE_POINT SQLType = 33 SQLType_SELECT_FROM_UPDATE SQLType = 34 SQLType_MULTI_DELETE SQLType = 35 SQLType_MULTI_UPDATE SQLType = 36 SQLType_CREATE_INDEX SQLType = 37 SQLType_DROP_INDEX SQLType = 38 )
type Scanner ¶ added in v1.4.4
type Scanner interface { // Scan assigns a value from a database driver. // // The src value will be of one of the following types: // // int64 // float64 // bool // []byte // string // time.Time // nil - for NULL values // // An error should be returned if the value cannot be stored // without loss of information. // // Reference types such as []byte are only valid until the next call to Scan // and should not be retained. Their underlying memory is owned by the driver. // If retention is necessary, copy their values before the next call to Scan. Scan(src interface{}) error }
Scanner is an interface used by Scan.
type SqlDataType ¶ added in v1.4.4
type SqlDataType int32
type TableMetaCache ¶ added in v1.4.4
type TableMetaCache struct {
// contains filtered or unexported fields
}
func GetTableMetaCache ¶ added in v1.4.4
func GetTableMetaCache(dbName string) *TableMetaCache
func (*TableMetaCache) FetchSchema ¶ added in v1.4.4
func (cache *TableMetaCache) FetchSchema(conn *mysqlConn, tableName string) (schema.TableMeta, error)
func (*TableMetaCache) GetCacheKey ¶ added in v1.4.4
func (cache *TableMetaCache) GetCacheKey(tableName string) string
func (*TableMetaCache) GetTableMeta ¶ added in v1.4.4
func (cache *TableMetaCache) GetTableMeta(conn *mysqlConn, tableName string) (schema.TableMeta, error)
func (*TableMetaCache) Refresh ¶ added in v1.4.4
func (cache *TableMetaCache) Refresh(conn *mysqlConn, resourceID string)
type UndoLogParser ¶ added in v1.4.4
type UndoLogParser interface { GetName() string // return the default content if undo log is empty GetDefaultContent() []byte Encode(branchUndoLog *branchUndoLog) []byte Decode(data []byte) *branchUndoLog }
func GetUndoLogParser ¶ added in v1.4.4
func GetUndoLogParser() UndoLogParser
Source Files
¶
- atomic_bool.go
- auth.go
- buffer.go
- collations.go
- conncheck.go
- connection.go
- connector.go
- const.go
- datasource_manager.go
- driver.go
- dsn.go
- errors.go
- executor.go
- fields.go
- infile.go
- mysql_keyword_checker.go
- mysql_undo_executor.go
- mysql_undo_log_manager.go
- nulltime.go
- nulltime_go113.go
- packets.go
- protobuf_undo_log_parser.go
- result.go
- rows.go
- sql_data_type.go
- sql_type.go
- statement.go
- table_meta_cache.go
- table_records.pb.go
- transaction.go
- undo_log.go
- undo_log.pb.go
- undo_log_parser.go
- utils.go