Skip to content

Commit

Permalink
Fix: mysql comment with = (#1936)
Browse files Browse the repository at this point in the history
* Fix: mysql comment with `=`

* Fix: mysql comment with `=`
  • Loading branch information
jxnu-liguobin authored Dec 26, 2023
1 parent 256a1ef commit 0244905
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,11 @@ public String toString() {
// Oracle Multi Column Drop
b.append("DROP (").append(PlainSelect.getStringList(pkColumns)).append(')');
} else {
b.append(operation).append(" ");

if (operation == AlterOperation.COMMENT_WITH_EQUAL_SIGN) {
b.append("COMMENT =").append(" ");
} else {
b.append(operation).append(" ");
}
if (commentText != null) {
if (columnName != null) {
b.append(columnName).append(" COMMENT ");
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_KEY, 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, COMMENT_WITH_EQUAL_SIGN, UNSPECIFIC;

public static AlterOperation from(String operation) {
return Enum.valueOf(AlterOperation.class, operation.toUpperCase());
Expand Down
1 change: 1 addition & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -6500,6 +6500,7 @@ AlterExpression AlterExpression():
)
|
(<K_COMMENT> {alterExp.setOperation(AlterOperation.COMMENT);}
["=" {alterExp.setOperation(AlterOperation.COMMENT_WITH_EQUAL_SIGN);} ]
tk=<S_CHAR_LITERAL> { alterExp.setCommentText(tk.image); }
)
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,12 @@ public void testAlterTableDropColumnIfExists() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("ALTER TABLE test DROP COLUMN IF EXISTS name");
}

@Test
public void testAlterTableCommentIssue1935() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("ALTER TABLE table_name COMMENT = 'New table comment'");
assertSqlCanBeParsedAndDeparsed("ALTER TABLE table_name COMMENT 'New table comment'");
}

@Test
public void testAlterTableDropMultipleColumnsIfExists() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
Expand Down

0 comments on commit 0244905

Please sign in to comment.