Skip to content

Commit

Permalink
fix bug: parse error 'alter table t1 rename to/as t2'
Browse files Browse the repository at this point in the history
  • Loading branch information
yakolee committed Mar 3, 2014
1 parent 7f687a1 commit dcbdac3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,9 @@ public SQLStatement parseAlter() {
}
} else if (identifierEquals("RENAME")) {
lexer.nextToken();
if (lexer.token() == Token.TO || lexer.token() == Token.AS) {
lexer.nextToken();
}
MySqlRenameTableStatement renameStmt = new MySqlRenameTableStatement();
MySqlRenameTableStatement.Item item = new MySqlRenameTableStatement.Item();
item.setName(stmt.getTableSource().getExpr());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,23 @@ public void test_alter_2() throws Exception {
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("ALTER TABLE t2\n\tADD INDEX (d),\n\tADD UNIQUE INDEX (a)", output);
}

public void test_alter_3() throws Exception {
String sql = "ALTER TABLE t1 RENAME TO t2;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("RENAME TABLE t1 TO t2", output);
}

public void test_alter_4() throws Exception {
String sql = "ALTER TABLE t1 RENAME AS t2;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("RENAME TABLE t1 TO t2", output);
}

}

0 comments on commit dcbdac3

Please sign in to comment.