Skip to content

Commit 07b8676

Browse files
PraTrickwumpz
authored andcommitted
Added support for comment(s) for column definitions in CREATE TABLE s… (#743)
* Added support for comment(s) for column definitions in CREATE TABLE statements * Added support for comment(s) for column definitions in CREATE TABLE statements #2 * To increase code coverage * To increase code coverage #2
1 parent cb0e0b7 commit 07b8676

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/main/java/net/sf/jsqlparser/schema/Table.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,18 @@ public Table() {
5151
}
5252

5353
public Table(String name) {
54-
setIndex(NAME_IDX, name);
54+
setName(name);
5555
}
5656

5757
public Table(String schemaName, String name) {
58-
setIndex(NAME_IDX, name);
59-
setIndex(SCHEMA_IDX, schemaName);
58+
setName(name);
59+
setSchemaName(schemaName);
6060
}
6161

6262
public Table(Database database, String schemaName, String name) {
63-
setIndex(NAME_IDX, name);
64-
setIndex(SCHEMA_IDX, schemaName);
65-
setIndex(DATABASE_IDX, database.getDatabaseName());
66-
setIndex(SERVER_IDX, database.getServer().getFullyQualifiedName());
63+
setName(name);
64+
setSchemaName(schemaName);
65+
setDatabase(database);
6766
}
6867

6968
public Table(List<String> partItems) {
@@ -77,6 +76,7 @@ public Database getDatabase() {
7776

7877
public void setDatabase(Database database) {
7978
setIndex(DATABASE_IDX, database.getDatabaseName());
79+
setIndex(SERVER_IDX, database.getServer().getFullyQualifiedName());
8080
}
8181

8282
public String getSchemaName() {
@@ -173,3 +173,4 @@ public String toString() {
173173
+ ((hint != null) ? hint.toString() : "");
174174
}
175175
}
176+

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3584,6 +3584,8 @@ List<String> CreateParameter():
35843584
tk=<K_IN> { param.add(tk.image); }
35853585
|
35863586
tk=<K_TYPE> { param.add(tk.image); }
3587+
|
3588+
tk=<K_COMMENT> { param.add(tk.image); }
35873589
)
35883590
{return param;}
35893591
}

src/test/java/net/sf/jsqlparser/parser/CCJSqlParserUtilTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,17 @@ public void testParseStatementsIssue691_2() throws Exception {
128128
+ "---test");
129129
assertEquals("SELECT * FROM dual;\n", result.toString());
130130
}
131+
132+
@Test
133+
public void testParseStatementIssue742() throws Exception {
134+
Statements result = CCJSqlParserUtil.parseStatements("CREATE TABLE `table_name` (\n" +
135+
" `id` bigint(20) NOT NULL AUTO_INCREMENT,\n" +
136+
" `another_column_id` bigint(20) NOT NULL COMMENT 'column id as sent by SYSTEM',\n" +
137+
" PRIMARY KEY (`id`),\n" +
138+
" UNIQUE KEY `uk_another_column_id` (`another_column_id`)\n" +
139+
")");
140+
assertEquals("CREATE TABLE `table_name` (`id` bigint (20) NOT NULL AUTO_INCREMENT, `another_column_id` " +
141+
"bigint (20) NOT NULL COMMENT 'column id as sent by SYSTEM', PRIMARY KEY (`id`), UNIQUE KEY `uk_another_column_id` " +
142+
"(`another_column_id`));\n", result.toString());
143+
}
131144
}

0 commit comments

Comments
 (0)