Documentation
¶
Index ¶
- Constants
- Variables
- func GetStatusVars() (map[string]*StatusVal, error)
- func RegisterStatistics(s Statistics)
- type GlobalVarAccessor
- type RetryInfo
- type ScopeFlag
- type SessionVars
- type StatementContext
- func (sc *StatementContext) AddAffectedRows(rows uint64)
- func (sc *StatementContext) AddFoundRows(rows uint64)
- func (sc *StatementContext) AffectedRows() uint64
- func (sc *StatementContext) AppendWarning(warn error)
- func (sc *StatementContext) FoundRows() uint64
- func (sc *StatementContext) GetWarnings() []error
- func (sc *StatementContext) SetWarnings(warns []error)
- type Statistics
- type StatusVal
- type SysVar
- type TransactionContext
Constants ¶
const ( SQLModeVar = "sql_mode" AutocommitVar = "autocommit" CharacterSetResults = "character_set_results" MaxAllowedPacket = "max_allowed_packet" TimeZone = "time_zone" )
special session variables.
const ( CodeUnknownStatusVar terror.ErrCode = 1 CodeUnknownSystemVar terror.ErrCode = 1193 CodeIncorrectScope terror.ErrCode = 1238 )
Variable error codes.
const ( // CollationConnection is the name for collation_connection system variable. CollationConnection = "collation_connection" // CharsetDatabase is the name for character_set_database system variable. CharsetDatabase = "character_set_database" // CollationDatabase is the name for collation_database system variable. CollationDatabase = "collation_database" )
Variables ¶
var ( UnknownStatusVar = terror.ClassVariable.New(CodeUnknownStatusVar, "unknown status variable") UnknownSystemVar = terror.ClassVariable.New(CodeUnknownSystemVar, "unknown system variable '%s'") ErrIncorrectScope = terror.ClassVariable.New(CodeIncorrectScope, "Incorrect variable scope") )
Variable errors
var DefaultScopeFlag = ScopeGlobal | ScopeSession
DefaultScopeFlag is the status default scope.
var (
ErrCantSetToNull = terror.ClassVariable.New(codeCantSetToNull, "cannot set variable to null")
)
Error instances.
var SetNamesVariables = []string{
"character_set_client",
"character_set_connection",
"character_set_results",
}
SetNamesVariables is the system variable names related to set names statements.
var SysVars map[string]*SysVar
SysVars is global sys vars map.
Functions ¶
func GetStatusVars ¶
GetStatusVars gets registered statistics status variables.
func RegisterStatistics ¶
func RegisterStatistics(s Statistics)
RegisterStatistics registers statistics.
Types ¶
type GlobalVarAccessor ¶
type GlobalVarAccessor interface {
// GetGlobalSysVar gets the global system variable value for name.
GetGlobalSysVar(name string) (string, error)
// SetGlobalSysVar sets the global system variable name to value.
SetGlobalSysVar(name string, value string) error
}
GlobalVarAccessor is the interface for accessing global scope system and status variables.
type RetryInfo ¶
type RetryInfo struct {
Retrying bool
DroppedPreparedStmtIDs []uint32
// contains filtered or unexported fields
}
RetryInfo saves retry information.
func (*RetryInfo) AddAutoIncrementID ¶
AddAutoIncrementID adds id to AutoIncrementIDs.
func (*RetryInfo) GetCurrAutoIncrementID ¶
GetCurrAutoIncrementID gets current AutoIncrementID.
func (*RetryInfo) ResetOffset ¶
func (r *RetryInfo) ResetOffset()
ResetOffset resets the current retry offset.
type ScopeFlag ¶
type ScopeFlag uint8
ScopeFlag is for system variable whether can be changed in global/session dynamically or not.
const ( // ScopeNone means the system variable can not be changed dynamically. ScopeNone ScopeFlag = 0 // ScopeGlobal means the system variable can be changed globally. ScopeGlobal ScopeFlag = 1 << 0 // ScopeSession means the system variable can only be changed in current session. ScopeSession ScopeFlag = 1 << 1 )
type SessionVars ¶
type SessionVars struct {
// user-defined variables
Users map[string]string
// system variables
Systems map[string]string
// Should be reset on transaction finished.
TxnCtx *TransactionContext
// following variables are special for current session
Status uint16
// Client capability
ClientCapability uint32
// Current user
User string
// Current DB
CurrentDB string
// Strict SQL mode
StrictSQLMode bool
// CommonGlobalLoaded indicates if common global variable has been loaded for this session.
CommonGlobalLoaded bool
// GlobalAccessor is used to set and get global variables.
GlobalVarsAccessor GlobalVarAccessor
// StmtCtx holds variables for current executing statement.
StmtCtx *StatementContext
// CurrInsertValues is used to record current ValuesExpr's values.
// See http://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_values
CurrInsertValues interface{}
// Per-connection time zones. Each client that connects has its own time zone setting, given by the session time_zone variable.
// See https://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html
TimeZone *time.Location
}
SessionVars is to handle user-defined or global variables in current session.
func NewSessionVars ¶
func NewSessionVars() *SessionVars
NewSessionVars creates a session vars object.
func (*SessionVars) GetCharsetInfo ¶
func (s *SessionVars) GetCharsetInfo() (charset, collation string)
GetCharsetInfo gets charset and collation for current context. What character set should the server translate a statement to after receiving it? For this, the server uses the character_set_connection and collation_connection system variables. It converts statements sent by the client from character_set_client to character_set_connection (except for string literals that have an introducer such as _latin1 or _utf8). collation_connection is important for comparisons of literal strings. For comparisons of strings with column values, collation_connection does not matter because columns have their own collation, which has a higher collation precedence. See https://dev.mysql.com/doc/refman/5.7/en/charset-connection.html
func (*SessionVars) GetStatusFlag ¶
func (s *SessionVars) GetStatusFlag(flag uint16) bool
GetStatusFlag gets the session server status variable, returns true if it is on.
func (*SessionVars) InTxn ¶
func (s *SessionVars) InTxn() bool
InTxn returns if the session is in transaction.
func (*SessionVars) IsAutocommit ¶
func (s *SessionVars) IsAutocommit() bool
IsAutocommit returns if the session is set to autocommit.
func (*SessionVars) SetStatusFlag ¶
func (s *SessionVars) SetStatusFlag(flag uint16, on bool)
SetStatusFlag sets the session server status variable. If on is ture sets the flag in session status, otherwise removes the flag.
type StatementContext ¶
type StatementContext struct {
/* Variables that are set before execution */
InUpdateOrDeleteStmt bool
IgnoreTruncate bool
TruncateAsWarning bool
// contains filtered or unexported fields
}
StatementContext contains variables for a statement. It should be reset before executing a statement.
func (*StatementContext) AddAffectedRows ¶
func (sc *StatementContext) AddAffectedRows(rows uint64)
AddAffectedRows adds affected rows.
func (*StatementContext) AddFoundRows ¶
func (sc *StatementContext) AddFoundRows(rows uint64)
AddFoundRows adds found rows.
func (*StatementContext) AffectedRows ¶
func (sc *StatementContext) AffectedRows() uint64
AffectedRows gets affected rows.
func (*StatementContext) AppendWarning ¶
func (sc *StatementContext) AppendWarning(warn error)
AppendWarning appends a warning.
func (*StatementContext) FoundRows ¶
func (sc *StatementContext) FoundRows() uint64
FoundRows gets found rows.
func (*StatementContext) GetWarnings ¶
func (sc *StatementContext) GetWarnings() []error
GetWarnings gets warnings.
func (*StatementContext) SetWarnings ¶
func (sc *StatementContext) SetWarnings(warns []error)
SetWarnings sets warnings.
type Statistics ¶
type Statistics interface {
// GetScope gets the status variables scope.
GetScope(status string) ScopeFlag
// Stats returns the statistics status variables.
Stats() (map[string]interface{}, error)
}
Statistics is the interface of statistics.
type StatusVal ¶
type StatusVal struct {
Scope ScopeFlag
Value interface{}
}
StatusVal is the value of the corresponding status variable.
type SysVar ¶
type SysVar struct {
// Scope is for whether can be changed or not
Scope ScopeFlag
// Variable name
Name string
// Variable value
Value string
}
SysVar is for system variable.
type TransactionContext ¶
TransactionContext is used to store variables that has transaction scope.