variable

package
v0.0.0-...-815d2fd Latest Latest
Warning

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

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

Documentation

Index

Constants

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

Variable error codes.

View Source
const (
	// CollationConnection is the name for collation_connection system variable.
	CollationConnection = "collation_connection"
	// CharsetDatabase is the name for charactor_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 BindGlobalVarAccessor

func BindGlobalVarAccessor(ctx context.Context, accessor GlobalVarAccessor)

BindGlobalVarAccessor binds global var accessor to context.

func BindSessionVars

func BindSessionVars(ctx context.Context)

BindSessionVars creates a session vars object and binds it to context.

func GetCharsetInfo

func GetCharsetInfo(ctx context.Context) (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 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(ctx context.Context, name string) (string, error)
	// SetGlobalSysVar sets the global system variable name to value.
	SetGlobalSysVar(ctx context.Context, name string, value string) error
}

GlobalVarAccessor is the interface for accessing global scope system and status variables.

func GetGlobalVarAccessor

func GetGlobalVarAccessor(ctx context.Context) GlobalVarAccessor

GetGlobalVarAccessor gets accessor from ctx.

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

	// Strict SQL mode
	StrictSQLMode bool

	// InUpdateStmt indicates if the session is handling update stmt.
	InUpdateStmt bool
	// contains filtered or unexported fields
}

SessionVars is to handle user-defined or global variables in current session.

func GetSessionVars

func GetSessionVars(ctx context.Context) *SessionVars

GetSessionVars gets the session vars from context.

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

func (s *SessionVars) GetNextPreparedStmtID() uint32

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

func (*SessionVars) GetSystemVar

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

GetSystemVar gets a system 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.

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