@@ -2047,7 +2047,8 @@ pub enum Statement {
20472047 table_name : ObjectName ,
20482048 if_exists : bool ,
20492049 } ,
2050- ///CreateSequence -- define a new sequence
2050+ /// Define a new sequence:
2051+ ///
20512052 /// CREATE [ { TEMPORARY | TEMP } ] SEQUENCE [ IF NOT EXISTS ] <sequence_name>
20522053 CreateSequence {
20532054 temporary : bool ,
@@ -2068,6 +2069,15 @@ pub enum Statement {
20682069 value : Option < Value > ,
20692070 is_eq : bool ,
20702071 } ,
2072+ /// `LOCK TABLES <table_name> [READ [LOCAL] | [LOW_PRIORITY] WRITE]`
2073+ ///
2074+ /// Note: this is a MySQL-specific statement. See <https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html>
2075+ LockTables {
2076+ tables : Vec < LockTable > ,
2077+ } ,
2078+ /// `UNLOCK TABLES`
2079+ /// Note: this is a MySQL-specific statement. See <https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html>
2080+ UnlockTables ,
20712081}
20722082
20732083impl fmt:: Display for Statement {
@@ -3477,6 +3487,12 @@ impl fmt::Display for Statement {
34773487 }
34783488 Ok ( ( ) )
34793489 }
3490+ Statement :: LockTables { tables } => {
3491+ write ! ( f, "LOCK TABLES {}" , display_comma_separated( tables) )
3492+ }
3493+ Statement :: UnlockTables => {
3494+ write ! ( f, "UNLOCK TABLES" )
3495+ }
34803496 }
34813497 }
34823498}
@@ -4979,6 +4995,61 @@ impl fmt::Display for SearchModifier {
49794995 }
49804996}
49814997
4998+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
4999+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5000+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5001+ pub struct LockTable {
5002+ pub table : Ident ,
5003+ pub alias : Option < Ident > ,
5004+ pub lock_type : LockTableType ,
5005+ }
5006+
5007+ impl fmt:: Display for LockTable {
5008+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
5009+ let Self {
5010+ table : tbl_name,
5011+ alias,
5012+ lock_type,
5013+ } = self ;
5014+
5015+ write ! ( f, "{tbl_name} " ) ?;
5016+ if let Some ( alias) = alias {
5017+ write ! ( f, "AS {alias} " ) ?;
5018+ }
5019+ write ! ( f, "{lock_type}" ) ?;
5020+ Ok ( ( ) )
5021+ }
5022+ }
5023+
5024+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5025+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5026+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5027+ pub enum LockTableType {
5028+ Read { local : bool } ,
5029+ Write { low_priority : bool } ,
5030+ }
5031+
5032+ impl fmt:: Display for LockTableType {
5033+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
5034+ match self {
5035+ Self :: Read { local } => {
5036+ write ! ( f, "READ" ) ?;
5037+ if * local {
5038+ write ! ( f, " LOCAL" ) ?;
5039+ }
5040+ }
5041+ Self :: Write { low_priority } => {
5042+ if * low_priority {
5043+ write ! ( f, "LOW_PRIORITY " ) ?;
5044+ }
5045+ write ! ( f, "WRITE" ) ?;
5046+ }
5047+ }
5048+
5049+ Ok ( ( ) )
5050+ }
5051+ }
5052+
49825053#[ cfg( test) ]
49835054mod tests {
49845055 use super :: * ;
0 commit comments