Skip to content

Commit

Permalink
Merge pull request #285 from flike/bugfix-autocommit
Browse files Browse the repository at this point in the history
Bugfix autocommit
  • Loading branch information
flike authored Nov 29, 2016
2 parents 2f21f25 + 13f4744 commit 104a5d4
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 215 deletions.
4 changes: 2 additions & 2 deletions core/hack/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hack

const (
Version = "2016-11-20 09:29:56 +0800 @c9b0909"
Compile = "2016-11-24 19:35:53 +0800 by go version go1.7.3 darwin/amd64"
Version = "2016-11-26 11:13:45 +0800 @7b5c49e"
Compile = "2016-11-26 11:25:54 +0800 by go version go1.7.1 linux/amd64"
)
19 changes: 12 additions & 7 deletions proxy/server/conn_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,17 @@ func (c *ClientConn) handleSet(stmt *sqlparser.Set, sql string) (err error) {
}

func (c *ClientConn) handleSetAutoCommit(val sqlparser.ValExpr) error {
value, ok := val.(sqlparser.NumVal)
if !ok {
return fmt.Errorf("set autocommit error")
flag := sqlparser.String(val)
flag = strings.Trim(flag, "'`\"")
// autocommit允许为 0, 1, ON, OFF, "ON", "OFF", 不允许"0", "1"
if flag == `0` || flag == `1` {
_, ok := val.(sqlparser.NumVal)
if !ok {
return fmt.Errorf("set autocommit error")
}
}
switch value[0] {
case '1':
switch strings.ToUpper(flag) {
case `1`, `ON`:
c.status |= mysql.SERVER_STATUS_AUTOCOMMIT
if c.status&mysql.SERVER_STATUS_IN_TRANS > 0 {
c.status &= ^mysql.SERVER_STATUS_IN_TRANS
Expand All @@ -95,10 +100,10 @@ func (c *ClientConn) handleSetAutoCommit(val sqlparser.ValExpr) error {
co.Close()
}
c.txConns = make(map[*backend.Node]*backend.BackendConn)
case '0':
case `0`, `OFF`:
c.status &= ^mysql.SERVER_STATUS_AUTOCOMMIT
default:
return fmt.Errorf("invalid autocommit flag %s", value)
return fmt.Errorf("invalid autocommit flag %s", flag)
}

return c.writeOK(nil)
Expand Down
Loading

0 comments on commit 104a5d4

Please sign in to comment.