Skip to content

Commit

Permalink
*: address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood committed Dec 23, 2015
1 parent 7e41cae commit 2d7a105
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions executor/prepared.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ func (e *PrepareExec) Close() error {
func (e *PrepareExec) DoPrepare() {
vars := variable.GetSessionVars(e.Ctx)
if e.ID != 0 {
// Must be the case when we retry a prepare.
// Make sure it is idempotent.
_, ok := vars.PreparedStmts[e.ID]
if ok {
return
Expand All @@ -122,6 +124,10 @@ func (e *PrepareExec) DoPrepare() {
stmt := l.Stmts()[0]
var extractor paramMarkerExtractor
stmt.Accept(&extractor)

// The parameter markers are appended in visiting order, which may not
// be the same as the position order in the query string. We need to
// sort it by position.
sorter := &paramMarkerSorter{markers: extractor.markers}
sort.Sort(sorter)
e.ParamCount = len(sorter.markers)
Expand Down
9 changes: 7 additions & 2 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func GetSessionVars(ctx context.Context) *SessionVars {
return v
}

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 @@ -90,8 +95,8 @@ func GetSessionVars(ctx context.Context) *SessionVars {
// See: https://dev.mysql.com/doc/refman/5.7/en/charset-connection.html
func GetCharsetInfo(ctx context.Context) (charset, collation string) {
sessionVars := GetSessionVars(ctx)
charset = sessionVars.Systems["character_set_connection"]
collation = sessionVars.Systems["collation_connection"]
charset = sessionVars.Systems[characterSetConnection]
collation = sessionVars.Systems[collationConnection]
return
}

Expand Down

0 comments on commit 2d7a105

Please sign in to comment.