Skip to content

Commit

Permalink
support keyword OPTIMISTIC and PESSIMISTIC. (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood committed May 22, 2019
1 parent 4afa585 commit 4628ac3
Show file tree
Hide file tree
Showing 5 changed files with 6,244 additions and 6,200 deletions.
15 changes: 13 additions & 2 deletions ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ const (
DrainerType = "DRAINER"
)

// Transaction mode constants.
const (
Optimistic = "OPTIMISTIC"
Pessimistic = "PESSIMISTIC"
)

var (
// ExplainFormats stores the valid formats for explain statement, used by validator.
ExplainFormats = []string{
Expand Down Expand Up @@ -365,12 +371,17 @@ func (n *ExecuteStmt) Accept(v Visitor) (Node, bool) {
// See https://dev.mysql.com/doc/refman/5.7/en/commit.html
type BeginStmt struct {
stmtNode
Pessimistic bool
Mode string
}

// Restore implements Node interface.
func (n *BeginStmt) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord("START TRANSACTION")
if n.Mode == "" {
ctx.WriteKeyWord("START TRANSACTION")
} else {
ctx.WriteKeyWord("BEGIN ")
ctx.WriteKeyWord(n.Mode)
}
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ var tokenMap = map[string]int{
"OFFSET": offset,
"ON": on,
"ONLY": only,
"OPTIMISTIC": optimistic,
"OPTION": option,
"OPTIONALLY": optionally,
"OR": or,
Expand All @@ -400,6 +401,7 @@ var tokenMap = map[string]int{
"PARTITION": partition,
"PARTITIONS": partitions,
"PASSWORD": password,
"PESSIMISTIC": pessimistic,
"PLUGINS": plugins,
"POSITION": position,
"PRECEDING": preceding,
Expand Down
Loading

0 comments on commit 4628ac3

Please sign in to comment.