variable

package
v0.0.0-...-40faf7d Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2016 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SQLModeVar    = "sql_mode"
	AutocommitVar = "autocommit"
)

special session variables.

View Source
const (
	CodeUnknownStatusVar terror.ErrCode = 1
	CodeUnknownSystemVar terror.ErrCode = 1193
)

Variable error codes.

View Source
const (
	TiDBSnapshot              = "tidb_snapshot"
	DistSQLScanConcurrencyVar = "tidb_distsql_scan_concurrency"
	DistSQLJoinConcurrencyVar = "tidb_distsql_join_concurrency"
	TiDBSkipConstraintCheck   = "tidb_skip_constraint_check"
)

TiDB system variables

View Source
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

View Source
var (
	UnknownStatusVar = terror.ClassVariable.New(CodeUnknownStatusVar, "unknown status variable")
	UnknownSystemVar = terror.ClassVariable.New(CodeUnknownSystemVar, "unknown system variable")
)

Variable errors

View Source
var DefaultScopeFlag = ScopeGlobal | ScopeSession

DefaultScopeFlag is the status default scope.

View Source
var SetNamesVariables = []string{
	"character_set_client",
	"character_set_connection",
	"character_set_results",
}

SetNamesVariables is the system variable names related to set names statements.

View Source
var SysVars map[string]*SysVar

SysVars is global sys vars map.

Functions

func GetStatusVars

func GetStatusVars() (map[string]*StatusVal, error)

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

	// Attempts is the current number of retry attempts.
	Attempts int
	// contains filtered or unexported fields
}

RetryInfo saves retry information.

func (*RetryInfo) AddAutoIncrementID

func (r *RetryInfo) AddAutoIncrementID(id int64)

AddAutoIncrementID adds id to AutoIncrementIDs.

func (*RetryInfo) Clean

func (r *RetryInfo) Clean()

Clean does some clean work.

func (*RetryInfo) GetCurrAutoIncrementID

func (r *RetryInfo) GetCurrAutoIncrementID() (int64, error)

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

	// prepared statement
	PreparedStmts        map[uint32]interface{}
	PreparedStmtNameToID map[string]uint32

	// retry information
	RetryInfo *RetryInfo

	// following variables are special for current session
	Status       uint16
	LastInsertID uint64
	AffectedRows uint64

	// Client capability
	ClientCapability uint32

	// Connection ID
	ConnectionID uint64

	// Found rows
	FoundRows uint64

	// 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

	// InUpdateStmt indicates if the session is handling update stmt.
	InUpdateStmt bool

	// InRestrictedSQL indicates if the session is handling restricted SQL execution.
	InRestrictedSQL bool

	// SnapshotTS is used for reading history data. For simplicity, SnapshotTS only supports distsql request.
	SnapshotTS uint64

	// SnapshotInfoschema is used with SnapshotTS, when the schema version at snapshotTS less than current schema
	// version, we load an old version schema for query.
	SnapshotInfoschema interface{}

	// SkipConstraintCheck is true when importing data.
	SkipConstraintCheck bool

	// GlobalAccessor is used to set and get global variables.
	GlobalVarsAccessor GlobalVarAccessor
	// contains filtered or unexported fields
}

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) AddAffectedRows

func (s *SessionVars) AddAffectedRows(rows uint64)

AddAffectedRows adds affected rows with the argument rows.

func (*SessionVars) AddFoundRows

func (s *SessionVars) AddFoundRows(rows uint64)

AddFoundRows adds found rows with the argument rows.

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) GetNextPreparedStmtID

func (s *SessionVars) GetNextPreparedStmtID() uint32

GetNextPreparedStmtID generates and returns the next session scope prepared statement id.

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) GetSystemVar

func (s *SessionVars) GetSystemVar(key string) types.Datum

GetSystemVar gets a system variable.

func (*SessionVars) GetTiDBSystemVar

func (s *SessionVars) GetTiDBSystemVar(name string) (string, error)

GetTiDBSystemVar gets variable value for name. The variable should be a TiDB specific system variable (The vars in tidbSysVars map). We load the variable from session first, if not found, use local defined default variable.

func (*SessionVars) SetAffectedRows

func (s *SessionVars) SetAffectedRows(affectedRows uint64)

SetAffectedRows saves the affected rows to the session context.

func (*SessionVars) SetCurrentUser

func (s *SessionVars) SetCurrentUser(user string)

SetCurrentUser saves the current user to the session context.

func (*SessionVars) SetLastInsertID

func (s *SessionVars) SetLastInsertID(insertID uint64)

SetLastInsertID saves the last insert id to the session context. TODO: we may store the result for last_insert_id sys var later.

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.

func (*SessionVars) SetSystemVar

func (s *SessionVars) SetSystemVar(key string, value types.Datum) error

SetSystemVar sets a system variable.

func (*SessionVars) ShouldAutocommit

func (s *SessionVars) ShouldAutocommit() bool

ShouldAutocommit checks if current session should autocommit. With START TRANSACTION, autocommit remains disabled until you end the transaction with COMMIT or ROLLBACK.

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.

func GetSysVar

func GetSysVar(name string) *SysVar

GetSysVar returns sys var info for name as key.

Jump to

Keyboard shortcuts

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