@@ -47,6 +47,7 @@ type BaseSession struct {
4747 lastQueryInfo map [string ]* atomic.Value
4848 tx Transaction
4949 ignoreAutocommit bool
50+ charset CharacterSetID
5051
5152 // When the MySQL database updates any tables related to privileges, it increments its counter. We then update our
5253 // privilege set if our counter doesn't equal the database's counter.
@@ -177,6 +178,9 @@ func (s *BaseSession) setSessVar(ctx *Context, sysVar SystemVariable, value inte
177178 }
178179 sysVarName := strings .ToLower (sysVar .GetName ())
179180 s .systemVars [sysVarName ] = svv
181+ if sysVarName == characterSetResultsSysVarName {
182+ s .charset = CharacterSet_Unspecified
183+ }
180184 return nil
181185}
182186
@@ -263,15 +267,18 @@ func (s *BaseSession) GetCharacterSet() CharacterSetID {
263267
264268// GetCharacterSetResults returns the result character set for this session (defined by the system variable `character_set_results`).
265269func (s * BaseSession ) GetCharacterSetResults () CharacterSetID {
266- sysVar , _ := s .systemVars [characterSetResultsSysVarName ]
267- if sysVar .Val == nil {
268- return CharacterSet_Unspecified
269- }
270- charSet , err := ParseCharacterSet (sysVar .Val .(string ))
271- if err != nil {
272- panic (err ) // shouldn't happen
270+ if s .charset == CharacterSet_Unspecified {
271+ sysVar , _ := s .systemVars [characterSetResultsSysVarName ]
272+ if sysVar .Val == nil {
273+ return CharacterSet_Unspecified
274+ }
275+ var err error
276+ s .charset , err = ParseCharacterSet (sysVar .Val .(string ))
277+ if err != nil {
278+ panic (err ) // shouldn't happen
279+ }
273280 }
274- return charSet
281+ return s . charset
275282}
276283
277284// GetCollation returns the collation for this session (defined by the system variable `collation_connection`).
0 commit comments