Skip to content

Commit

Permalink
plan: refine return type, charset and collation for 'get variable' ex…
Browse files Browse the repository at this point in the history
…pression (pingcap#4550)
  • Loading branch information
spongedu authored and coocood committed Sep 19, 2017
1 parent 9e6accb commit 8794374
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 5 additions & 1 deletion plan/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/parser/opcode"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/sessionctx/varsutil"
"github.com/pingcap/tidb/util/charset"
"github.com/pingcap/tidb/util/types"
Expand Down Expand Up @@ -764,7 +765,10 @@ func (er *expressionRewriter) rewriteVariable(v *ast.VariableExpr) {
er.err = errors.Trace(err)
return
}
er.ctxStack = append(er.ctxStack, datumToConstant(types.NewStringDatum(val), mysql.TypeString))
e := datumToConstant(types.NewStringDatum(val), mysql.TypeVarString)
e.RetType.Charset = er.ctx.GetSessionVars().Systems[variable.CharacterSetConnection]
e.RetType.Collate = er.ctx.GetSessionVars().Systems[variable.CollationConnection]
er.ctxStack = append(er.ctxStack, e)
return
}

Expand Down
9 changes: 2 additions & 7 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,6 @@ func NewSessionVars() *SessionVars {
}
}

const (
characterSetConnection = "character_set_connection"
collationConnection = "collation_connection"
)

// 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.
Expand All @@ -263,8 +258,8 @@ const (
// have their own collation, which has a higher collation precedence.
// See https://dev.mysql.com/doc/refman/5.7/en/charset-connection.html
func (s *SessionVars) GetCharsetInfo() (charset, collation string) {
charset = s.Systems[characterSetConnection]
collation = s.Systems[collationConnection]
charset = s.Systems[CharacterSetConnection]
collation = s.Systems[CollationConnection]
return
}

Expand Down
2 changes: 2 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ var SetNamesVariables = []string{
}

const (
// CharacterSetConnection is the name for character_set_connection system variable.
CharacterSetConnection = "character_set_connection"
// CollationConnection is the name for collation_connection system variable.
CollationConnection = "collation_connection"
// CharsetDatabase is the name for character_set_database system variable.
Expand Down

0 comments on commit 8794374

Please sign in to comment.