Skip to content

Commit

Permalink
Merge pull request #6551 from planetscale/jacques_5825
Browse files Browse the repository at this point in the history
Correctly report AUTOCOMMIT status in network packets
  • Loading branch information
sougou authored Aug 17, 2020
2 parents 4f4fd30 + 3e4a8d6 commit cac2ca7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions go/mysql/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,13 @@ const (
// Originally found in include/mysql/mysql_com.h
// See http://dev.mysql.com/doc/internals/en/status-flags.html
const (
// ServerStatusAutocommit is SERVER_STATUS_AUTOCOMMIT.
ServerStatusAutocommit = 0x0002
// ServerStatusAutocommit is SERVER_STATUS_IN_TRANS
ServerStatusInTransaction = 0x0001
NoServerStatusInTransaction = 0xFFFE

// ServerStatusAutocommit is SERVER_STATUS_AUTOCOMMIT
ServerStatusAutocommit = 0x0002
NoServerStatusAutocommit = 0xFFFD

// ServerMoreResultsExists is SERVER_MORE_RESULTS_EXISTS
ServerMoreResultsExists = 0x0008
Expand Down
15 changes: 15 additions & 0 deletions go/vt/vtgate/plugin_mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,23 @@ func (vh *vtgateHandler) ComQuery(c *mysql.Conn, query string, callback func(*sq
if err != nil {
return err
}
fillInTxStatusFlags(c, session)
return callback(result)
}

func fillInTxStatusFlags(c *mysql.Conn, session *vtgatepb.Session) {
if session.InTransaction {
c.StatusFlags |= mysql.ServerStatusInTransaction
} else {
c.StatusFlags &= mysql.NoServerStatusInTransaction
}
if session.Autocommit {
c.StatusFlags |= mysql.ServerStatusAutocommit
} else {
c.StatusFlags &= mysql.NoServerStatusAutocommit
}
}

// ComPrepare is the handler for command prepare.
func (vh *vtgateHandler) ComPrepare(c *mysql.Conn, query string, bindVars map[string]*querypb.BindVariable) ([]*querypb.Field, error) {
var ctx context.Context
Expand Down Expand Up @@ -303,6 +317,7 @@ func (vh *vtgateHandler) ComStmtExecute(c *mysql.Conn, prepare *mysql.PrepareDat
err = mysql.NewSQLErrorFromError(err)
return err
}
fillInTxStatusFlags(c, session)

return callback(qr)
}
Expand Down

0 comments on commit cac2ca7

Please sign in to comment.