Skip to content

Commit 763e92d

Browse files
authored
Fix alter table index descending (#2387)
1 parent d33d61a commit 763e92d

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
@@ -9621,11 +9621,13 @@ String AList():
96219621
String ColumnsNamesListItem():
96229622
{
96239623
Token tk = null;
9624+
Token sortDirection = null;
96249625
String item = null;
96259626
}
96269627
{
96279628
( item = RelObjectName() )
96289629
[ LOOKAHEAD(2) "(" tk = <S_LONG> ")" { item = item + "(" + tk.image + ")"; } ]
9630+
[ (sortDirection = <K_ASC> | sortDirection = <K_DESC>) { item = item + " " + sortDirection.image; } ]
96299631
{
96309632
return item;
96319633
}

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)