Skip to content

Support table option character set and index options #1586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -4988,8 +4988,10 @@ CreateTable CreateTable():
sk3=RelObjectName()
/* colNames=ColumnsNamesList() */
colNames = ColumnNamesWithParamsList()
{ idxSpec.clear(); }
( parameter=CreateParameter() { idxSpec.addAll(parameter); } )*
{
index = new Index().withType(tk.image).withName(sk3).withColumns(colNames);
index = new Index().withType(tk.image).withName(sk3).withColumns(colNames).withIndexSpec(idxSpec);
indexes.add(index);
}
)
Expand All @@ -5005,6 +5007,7 @@ CreateTable CreateTable():
)
/* colNames=ColumnsNamesList() */
colNames = ColumnNamesWithParamsList()
{ idxSpec.clear(); }
( parameter=CreateParameter() { idxSpec.addAll(parameter); } )*
{
index.withColumns(colNames).withIndexSpec(idxSpec);
Expand All @@ -5021,6 +5024,7 @@ CreateTable CreateTable():
sk3=RelObjectName()
/* colNames=ColumnsNamesList() */
colNames = ColumnNamesWithParamsList()
{ idxSpec.clear(); }
( parameter=CreateParameter() { idxSpec.addAll(parameter); } )*
{
index = new Index()
Expand Down Expand Up @@ -5338,6 +5342,8 @@ List<String> CreateParameter():
|
tk=<K_BINARY> { param.add(tk.image); }
|
(tk=<K_CHARACTER> tk2=<K_SET>) { param.add(tk.image); param.add(tk2.image);}
|
(<K_ARRAY_LITERAL> exp=ArrayConstructor(true)) { param.add(exp.toString()); }
|
tk="::" colDataType = ColDataType() { param.add(tk.image); param.add(colDataType.toString()); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,4 +861,34 @@ public void testCreateUnionIssue1309() throws JSQLParserException {
public void testCreateTableBinaryIssue1518() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE TABLE `s` (`a` enum ('a', 'b', 'c') CHARACTER SET binary COLLATE binary)");
}

@Test
public void testCreateTableIssue1488() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE TABLE u_call_record (\n" +
"card_user_id int(11) NOT NULL,\n" +
"device_id int(11) NOT NULL,\n" +
"call_start_at int(11) NOT NULL DEFAULT CURRENT_TIMESTAMP(11),\n" +
"card_user_name varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n" +
"sim_id varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n" +
"called_number varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n" +
"called_nickname varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n" +
"talk_time smallint(8) NULL DEFAULT NULL,\n" +
"area_name varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n" +
"area_service_id int(11) NULL DEFAULT NULL,\n" +
"operator_id int(4) NULL DEFAULT NULL,\n" +
"status tinyint(4) NULL DEFAULT NULL,\n" +
"create_at timestamp NULL DEFAULT NULL,\n" +
"place_user varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,\n" +
"PRIMARY KEY (card_user_id, device_id, call_start_at) USING BTREE,\n" +
"INDEX ucr_index_area_name(area_name) USING BTREE,\n" +
"INDEX ucr_index_area_service_id(area_service_id) USING BTREE,\n" +
"INDEX ucr_index_called_number(called_number) USING BTREE,\n" +
"INDEX ucr_index_create_at(create_at) USING BTREE,\n" +
"INDEX ucr_index_operator_id(operator_id) USING BTREE,\n" +
"INDEX ucr_index_place_user(place_user) USING BTREE,\n" +
"INDEX ucr_index_sim_id(sim_id) USING BTREE,\n" +
"INDEX ucr_index_status(status) USING BTREE,\n" +
"INDEX ucr_index_talk_time(talk_time) USING BTREE\n" +
") ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic", true);
}
}