Skip to content

Commit f43531b

Browse files
committed
Fix alter table index descending
1 parent 865a3bf commit f43531b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8731,11 +8731,13 @@ String AList():
87318731
String ColumnsNamesListItem():
87328732
{
87338733
Token tk = null;
8734+
Token sortDirection = null;
87348735
String item = null;
87358736
}
87368737
{
87378738
( item = RelObjectName() )
87388739
[ LOOKAHEAD(2) "(" tk = <S_LONG> ")" { item = item + "(" + tk.image + ")"; } ]
8740+
[ (sortDirection = <K_ASC> | sortDirection = <K_DESC>) { item = item + " " + sortDirection.image; } ]
87398741
{
87408742
return item;
87418743
}

src/test/java/net/sf/jsqlparser/statement/alter/AlterTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,17 @@ public void testAlterTableIndex586() throws Exception {
572572
+ "USING BTREE, ALGORITHM = INPLACE", result.toString());
573573
}
574574

575+
@Test
576+
public void testAlterTableDropAndAddUniqueIndexWithAscendingColumns() throws Exception {
577+
Statement result =
578+
CCJSqlParserUtil.parse("ALTER TABLE `wxp_dm`.`xqgl_req_report` "
579+
+ "DROP INDEX `index_name`, "
580+
+ "ADD UNIQUE INDEX `index_name`(`report_name` ASC) USING BTREE");
581+
assertEquals("ALTER TABLE `wxp_dm`.`xqgl_req_report` DROP INDEX `index_name`, "
582+
+ "ADD UNIQUE INDEX `index_name` (`report_name` ASC) USING BTREE",
583+
result.toString());
584+
}
585+
575586
@Test
576587
public void testIssue259() throws JSQLParserException {
577588
assertSqlCanBeParsedAndDeparsed(

0 commit comments

Comments
 (0)