Skip to content

Commit 32c0ab7

Browse files
committed
undo the initvalue and setvalue changes
1 parent 53e17b4 commit 32c0ab7

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

sql/base_session.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (s *BaseSession) InitSessionVariableDefault(ctx *Context, sysVarName string
167167
}
168168

169169
sysVar.SetDefault(value)
170-
svv, err := sysVar.InitValue(ctx, sysVar.GetDefault(), value, false)
170+
svv, err := sysVar.InitValue(ctx, value, false)
171171
if err != nil {
172172
return err
173173
}
@@ -180,25 +180,21 @@ func (s *BaseSession) InitSessionVariableDefault(ctx *Context, sysVarName string
180180
return nil
181181
}
182182

183-
func (s *BaseSession) setSessVar(ctx *Context, sysVar SystemVariable, newVal interface{}, init bool) error {
183+
func (s *BaseSession) setSessVar(ctx *Context, sysVar SystemVariable, val interface{}, init bool) error {
184184
var svv SystemVarValue
185185
var err error
186-
sysVarName := strings.ToLower(sysVar.GetName())
187-
var currVal = sysVar.GetDefault()
188-
if ov, ok := s.systemVars[sysVarName]; ok {
189-
currVal = ov.Val
190-
}
191186
if init {
192-
svv, err = sysVar.InitValue(ctx, currVal, newVal, false)
187+
svv, err = sysVar.InitValue(ctx, val, false)
193188
if err != nil {
194189
return err
195190
}
196191
} else {
197-
svv, err = sysVar.SetValue(ctx, currVal, newVal, false)
192+
svv, err = sysVar.SetValue(ctx, val, false)
198193
if err != nil {
199194
return err
200195
}
201196
}
197+
sysVarName := strings.ToLower(sysVar.GetName())
202198
s.systemVars[sysVarName] = svv
203199
if sysVarName == characterSetResultsSysVarName {
204200
s.charset = CharacterSet_Unspecified

sql/core.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,12 @@ type SystemVariable interface {
547547
// InitValue sets value without validation.
548548
// This is used for setting the initial values internally
549549
// using pre-defined variables or for test-purposes.
550-
InitValue(ctx *Context, currVal, newVal any, global bool) (SystemVarValue, error)
550+
InitValue(ctx *Context, val any, global bool) (SystemVarValue, error)
551551
// SetValue sets the value of the sv of given scope, global or session
552552
// It validates setting value of correct scope,
553553
// converts the given value to appropriate value depending on the sv
554554
// and it returns the SystemVarValue with the updated value.
555-
SetValue(ctx *Context, currVal, newVal any, global bool) (SystemVarValue, error)
555+
SetValue(ctx *Context, val any, global bool) (SystemVarValue, error)
556556
// IsReadOnly checks whether the variable is read only.
557557
// It returns false if variable can be set to a value.
558558
IsReadOnly() bool
@@ -626,8 +626,8 @@ func (m *MysqlSystemVariable) GetDefault() any {
626626
}
627627

628628
// InitValue implements SystemVariable.
629-
func (m *MysqlSystemVariable) InitValue(ctx *Context, currVal, newVal any, global bool) (SystemVarValue, error) {
630-
convertedVal, _, err := m.Type.Convert(ctx, newVal)
629+
func (m *MysqlSystemVariable) InitValue(ctx *Context, val any, global bool) (SystemVarValue, error) {
630+
convertedVal, _, err := m.Type.Convert(ctx, val)
631631
if err != nil {
632632
return SystemVarValue{}, err
633633
}
@@ -649,7 +649,7 @@ func (m *MysqlSystemVariable) InitValue(ctx *Context, currVal, newVal any, globa
649649
}
650650

651651
// SetValue implements SystemVariable.
652-
func (m *MysqlSystemVariable) SetValue(ctx *Context, currVal, newVal any, global bool) (SystemVarValue, error) {
652+
func (m *MysqlSystemVariable) SetValue(ctx *Context, val any, global bool) (SystemVarValue, error) {
653653
if global && m.Scope.Type == SystemVariableScope_Session {
654654
return SystemVarValue{}, ErrSystemVariableSessionOnly.New(m.Name)
655655
}
@@ -659,7 +659,7 @@ func (m *MysqlSystemVariable) SetValue(ctx *Context, currVal, newVal any, global
659659
if !m.Dynamic || m.ValueFunction != nil {
660660
return SystemVarValue{}, ErrSystemVariableReadOnly.New(m.Name)
661661
}
662-
return m.InitValue(ctx, currVal, newVal, global)
662+
return m.InitValue(ctx, val, global)
663663
}
664664

665665
// IsReadOnly implements SystemVariable.

sql/variables/system_variables.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (sv *globalSystemVariables) AssignValues(vals map[string]interface{}) error
7878
if !ok {
7979
return sql.ErrUnknownSystemVariable.New(varName)
8080
}
81-
svv, err := sysVar.InitValue(ctx, sysVar.GetDefault(), val, true)
81+
svv, err := sysVar.InitValue(ctx, val, true)
8282
if err != nil {
8383
return err
8484
}
@@ -137,19 +137,15 @@ func (sv *globalSystemVariables) GetGlobal(name string) (sql.SystemVariable, int
137137
// Only global dynamic variables may be set through this function, as it is intended for use through the SET GLOBAL
138138
// statement. To set session system variables, use the appropriate function on the session context. To set values
139139
// directly (such as when loading persisted values), use AssignValues. Case-insensitive.
140-
func (sv *globalSystemVariables) SetGlobal(ctx *sql.Context, name string, newVal interface{}) error {
140+
func (sv *globalSystemVariables) SetGlobal(ctx *sql.Context, name string, val interface{}) error {
141141
sv.mutex.Lock()
142142
defer sv.mutex.Unlock()
143143
name = strings.ToLower(name)
144144
sysVar, ok := systemVars[name]
145145
if !ok {
146146
return sql.ErrUnknownSystemVariable.New(name)
147147
}
148-
var currVal = sysVar.GetDefault()
149-
if sysVarVal, exists := sv.sysVarVals[name]; exists {
150-
currVal = sysVarVal.Val
151-
}
152-
svv, err := sysVar.SetValue(ctx, currVal, newVal, true)
148+
svv, err := sysVar.SetValue(ctx, val, true)
153149
if err != nil {
154150
return err
155151
}

0 commit comments

Comments
 (0)