Skip to content

Commit

Permalink
[parser] support keyword OPTIMISTIC and PESSIMISTIC. (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood authored and ti-chi-bot committed Oct 9, 2021
1 parent 02f2bdc commit 6a484a4
Show file tree
Hide file tree
Showing 5 changed files with 6,244 additions and 6,200 deletions.
15 changes: 13 additions & 2 deletions parser/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 parser/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 6a484a4

Please sign in to comment.