Skip to content

Commit 6227b0b

Browse files
committed
fix convert toString
1 parent fee2f90 commit 6227b0b

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/main/java/net/sf/jsqlparser/statement/alter/AlterExpression.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public boolean isOnDeleteCascade() {
196196
/**
197197
* @param onDeleteCascade
198198
* @deprecated use
199-
* {@link #setReferentialAction(ReferentialAction.Type, ReferentialAction.Action, boolean)}
199+
* {@link #setReferentialAction(ReferentialAction.Type, ReferentialAction.Action, boolean)}
200200
*/
201201
@Deprecated
202202
public void setOnDeleteCascade(boolean onDeleteCascade) {
@@ -216,7 +216,7 @@ public boolean isOnDeleteRestrict() {
216216
/**
217217
* @param onDeleteRestrict
218218
* @deprecated use
219-
* {@link #setReferentialAction(ReferentialAction.Type, ReferentialAction.Action, boolean)}
219+
* {@link #setReferentialAction(ReferentialAction.Type, ReferentialAction.Action, boolean)}
220220
*/
221221
@Deprecated
222222
public void setOnDeleteRestrict(boolean onDeleteRestrict) {
@@ -236,7 +236,7 @@ public boolean isOnDeleteSetNull() {
236236
/**
237237
* @param onDeleteSetNull
238238
* @deprecated use
239-
* {@link #setReferentialAction(ReferentialAction.Type, ReferentialAction.Action, boolean)}
239+
* {@link #setReferentialAction(ReferentialAction.Type, ReferentialAction.Action, boolean)}
240240
*/
241241
@Deprecated
242242
public void setOnDeleteSetNull(boolean onDeleteSetNull) {
@@ -485,6 +485,14 @@ public String toString() {
485485
} else if (operation == AlterOperation.DROP_PRIMARY_KEY) {
486486

487487
b.append("DROP PRIMARY KEY ");
488+
} else if (operation == AlterOperation.CONVERT) {
489+
b.append("CONVERT TO CHARACTER SET ");
490+
if (getCharacterSet() != null) {
491+
b.append(getCharacterSet());
492+
}
493+
if (getCollation() != null) {
494+
b.append(" COLLATE ").append(getCollation());
495+
}
488496
} else if (operation == AlterOperation.DROP_UNIQUE) {
489497

490498
b.append("DROP UNIQUE (").append(PlainSelect.getStringList(pkColumns)).append(')');

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.List;
3131

3232
import static net.sf.jsqlparser.test.TestUtils.*;
33-
import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed;
3433
import static org.junit.jupiter.api.Assertions.*;
3534

3635
public class AlterTest {
@@ -835,7 +834,7 @@ public void testAlterTableDefaultValueTrueIssue926() throws JSQLParserException
835834
}
836835

837836
private void assertReferentialActionOnConstraint(Alter parsed, Action onUpdate,
838-
Action onDelete) {
837+
Action onDelete) {
839838
AlterExpression alterExpression = parsed.getAlterExpressions().get(0);
840839
ForeignKeyIndex index = (ForeignKeyIndex) alterExpression.getIndex();
841840

@@ -1112,7 +1111,7 @@ public void testIssue2089() throws JSQLParserException {
11121111
}
11131112

11141113
@Test
1115-
public void testIssue2089WithCollation() throws JSQLParserException {
1114+
public void testIssue2089ConvertWithCollation() throws JSQLParserException {
11161115
String sql =
11171116
"ALTER TABLE test_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci";
11181117
Statement stmt = CCJSqlParserUtil.parse(sql);
@@ -1128,6 +1127,8 @@ public void testIssue2089WithCollation() throws JSQLParserException {
11281127
assertEquals(AlterOperation.CONVERT, convertExp.getOperation());
11291128
assertEquals("utf8mb4", convertExp.getCharacterSet());
11301129
assertEquals("utf8mb4_general_ci", convertExp.getCollation());
1130+
1131+
assertSqlCanBeParsedAndDeparsed(sql);
11311132
}
11321133

11331134
@Test

0 commit comments

Comments
 (0)