Skip to content

Commit 27cdfa9

Browse files
authored
Support table option character set and index options (#1586)
* Support table option character set and index options Signed-off-by: luofei <luoffei@outlook.com> * move test Signed-off-by: luofei <luoffei@outlook.com>
1 parent afbaf53 commit 27cdfa9

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5014,8 +5014,10 @@ CreateTable CreateTable():
50145014
sk3=RelObjectName()
50155015
/* colNames=ColumnsNamesList() */
50165016
colNames = ColumnNamesWithParamsList()
5017+
{ idxSpec.clear(); }
5018+
( parameter=CreateParameter() { idxSpec.addAll(parameter); } )*
50175019
{
5018-
index = new Index().withType(tk.image).withName(sk3).withColumns(colNames);
5020+
index = new Index().withType(tk.image).withName(sk3).withColumns(colNames).withIndexSpec(idxSpec);
50195021
indexes.add(index);
50205022
}
50215023
)
@@ -5031,6 +5033,7 @@ CreateTable CreateTable():
50315033
)
50325034
/* colNames=ColumnsNamesList() */
50335035
colNames = ColumnNamesWithParamsList()
5036+
{ idxSpec.clear(); }
50345037
( parameter=CreateParameter() { idxSpec.addAll(parameter); } )*
50355038
{
50365039
index.withColumns(colNames).withIndexSpec(idxSpec);
@@ -5047,6 +5050,7 @@ CreateTable CreateTable():
50475050
sk3=RelObjectName()
50485051
/* colNames=ColumnsNamesList() */
50495052
colNames = ColumnNamesWithParamsList()
5053+
{ idxSpec.clear(); }
50505054
( parameter=CreateParameter() { idxSpec.addAll(parameter); } )*
50515055
{
50525056
index = new Index()
@@ -5364,6 +5368,8 @@ List<String> CreateParameter():
53645368
|
53655369
tk=<K_BINARY> { param.add(tk.image); }
53665370
|
5371+
(tk=<K_CHARACTER> tk2=<K_SET>) { param.add(tk.image); param.add(tk2.image);}
5372+
|
53675373
(<K_ARRAY_LITERAL> exp=ArrayConstructor(true)) { param.add(exp.toString()); }
53685374
|
53695375
tk="::" colDataType = ColDataType() { param.add(tk.image); param.add(colDataType.toString()); }

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,4 +861,34 @@ public void testCreateUnionIssue1309() throws JSQLParserException {
861861
public void testCreateTableBinaryIssue1518() throws JSQLParserException {
862862
assertSqlCanBeParsedAndDeparsed("CREATE TABLE `s` (`a` enum ('a', 'b', 'c') CHARACTER SET binary COLLATE binary)");
863863
}
864+
865+
@Test
866+
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);
893+
}
864894
}

0 commit comments

Comments
 (0)