Skip to content

Commit 9224db9

Browse files
committed
remove redundant code
1 parent 489da03 commit 9224db9

File tree

5 files changed

+18
-44
lines changed

5 files changed

+18
-44
lines changed

src/ast/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,7 +3407,7 @@ pub enum Statement {
34073407
/// Renames one or more tables
34083408
///
34093409
/// See Mysql <https://dev.mysql.com/doc/refman/9.1/en/rename-table.html>
3410-
RenameTable(Vec<RenameObjectDef>),
3410+
RenameTable(Vec<RenameTable>),
34113411
}
34123412

34133413
impl fmt::Display for Statement {
@@ -7660,12 +7660,12 @@ impl Display for JsonNullClause {
76607660
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
76617661
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
76627662
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7663-
pub struct RenameObjectDef {
7663+
pub struct RenameTable {
76647664
pub old_name: ObjectName,
76657665
pub new_name: ObjectName,
76667666
}
76677667

7668-
impl fmt::Display for RenameObjectDef {
7668+
impl fmt::Display for RenameTable {
76697669
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
76707670
write!(f, "{} TO {}", self.old_name, self.new_name)?;
76717671
Ok(())

src/dialect/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,6 @@ pub trait Dialect: Debug + Any {
715715
true
716716
}
717717

718-
// Returns true if the dialect supports the `RENAME TABLE` statement
719-
fn supports_rename_table(&self) -> bool {
720-
false
721-
}
722-
723718
/// Returns true if this dialect supports the `LIKE 'pattern'` option in
724719
/// a `SHOW` statement before the `IN` option
725720
fn supports_show_like_before_in(&self) -> bool {

src/dialect/mysql.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ impl Dialect for MySqlDialect {
102102
fn supports_create_table_select(&self) -> bool {
103103
true
104104
}
105-
106-
/// see <https://dev.mysql.com/doc/refman/9.1/en/rename-table.html>
107-
fn supports_rename_table(&self) -> bool {
108-
true
109-
}
110105
}
111106

112107
/// `LOCK TABLES`

src/parser/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,15 +1047,16 @@ impl<'a> Parser<'a> {
10471047
}
10481048

10491049
/// Parses a `RENAME TABLE` statement. See [Statement::RenameTable]
1050+
/// see <https://dev.mysql.com/doc/refman/9.1/en/rename-table.html>
10501051
pub fn parse_rename(&mut self) -> Result<Statement, ParserError> {
1051-
if self.dialect.supports_rename_table() && self.peek_keyword(Keyword::TABLE) {
1052+
if self.peek_keyword(Keyword::TABLE) {
10521053
self.expect_keyword(Keyword::TABLE)?;
10531054
let rename_object_defs = self.parse_comma_separated(|parser| {
10541055
let old_name = parser.parse_object_name(false)?;
10551056
parser.expect_keyword(Keyword::TO)?;
10561057
let new_name = parser.parse_object_name(false)?;
10571058

1058-
Ok(RenameObjectDef { old_name, new_name })
1059+
Ok(RenameTable { old_name, new_name })
10591060
})?;
10601061
Ok(Statement::RenameTable(rename_object_defs))
10611062
} else {

tests/sqlparser_common.rs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4028,19 +4028,17 @@ fn parse_alter_table() {
40284028

40294029
#[test]
40304030
fn parse_rename_table() {
4031-
let dialects = all_dialects_where(|d| d.supports_rename_table());
4032-
4033-
match dialects.verified_stmt("RENAME TABLE `test`.`test1` TO `test_db`.`test2`") {
4031+
match verified_stmt("RENAME TABLE test.test1 TO test_db.test2") {
40344032
Statement::RenameTable(rename_object_defs) => {
40354033
assert_eq!(
4036-
vec![RenameObjectDef {
4034+
vec![RenameTable {
40374035
old_name: ObjectName(vec![
4038-
Ident::with_quote('`', "test".to_string()),
4039-
Ident::with_quote('`', "test1".to_string()),
4036+
Ident::new("test".to_string()),
4037+
Ident::new("test1".to_string()),
40404038
]),
40414039
new_name: ObjectName(vec![
4042-
Ident::with_quote('`', "test_db".to_string()),
4043-
Ident::with_quote('`', "test2".to_string()),
4040+
Ident::new("test_db".to_string()),
4041+
Ident::new("test2".to_string()),
40444042
]),
40454043
}],
40464044
rename_object_defs
@@ -4049,21 +4047,21 @@ fn parse_rename_table() {
40494047
_ => unreachable!(),
40504048
};
40514049

4052-
match dialects.verified_stmt(
4050+
match verified_stmt(
40534051
"RENAME TABLE old_table1 TO new_table1, old_table2 TO new_table2, old_table3 TO new_table3",
40544052
) {
40554053
Statement::RenameTable(rename_object_defs) => {
40564054
assert_eq!(
40574055
vec![
4058-
RenameObjectDef {
4056+
RenameTable {
40594057
old_name: ObjectName(vec![Ident::new("old_table1".to_string())]),
40604058
new_name: ObjectName(vec![Ident::new("new_table1".to_string())]),
40614059
},
4062-
RenameObjectDef {
4060+
RenameTable {
40634061
old_name: ObjectName(vec![Ident::new("old_table2".to_string())]),
40644062
new_name: ObjectName(vec![Ident::new("new_table2".to_string())]),
40654063
},
4066-
RenameObjectDef {
4064+
RenameTable {
40674065
old_name: ObjectName(vec![Ident::new("old_table3".to_string())]),
40684066
new_name: ObjectName(vec![Ident::new("new_table3".to_string())]),
40694067
}
@@ -4075,31 +4073,16 @@ fn parse_rename_table() {
40754073
};
40764074

40774075
assert_eq!(
4078-
dialects
4079-
.parse_sql_statements("RENAME TABLE `old_table` TO new_table a")
4080-
.unwrap_err(),
4076+
parse_sql_statements("RENAME TABLE old_table TO new_table a").unwrap_err(),
40814077
ParserError::ParserError("Expected: end of statement, found: a".to_string())
40824078
);
40834079

40844080
assert_eq!(
4085-
dialects
4086-
.parse_sql_statements("RENAME TABLE1 `old_table` TO new_table a")
4087-
.unwrap_err(),
4081+
parse_sql_statements("RENAME TABLE1 old_table TO new_table a").unwrap_err(),
40884082
ParserError::ParserError(
40894083
"Expected: KEYWORD `TABLE` after RENAME, found: TABLE1".to_string()
40904084
)
40914085
);
4092-
4093-
let dialects = all_dialects_where(|d| !d.supports_rename_table());
4094-
4095-
assert_eq!(
4096-
dialects
4097-
.parse_sql_statements("RENAME TABLE `old_table` TO new_table")
4098-
.unwrap_err(),
4099-
ParserError::ParserError(
4100-
"Expected: KEYWORD `TABLE` after RENAME, found: TABLE".to_string()
4101-
)
4102-
);
41034086
}
41044087

41054088
#[test]

0 commit comments

Comments
 (0)