@@ -159,16 +159,37 @@ func (s *BaseSession) InitSessionVariable(ctx *Context, sysVarName string, value
159159 return s .setSessVar (ctx , sysVar , value , true )
160160}
161161
162- func (s * BaseSession ) setSessVar (ctx * Context , sysVar SystemVariable , value interface {}, init bool ) error {
162+ // InitSessionVariableDefault implements the Session interface and is used to initialize variables (Including read-only variables)
163+ func (s * BaseSession ) InitSessionVariableDefault (ctx * Context , sysVarName string , value interface {}) error {
164+ sysVar , _ , ok := SystemVariables .GetGlobal (sysVarName )
165+ if ! ok {
166+ return ErrUnknownSystemVariable .New (sysVarName )
167+ }
168+
169+ sysVar .SetDefault (value )
170+ svv , err := sysVar .InitValue (ctx , value , false )
171+ if err != nil {
172+ return err
173+ }
174+
175+ sysVarName = strings .ToLower (sysVarName )
176+ s .systemVars [sysVarName ] = svv
177+ if sysVarName == characterSetResultsSysVarName {
178+ s .charset = CharacterSet_Unspecified
179+ }
180+ return nil
181+ }
182+
183+ func (s * BaseSession ) setSessVar (ctx * Context , sysVar SystemVariable , val interface {}, init bool ) error {
163184 var svv SystemVarValue
164185 var err error
165186 if init {
166- svv , err = sysVar .InitValue (ctx , value , false )
187+ svv , err = sysVar .InitValue (ctx , val , false )
167188 if err != nil {
168189 return err
169190 }
170191 } else {
171- svv , err = sysVar .SetValue (ctx , value , false )
192+ svv , err = sysVar .SetValue (ctx , val , false )
172193 if err != nil {
173194 return err
174195 }
@@ -202,6 +223,22 @@ func (s *BaseSession) GetSessionVariable(ctx *Context, sysVarName string) (inter
202223 return sysVar .Val , nil
203224}
204225
226+ // GetSessionVariableDefault implements the Session interface.
227+ func (s * BaseSession ) GetSessionVariableDefault (ctx * Context , sysVarName string ) (interface {}, error ) {
228+ sysVarName = strings .ToLower (sysVarName )
229+ sysVar , ok := s .systemVars [sysVarName ]
230+ if ! ok {
231+ return nil , ErrUnknownSystemVariable .New (sysVarName )
232+ }
233+ // TODO: this is duplicated from within variables.globalSystemVariables, suggesting the need for an interface
234+ if sysType , ok := sysVar .Var .GetType ().(SetType ); ok {
235+ if sv , ok := sysVar .Var .GetDefault ().(uint64 ); ok {
236+ return sysType .BitsToString (sv )
237+ }
238+ }
239+ return sysVar .Var .GetDefault (), nil
240+ }
241+
205242// GetUserVariable implements the Session interface.
206243func (s * BaseSession ) GetUserVariable (ctx * Context , varName string ) (Type , interface {}, error ) {
207244 return s .userVars .GetUserVariable (ctx , varName )
0 commit comments