Skip to content

Commit e902a41

Browse files
committed
fixes #92
1 parent 32bf3a2 commit e902a41

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/main/javacc/net/sf/jsqlparser/parser/JSqlParserCC.jj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
205205
| <K_NEXT:"NEXT">
206206
| <K_ONLY:"ONLY">
207207
| <K_COMMIT:"COMMIT">
208+
| <K_UNIQUE:"UNIQUE">
208209
}
209210

210211
TOKEN : /* Numeric Constants */
@@ -2190,10 +2191,12 @@ CreateTable CreateTable():
21902191
index = new NamedConstraint();
21912192
}
21922193
[<K_CONSTRAINT> tk3=<S_IDENTIFIER> {index.setName(tk3.image);} ]
2193-
tk=<K_PRIMARY> tk2=<K_KEY>
2194+
2195+
(tk=<K_PRIMARY> tk2=<K_KEY> {index.setType(tk.image + " " + tk2.image);}
2196+
| tk=<K_UNIQUE> {index.setType(tk.image);} )
21942197
colNames=ColumnsNamesList()
21952198
{
2196-
index.setType(tk.image + " " + tk2.image);
2199+
21972200
index.setColumnsNames(colNames);
21982201
indexes.add(index);
21992202
}
@@ -2348,6 +2351,8 @@ String CreateParameter():
23482351
tk=<K_COMMIT> { retval = tk.image; }
23492352
|
23502353
tk=<K_ROWS> { retval = tk.image; }
2354+
|
2355+
tk=<K_UNIQUE> { retval = tk.image; }
23512356
|
23522357
"=" { retval = "="; }
23532358
|

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public void testCreateTablePrimaryKey() throws JSQLParserException {
9595
public void testCreateTableParams() throws JSQLParserException {
9696
assertSqlCanBeParsedAndDeparsed("CREATE TEMPORARY TABLE T1 (PROCESSID VARCHAR (32)) ON COMMIT PRESERVE ROWS");
9797
}
98+
99+
public void testCreateTableUniqueConstraint() throws JSQLParserException {
100+
assertSqlCanBeParsedAndDeparsed("CREATE TABLE Activities (_id INTEGER PRIMARY KEY AUTOINCREMENT,uuid VARCHAR(255),user_id INTEGER,sound_id INTEGER,sound_type INTEGER,comment_id INTEGER,type String,tags VARCHAR(255),created_at INTEGER,content_id INTEGER,sharing_note_text VARCHAR(255),sharing_note_created_at INTEGER,UNIQUE (created_at, type, content_id, sound_id, user_id))", true);
101+
}
98102

99103
public void testRUBiSCreateList() throws Exception {
100104
BufferedReader in = new BufferedReader(new InputStreamReader(CreateTableTest.class.getResourceAsStream("/RUBiS-create-requests.txt")));
@@ -190,7 +194,7 @@ public void testRUBiSCreateList() throws Exception {
190194

191195
}
192196
} catch (Exception e) {
193-
throw new TestException("error at stm num: " + numSt, e);
197+
throw new TestException("error at stm num: " + numSt + " " + query, e);
194198
}
195199
numSt++;
196200

src/test/java/net/sf/jsqlparser/test/select/SpecialOracleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void testAllSqlsParseDeparse() throws IOException {
6868
}
6969

7070
LOG.log(Level.INFO, "tested {0} files. got {1} correct parse results", new Object[]{count, success});
71-
assertTrue(success>=106);
71+
assertTrue(success>=109);
7272
}
7373

7474
@Test

0 commit comments

Comments
 (0)