Skip to content

Commit 5d7bdb9

Browse files
committed
fixes #193
1 parent a90c745 commit 5d7bdb9

File tree

6 files changed

+67
-8
lines changed

6 files changed

+67
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Also I would like to know about needed examples or documentation stuff.
3838

3939
## Extensions in the latest SNAPSHOT version 0.9.5
4040

41+
* support for **INSERT LOW_PRIORITY INTO**
4142
* support for **ORDER BY** and **LIMIT** in **UPDATE** and **DELETE** statements
4243

4344
~~~

src/main/java/net/sf/jsqlparser/statement/insert/Insert.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class Insert implements Statement {
4848
private boolean useDuplicate = false;
4949
private List<Column> duplicateUpdateColumns;
5050
private List<Expression> duplicateUpdateExpressionList;
51-
private String modifierPriority = null;
51+
private InsertModifierPriority modifierPriority = null;
5252
private boolean modifierIgnore = false;
5353

5454
private boolean returningAllColumns = false;
@@ -158,11 +158,11 @@ public void setDuplicateUpdateExpressionList(List<Expression> duplicateUpdateExp
158158
this.duplicateUpdateExpressionList = duplicateUpdateExpressionList;
159159
}
160160

161-
public String getModifierPriority() {
161+
public InsertModifierPriority getModifierPriority() {
162162
return modifierPriority;
163163
}
164164

165-
public void setModifierPriority(String modifierPriority) {
165+
public void setModifierPriority(InsertModifierPriority modifierPriority) {
166166
this.modifierPriority = modifierPriority;
167167
}
168168

@@ -180,7 +180,7 @@ public String toString() {
180180

181181
sql.append("INSERT ");
182182
if(modifierPriority != null){
183-
sql.append(modifierPriority + " ");
183+
sql.append(modifierPriority.name()).append(" ");
184184
}
185185
if(modifierIgnore){
186186
sql.append("IGNORE ");
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2015 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
/*
23+
* Copyright (C) 2015 JSQLParser.
24+
*
25+
* This library is free software; you can redistribute it and/or
26+
* modify it under the terms of the GNU Lesser General Public
27+
* License as published by the Free Software Foundation; either
28+
* version 2.1 of the License, or (at your option) any later version.
29+
*
30+
* This library is distributed in the hope that it will be useful,
31+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
32+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33+
* Lesser General Public License for more details.
34+
*
35+
* You should have received a copy of the GNU Lesser General Public
36+
* License along with this library; if not, write to the Free Software
37+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
38+
* MA 02110-1301 USA
39+
*/
40+
package net.sf.jsqlparser.statement.insert;
41+
42+
/**
43+
*
44+
* @author tw
45+
*/
46+
public enum InsertModifierPriority {
47+
LOW_PRIORITY, DELAYED, HIGH_PRIORITY, IGNORE
48+
}

src/main/java/net/sf/jsqlparser/util/deparser/InsertDeParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import net.sf.jsqlparser.expression.operators.relational.MultiExpressionList;
3131
import net.sf.jsqlparser.schema.Column;
3232
import net.sf.jsqlparser.statement.insert.Insert;
33+
import net.sf.jsqlparser.statement.insert.InsertModifierPriority;
3334
import net.sf.jsqlparser.statement.select.SelectExpressionItem;
3435
import net.sf.jsqlparser.statement.select.SelectVisitor;
3536
import net.sf.jsqlparser.statement.select.SubSelect;
@@ -76,7 +77,7 @@ public void setBuffer(StringBuilder buffer) {
7677
public void deParse(Insert insert) {
7778
buffer.append("INSERT ");
7879
if(insert.getModifierPriority() != null){
79-
buffer.append(insert.getModifierPriority() + " ");
80+
buffer.append(insert.getModifierPriority()).append(" ");
8081
}
8182
if(insert.isModifierIgnore()){
8283
buffer.append("IGNORE ");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,14 +472,14 @@ Insert Insert():
472472
List<Column> duplicateUpdateColumns = null;
473473
List<Expression> duplicateUpdateExpressionList = null;
474474
Token tk = null;
475-
String modifierPriority = null;
475+
InsertModifierPriority modifierPriority = null;
476476
boolean modifierIgnore = false;
477477
}
478478
{
479479
<K_INSERT>
480480
[(tk = <K_LOW_PRIORITY> | tk = <K_DELAYED> | tk = <K_HIGH_PRIORITY>)
481481
{if (tk!=null)
482-
modifierPriority = tk.image.toUpperCase();
482+
modifierPriority = InsertModifierPriority.valueOf(tk.image.toUpperCase());
483483
}]
484484
[<K_IGNORE>{ modifierIgnore = true; }]
485485
[<K_INTO>] table=Table()

src/test/java/net/sf/jsqlparser/test/insert/InsertTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,17 @@ public void testModifierIgnore() throws JSQLParserException {
159159
}
160160

161161
@Test
162-
public void testModifierPriority() throws JSQLParserException {
162+
public void testModifierPriority1() throws JSQLParserException {
163163
assertSqlCanBeParsedAndDeparsed("INSERT DELAYED INTO kvPair (value, key) VALUES (?, ?)");
164+
}
165+
166+
@Test
167+
public void testModifierPriority2() throws JSQLParserException {
164168
assertSqlCanBeParsedAndDeparsed("INSERT LOW_PRIORITY INTO kvPair (value, key) VALUES (?, ?)");
165169
}
170+
171+
@Test
172+
public void testModifierPriority3() throws JSQLParserException {
173+
assertSqlCanBeParsedAndDeparsed("INSERT HIGH_PRIORITY INTO kvPair (value, key) VALUES (?, ?)");
174+
}
166175
}

0 commit comments

Comments
 (0)