Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix
  • Loading branch information
jxnu-liguobin committed Dec 15, 2023
commit a88a351c6b26af959a2472e9a122c268ea15faaf
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public void setUk(boolean uk) {

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity",
"PMD.ExcessiveMethodLength"})
"PMD.ExcessiveMethodLength", "PMD.SwitchStmtsShouldHaveDefault"})
public String toString() {

StringBuilder b = new StringBuilder();
Expand All @@ -413,10 +413,16 @@ public String toString() {
b.append(optionalSpecifier);
} else if (getOldIndex() != null) {
b.append("RENAME");
if (operation == AlterOperation.RENAME_INDEX) {
b.append(" INDEX ");
} else if (operation == AlterOperation.RENAME_CONSTRAINT) {
b.append(" CONSTRAINT ");
switch (operation) {
case RENAME_KEY:
b.append(" KEY ");
break;
case RENAME_INDEX:
b.append(" INDEX ");
break;
case RENAME_CONSTRAINT:
b.append(" CONSTRAINT ");
break;
}
b.append(getOldIndex().getName()).append(" TO ").append(getIndex().getName());
} else if (operation == AlterOperation.RENAME_TABLE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
package net.sf.jsqlparser.statement.alter;

public enum AlterOperation {
ADD, ALTER, DROP, DROP_PRIMARY_KEY, DROP_UNIQUE, DROP_FOREIGN_KEY, MODIFY, CHANGE, ALGORITHM, RENAME, RENAME_TABLE, RENAME_INDEX, RENAME_CONSTRAINT, COMMENT, UNSPECIFIC;
ADD, ALTER, DROP, DROP_PRIMARY_KEY, DROP_UNIQUE, DROP_FOREIGN_KEY, MODIFY, CHANGE, ALGORITHM, RENAME, RENAME_TABLE, RENAME_INDEX, RENAME_KEY, RENAME_CONSTRAINT, COMMENT, UNSPECIFIC;

public static AlterOperation from(String operation) {
return Enum.valueOf(AlterOperation.class, operation.toUpperCase());
Expand Down
6 changes: 5 additions & 1 deletion src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -6469,7 +6469,11 @@ AlterExpression AlterExpression():
tk=<S_CHAR_LITERAL> { alterExp.setCommentText(tk.image); }
)
|
LOOKAHEAD(2)(<K_RENAME> ((<K_INDEX> | <K_KEY>) { alterExp.setOperation(AlterOperation.RENAME_INDEX); } | <K_CONSTRAINT> { alterExp.setOperation(AlterOperation.RENAME_CONSTRAINT); })
LOOKAHEAD(2)
(<K_RENAME> ((<K_INDEX> {alterExp.setOperation(AlterOperation.RENAME_INDEX);}
| <K_KEY> {alterExp.setOperation(AlterOperation.RENAME_KEY);})
| <K_CONSTRAINT> { alterExp.setOperation(AlterOperation.RENAME_CONSTRAINT); }
)
(tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER>){
alterExp.setOldIndex(new Index().withName(tk.image));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public void testAlterTableIssue1815() throws JSQLParserException {
// MySQL: see https://dev.mysql.com/doc/refman/8.0/en/alter-table.html
assertSqlCanBeParsedAndDeparsed(
"ALTER TABLE cers_record_10 RENAME INDEX idx_cers_record_1_gmtcreate TO idx_cers_record_10_gmtcreate");
assertSqlCanBeParsedAndDeparsed(
"ALTER TABLE cers_record_10 RENAME KEY k_cers_record_1_gmtcreate TO k_cers_record_10_gmtcreate");
// PostgreSQL: see https://www.postgresql.org/docs/current/sql-altertable.html
assertSqlCanBeParsedAndDeparsed(
"ALTER TABLE cers_record_10 RENAME CONSTRAINT cst_cers_record_1_gmtcreate TO cst_cers_record_10_gmtcreate");
Expand Down