Skip to content

Commit 23c19a5

Browse files
committed
Fix inline usage of foreign keys in CREATE TABLE statements
1 parent 978b60e commit 23c19a5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,6 +2522,10 @@ String CreateParameter():
25222522
tk=<K_NOT> { retval = tk.image; }
25232523
|
25242524
tk=<K_PRIMARY> { retval = tk.image; }
2525+
|
2526+
tk=<K_FOREIGN> { retval=tk.image; }
2527+
|
2528+
tk=<K_REFERENCES> { retval=tk.image; }
25252529
|
25262530
tk=<K_KEY> { retval = tk.image; }
25272531
|

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ public void testCreateTableForeignKey2() throws JSQLParserException {
8686
String statement = "CREATE TABLE test (id INT UNSIGNED NOT NULL AUTO_INCREMENT, string VARCHAR (20), user_id INT UNSIGNED, PRIMARY KEY (id), CONSTRAINT fkIdx FOREIGN KEY (user_id) REFERENCES ra_user(id))";
8787
assertSqlCanBeParsedAndDeparsed(statement);
8888
}
89+
90+
public void testCreateTableForeignKey3() throws JSQLParserException {
91+
String statement = "CREATE TABLE test (id INT UNSIGNED NOT NULL AUTO_INCREMENT, string VARCHAR (20), user_id INT UNSIGNED REFERENCES ra_user(id), PRIMARY KEY (id))";
92+
assertSqlCanBeParsedAndDeparsed(statement,true);
93+
}
94+
95+
public void testCreateTableForeignKey4() throws JSQLParserException {
96+
String statement = "CREATE TABLE test (id INT UNSIGNED NOT NULL AUTO_INCREMENT, string VARCHAR (20), user_id INT UNSIGNED FOREIGN KEY REFERENCES ra_user(id), PRIMARY KEY (id))";
97+
assertSqlCanBeParsedAndDeparsed(statement,true);
98+
}
8999

90100
public void testCreateTablePrimaryKey() throws JSQLParserException {
91101
String statement = "CREATE TABLE test (id INT UNSIGNED NOT NULL AUTO_INCREMENT, string VARCHAR (20), user_id INT UNSIGNED, CONSTRAINT pk_name PRIMARY KEY (id))";

0 commit comments

Comments
 (0)