@@ -377,13 +377,37 @@ func (n *ExecuteStmt) Accept(v Visitor) (Node, bool) {
377377// See https://dev.mysql.com/doc/refman/5.7/en/commit.html
378378type BeginStmt struct {
379379 stmtNode
380- Mode string
380+ Mode string
381+ ReadOnly bool
382+ Bound * TimestampBound
381383}
382384
383385// Restore implements Node interface.
384386func (n * BeginStmt ) Restore (ctx * RestoreCtx ) error {
385387 if n .Mode == "" {
386- ctx .WriteKeyWord ("START TRANSACTION" )
388+ if n .ReadOnly {
389+ ctx .WriteKeyWord ("START TRANSACTION READ ONLY" )
390+ if n .Bound != nil {
391+ switch n .Bound .Mode {
392+ case TimestampBoundStrong :
393+ ctx .WriteKeyWord (" WITH TIMESTAMP BOUND STRONG" )
394+ case TimestampBoundMaxStaleness :
395+ ctx .WriteKeyWord (" WITH TIMESTAMP BOUND MAX STALENESS " )
396+ return n .Bound .Timestamp .Restore (ctx )
397+ case TimestampBoundExactStaleness :
398+ ctx .WriteKeyWord (" WITH TIMESTAMP BOUND EXACT STALENESS " )
399+ return n .Bound .Timestamp .Restore (ctx )
400+ case TimestampBoundReadTimestamp :
401+ ctx .WriteKeyWord (" WITH TIMESTAMP BOUND READ TIMESTAMP " )
402+ return n .Bound .Timestamp .Restore (ctx )
403+ case TimestampBoundMinReadTimestamp :
404+ ctx .WriteKeyWord (" WITH TIMESTAMP BOUND MIN READ TIMESTAMP " )
405+ return n .Bound .Timestamp .Restore (ctx )
406+ }
407+ }
408+ } else {
409+ ctx .WriteKeyWord ("START TRANSACTION" )
410+ }
387411 } else {
388412 ctx .WriteKeyWord ("BEGIN " )
389413 ctx .WriteKeyWord (n .Mode )
@@ -398,6 +422,13 @@ func (n *BeginStmt) Accept(v Visitor) (Node, bool) {
398422 return v .Leave (newNode )
399423 }
400424 n = newNode .(* BeginStmt )
425+ if n .Bound != nil && n .Bound .Timestamp != nil {
426+ newTimestamp , ok := n .Bound .Timestamp .Accept (v )
427+ if ! ok {
428+ return n , false
429+ }
430+ n .Bound .Timestamp = newTimestamp .(ExprNode )
431+ }
401432 return v .Leave (n )
402433}
403434
0 commit comments