Skip to content

Commit

Permalink
replace support multiple values
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghai committed Aug 21, 2017
1 parent 147ec48 commit 93598bb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ public void setSelectVisitor(SelectVisitor visitor) {

@Override
public void visit(MultiExpressionList multiExprList) {
throw new UnsupportedOperationException("Not supported yet.");
buffer.append("VALUES ");
for (Iterator<ExpressionList> it = multiExprList.getExprList().iterator(); it.hasNext();) {
buffer.append("(");
for (Iterator<Expression> iter = it.next().getExpressions().iterator(); iter.hasNext();) {
Expression expression = iter.next();
expression.accept(expressionVisitor);
if (iter.hasNext()) {
buffer.append(", ");
}
}
buffer.append(")");
if (it.hasNext()) {
buffer.append(", ");
}
}
}
}
10 changes: 10 additions & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ Replace Replace():

List<Column> columns = new ArrayList<Column>();
List<Expression> expList = new ArrayList<Expression>();
MultiExpressionList multiExpr = null;
ItemsList itemsList = null;
Expression exp = null;
}
Expand All @@ -549,6 +550,15 @@ Replace Replace():
(
LOOKAHEAD(2) [<K_VALUES> | <K_VALUE>] "(" exp=PrimaryExpression() { expList.add(exp); }
("," exp=PrimaryExpression() { expList.add(exp); } )* ")" { itemsList = new ExpressionList(expList); }
("," "(" exp=SimpleExpression() {
if (multiExpr==null) {
multiExpr=new MultiExpressionList();
multiExpr.addExpressionList((ExpressionList)itemsList);
itemsList = multiExpr;
}
expList = new ArrayList<Expression>();
expList.add(exp); }
("," exp=SimpleExpression() { expList.add(exp); } )* ")" { multiExpr.addExpressionList(expList); } )*
|
{ replace.setUseValues(false); }
itemsList=SubSelect()
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/net/sf/jsqlparser/test/replace/ReplaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ public void testProblemMissingIntoIssue389() throws JSQLParserException {
TestUtils.
assertSqlCanBeParsedAndDeparsed("REPLACE INTO mytable (key, data) VALUES (1, \"aaa\")");
}


@Test
public void testMultipleValues() throws JSQLParserException {
TestUtils.
assertSqlCanBeParsedAndDeparsed("REPLACE INTO mytable (col1, col2, col3) VALUES (1, \"aaa\", now()), (2, \"bbb\", now())");
}
}

0 comments on commit 93598bb

Please sign in to comment.