File tree 4 files changed +25
-0
lines changed
4 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -760,6 +760,10 @@ pub enum Statement {
760
760
///
761
761
/// Note: this is a MySQL-specific statement.
762
762
ShowCollation { filter : Option < ShowStatementFilter > } ,
763
+ /// USE
764
+ ///
765
+ /// Note: this is a MySQL-specific statement.
766
+ Use { db_name : Ident } ,
763
767
/// `{ BEGIN [ TRANSACTION | WORK ] | START TRANSACTION } ...`
764
768
StartTransaction { modes : Vec < TransactionMode > } ,
765
769
/// `SET TRANSACTION ...`
@@ -1407,6 +1411,10 @@ impl fmt::Display for Statement {
1407
1411
}
1408
1412
Ok ( ( ) )
1409
1413
}
1414
+ Statement :: Use { db_name } => {
1415
+ write ! ( f, "USE {}" , db_name) ?;
1416
+ Ok ( ( ) )
1417
+ }
1410
1418
Statement :: StartTransaction { modes } => {
1411
1419
write ! ( f, "START TRANSACTION" ) ?;
1412
1420
if !modes. is_empty ( ) {
Original file line number Diff line number Diff line change @@ -475,6 +475,7 @@ define_keywords!(
475
475
UNNEST ,
476
476
UPDATE ,
477
477
UPPER ,
478
+ USE ,
478
479
USER ,
479
480
USING ,
480
481
UUID ,
Original file line number Diff line number Diff line change @@ -157,6 +157,7 @@ impl<'a> Parser<'a> {
157
157
Keyword :: COPY => Ok ( self . parse_copy ( ) ?) ,
158
158
Keyword :: SET => Ok ( self . parse_set ( ) ?) ,
159
159
Keyword :: SHOW => Ok ( self . parse_show ( ) ?) ,
160
+ Keyword :: USE => Ok ( self . parse_use ( ) ?) ,
160
161
Keyword :: START => Ok ( self . parse_start_transaction ( ) ?) ,
161
162
// `BEGIN` is a nonstandard but common alias for the
162
163
// standard `START TRANSACTION` statement. It is supported
@@ -2801,6 +2802,11 @@ impl<'a> Parser<'a> {
2801
2802
}
2802
2803
}
2803
2804
2805
+ pub fn parse_use ( & mut self ) -> Result < Statement , ParserError > {
2806
+ let db_name = self . parse_identifier ( ) ?;
2807
+ Ok ( Statement :: Use { db_name } )
2808
+ }
2809
+
2804
2810
pub fn parse_table_and_joins ( & mut self ) -> Result < TableWithJoins , ParserError > {
2805
2811
let relation = self . parse_table_factor ( ) ?;
2806
2812
Original file line number Diff line number Diff line change @@ -182,6 +182,16 @@ fn parse_show_collation() {
182
182
) ;
183
183
}
184
184
185
+ #[ test]
186
+ fn parse_use ( ) {
187
+ assert_eq ! (
188
+ mysql_and_generic( ) . verified_stmt( "USE database_name" ) ,
189
+ Statement :: Use {
190
+ db_name: Ident :: new( "database_name" )
191
+ }
192
+ ) ;
193
+ }
194
+
185
195
#[ test]
186
196
fn parse_show_create ( ) {
187
197
let obj_name = ObjectName ( vec ! [ Ident :: new( "myident" ) ] ) ;
You can’t perform that action at this time.
0 commit comments