Skip to content

Commit ba4b0cc

Browse files
committed
finished multi value set
1 parent d991bbe commit ba4b0cc

File tree

3 files changed

+56
-34
lines changed

3 files changed

+56
-34
lines changed

src/main/java/net/sf/jsqlparser/statement/SetStatement.java

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* JSQLParser library
44
* %%
5-
* Copyright (C) 2004 - 2015 JSQLParser
5+
* Copyright (C) 2004 - 2019 JSQLParser
66
* %%
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU Lesser General Public License as
@@ -19,24 +19,6 @@
1919
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
2020
* #L%
2121
*/
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-
*/
4022
package net.sf.jsqlparser.statement;
4123

4224
import java.util.ArrayList;
@@ -59,33 +41,65 @@ public void add(String name, Expression expression, boolean useEqual) {
5941
values.add(new NameExpr(name, expression, useEqual));
6042
}
6143

44+
public void remove(int idx) {
45+
values.remove(idx);
46+
}
47+
48+
public int getCount() {
49+
return values.size();
50+
}
51+
52+
public boolean isUseEqual(int idx) {
53+
return values.get(idx).useEqual;
54+
}
55+
6256
public boolean isUseEqual() {
63-
return values.get(0).useEqual;
57+
return isUseEqual(0);
6458
}
6559

66-
public SetStatement setUseEqual(boolean useEqual) {
67-
values.get(0).useEqual = useEqual;
60+
public SetStatement setUseEqual(int idx, boolean useEqual) {
61+
values.get(idx).useEqual = useEqual;
6862
return this;
6963
}
7064

65+
public SetStatement setUseEqual(boolean useEqual) {
66+
return setUseEqual(0, useEqual);
67+
}
68+
7169
public String getName() {
72-
return values.get(0).name;
70+
return getName(0);
71+
}
72+
73+
public String getName(int idx) {
74+
return values.get(idx).name;
7375
}
7476

7577
public void setName(String name) {
76-
values.get(0).name = name;
78+
setName(0, name);
79+
}
80+
81+
public void setName(int idx, String name) {
82+
values.get(idx).name = name;
83+
}
84+
85+
public Expression getExpression(int idx) {
86+
return values.get(idx).expression;
7787
}
7888

7989
public Expression getExpression() {
80-
return values.get(0).expression;
90+
return getExpression(0);
91+
}
92+
93+
public void setExpression(int idx, Expression expression) {
94+
values.get(idx).expression = expression;
8195
}
8296

8397
public void setExpression(Expression expression) {
84-
values.get(0).expression = expression;
98+
setExpression(0, expression);
8599
}
86100

87101
private String toString(NameExpr ne) {
88-
return "SET " + ne.name + (ne.useEqual ? " = " : " ") + ne.expression.toString();
102+
return ne.name + (ne.useEqual ? " = " : " ") + ne.expression.toString();
89103
}
90104

91105
@Override

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* JSQLParser library
44
* %%
5-
* Copyright (C) 2004 - 2015 JSQLParser
5+
* Copyright (C) 2004 - 2019 JSQLParser
66
* %%
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU Lesser General Public License as
@@ -49,12 +49,20 @@ public void setBuffer(StringBuilder buffer) {
4949
}
5050

5151
public void deParse(SetStatement set) {
52-
buffer.append("SET ").append(set.getName());
53-
if (set.isUseEqual()) {
54-
buffer.append(" =");
52+
buffer.append("SET ");
53+
54+
for (int i = 0; i < set.getCount(); i++) {
55+
if (i > 0) {
56+
buffer.append(", ");
57+
}
58+
buffer.append(set.getName(i));
59+
if (set.isUseEqual(i)) {
60+
buffer.append(" =");
61+
}
62+
buffer.append(" ");
63+
set.getExpression(i).accept(expressionVisitor);
5564
}
56-
buffer.append(" ");
57-
set.getExpression().accept(expressionVisitor);
65+
5866
}
5967

6068
public ExpressionVisitor getExpressionVisitor() {

src/test/java/net/sf/jsqlparser/statement/SetStatementTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ public void testIssue373_2() throws JSQLParserException {
4545

4646
@Test
4747
public void testMultiValue() throws JSQLParserException {
48-
assertSqlCanBeParsedAndDeparsed("SET v=1, c=3");
48+
assertSqlCanBeParsedAndDeparsed("SET v = 1, c = 3");
4949
}
5050
}

0 commit comments

Comments
 (0)