Skip to content

Commit 60d6483

Browse files
committed
fixes #1596
1 parent b392733 commit 60d6483

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5150,7 +5150,7 @@ CreateTable CreateTable():
51505150
{ idxSpec.clear(); }
51515151
( parameter=CreateParameter() { idxSpec.addAll(parameter); } )*
51525152
{
5153-
index = new Index().withType(tk.image).withName(sk3).withColumns(colNames).withIndexSpec(idxSpec);
5153+
index = new Index().withType(tk.image).withName(sk3).withColumns(colNames).withIndexSpec(new ArrayList<String>(idxSpec));
51545154
indexes.add(index);
51555155
}
51565156
)
@@ -5169,7 +5169,7 @@ CreateTable CreateTable():
51695169
{ idxSpec.clear(); }
51705170
( parameter=CreateParameter() { idxSpec.addAll(parameter); } )*
51715171
{
5172-
index.withColumns(colNames).withIndexSpec(idxSpec);
5172+
index.withColumns(colNames).withIndexSpec(new ArrayList<String>(idxSpec));
51735173
indexes.add(index);
51745174
}
51755175
// reset Token to null forcefullly
@@ -5190,7 +5190,7 @@ CreateTable CreateTable():
51905190
.withType((tk!=null?tk.image + " ":"") + (tk3!=null?tk3.image + " ":"") + tk2.image)
51915191
.withName(sk3)
51925192
.withColumns(colNames)
5193-
.withIndexSpec(idxSpec);
5193+
.withIndexSpec(new ArrayList<String>(idxSpec));
51945194
indexes.add(index);
51955195
}
51965196
)

src/test/java/net/sf/jsqlparser/statement/create/CreateTableTest.java

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -864,31 +864,45 @@ public void testCreateTableBinaryIssue1518() throws JSQLParserException {
864864

865865
@Test
866866
public void testCreateTableIssue1488() throws JSQLParserException {
867-
assertSqlCanBeParsedAndDeparsed("CREATE TABLE u_call_record (\n" +
868-
"card_user_id int(11) NOT NULL,\n" +
869-
"device_id int(11) NOT NULL,\n" +
870-
"call_start_at int(11) NOT NULL DEFAULT CURRENT_TIMESTAMP(11),\n" +
871-
"card_user_name varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n" +
872-
"sim_id varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n" +
873-
"called_number varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n" +
874-
"called_nickname varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n" +
875-
"talk_time smallint(8) NULL DEFAULT NULL,\n" +
876-
"area_name varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n" +
877-
"area_service_id int(11) NULL DEFAULT NULL,\n" +
878-
"operator_id int(4) NULL DEFAULT NULL,\n" +
879-
"status tinyint(4) NULL DEFAULT NULL,\n" +
880-
"create_at timestamp NULL DEFAULT NULL,\n" +
881-
"place_user varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n" +
882-
"PRIMARY KEY (card_user_id, device_id, call_start_at) USING BTREE,\n" +
883-
"INDEX ucr_index_area_name(area_name) USING BTREE,\n" +
884-
"INDEX ucr_index_area_service_id(area_service_id) USING BTREE,\n" +
885-
"INDEX ucr_index_called_number(called_number) USING BTREE,\n" +
886-
"INDEX ucr_index_create_at(create_at) USING BTREE,\n" +
887-
"INDEX ucr_index_operator_id(operator_id) USING BTREE,\n" +
888-
"INDEX ucr_index_place_user(place_user) USING BTREE,\n" +
889-
"INDEX ucr_index_sim_id(sim_id) USING BTREE,\n" +
890-
"INDEX ucr_index_status(status) USING BTREE,\n" +
891-
"INDEX ucr_index_talk_time(talk_time) USING BTREE\n" +
892-
") ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic", true);
867+
assertSqlCanBeParsedAndDeparsed("CREATE TABLE u_call_record (\n"
868+
+ "card_user_id int(11) NOT NULL,\n"
869+
+ "device_id int(11) NOT NULL,\n"
870+
+ "call_start_at int(11) NOT NULL DEFAULT CURRENT_TIMESTAMP(11),\n"
871+
+ "card_user_name varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n"
872+
+ "sim_id varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n"
873+
+ "called_number varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n"
874+
+ "called_nickname varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n"
875+
+ "talk_time smallint(8) NULL DEFAULT NULL,\n"
876+
+ "area_name varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n"
877+
+ "area_service_id int(11) NULL DEFAULT NULL,\n"
878+
+ "operator_id int(4) NULL DEFAULT NULL,\n"
879+
+ "status tinyint(4) NULL DEFAULT NULL,\n"
880+
+ "create_at timestamp NULL DEFAULT NULL,\n"
881+
+ "place_user varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n"
882+
+ "PRIMARY KEY (card_user_id, device_id, call_start_at) USING BTREE,\n"
883+
+ "INDEX ucr_index_area_name(area_name) USING BTREE,\n"
884+
+ "INDEX ucr_index_area_service_id(area_service_id) USING BTREE,\n"
885+
+ "INDEX ucr_index_called_number(called_number) USING BTREE,\n"
886+
+ "INDEX ucr_index_create_at(create_at) USING BTREE,\n"
887+
+ "INDEX ucr_index_operator_id(operator_id) USING BTREE,\n"
888+
+ "INDEX ucr_index_place_user(place_user) USING BTREE,\n"
889+
+ "INDEX ucr_index_sim_id(sim_id) USING BTREE,\n"
890+
+ "INDEX ucr_index_status(status) USING BTREE,\n"
891+
+ "INDEX ucr_index_talk_time(talk_time) USING BTREE\n"
892+
+ ") ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic", true);
893+
}
894+
895+
@Test
896+
public void testCreateTableBinaryIssue1596() throws JSQLParserException {
897+
assertSqlCanBeParsedAndDeparsed("CREATE TABLE student2 ("
898+
+ "id int (10) NOT NULL COMMENT 'ID', "
899+
+ "name varchar (20) COLLATE utf8mb4_bin DEFAULT NULL, "
900+
+ "birth year (4) DEFAULT NULL, "
901+
+ "department varchar (20) COLLATE utf8mb4_bin DEFAULT NULL, "
902+
+ "address varchar (50) COLLATE utf8mb4_bin DEFAULT NULL, "
903+
+ "PRIMARY KEY (id), "
904+
+ "UNIQUE KEY id (id), "
905+
+ "INDEX name (name) USING BTREE"
906+
+ ") ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_bin");
893907
}
894908
}

0 commit comments

Comments
 (0)