Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/parser/ast/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ type BetweenExpr struct {

// Restore implements Node interface.
func (n *BetweenExpr) Restore(ctx *format.RestoreCtx) error {
if ctx.Flags.HasRestoreBracketAroundBetweenExpr() {
ctx.WritePlain("(")
}
if err := n.Expr.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore BetweenExpr.Expr")
}
Expand All @@ -100,6 +103,9 @@ func (n *BetweenExpr) Restore(ctx *format.RestoreCtx) error {
if err := n.Right.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore BetweenExpr.Right ")
}
if ctx.Flags.HasRestoreBracketAroundBetweenExpr() {
ctx.WritePlain(")")
}
return nil
}

Expand Down Expand Up @@ -172,8 +178,10 @@ func restoreBinaryOpWithSpacesAround(ctx *format.RestoreCtx, op opcode.Op) error

// Restore implements Node interface.
func (n *BinaryOperationExpr) Restore(ctx *format.RestoreCtx) error {
originalFlags := ctx.Flags
if ctx.Flags.HasRestoreBracketAroundBinaryOperation() {
ctx.WritePlain("(")
ctx.Flags |= format.RestoreBracketAroundBetweenExpr
}
if err := n.L.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred when restore BinaryOperationExpr.L")
Expand All @@ -186,6 +194,7 @@ func (n *BinaryOperationExpr) Restore(ctx *format.RestoreCtx) error {
}
if ctx.Flags.HasRestoreBracketAroundBinaryOperation() {
ctx.WritePlain(")")
ctx.Flags = originalFlags
}
return nil
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/parser/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ const (
RestoreWithoutSchemaName
RestoreWithoutTableName
RestoreForNonPrepPlanCache

RestoreBracketAroundBetweenExpr
)

const (
Expand Down Expand Up @@ -323,6 +325,12 @@ func (rf RestoreFlags) HasStringWithoutDefaultCharset() bool {
return rf.has(RestoreStringWithoutDefaultCharset)
}

// HasRestoreBracketAroundBetweenExpr returns a boolean indicating
// whether `rf` has `RestoreBracketAroundBetweenExpr` flag.
func (rf RestoreFlags) HasRestoreBracketAroundBetweenExpr() bool {
return rf.has(RestoreBracketAroundBetweenExpr)
}

// HasStringWithoutCharset returns a boolean indicating whether `rf` has `RestoreStringWithoutCharset` flag.
func (rf RestoreFlags) HasStringWithoutCharset() bool {
return rf.has(RestoreStringWithoutCharset)
Expand Down
Loading