-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/net/sf/jsqlparser/statement/values/ValuesStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* #%L | ||
* JSQLParser library | ||
* %% | ||
* Copyright (C) 2004 - 2013 JSQLParser | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 2.1 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Lesser Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Lesser Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
* #L% | ||
*/ | ||
package net.sf.jsqlparser.statement.values; | ||
|
||
import java.util.List; | ||
import net.sf.jsqlparser.expression.Expression; | ||
import net.sf.jsqlparser.statement.Statement; | ||
import net.sf.jsqlparser.statement.StatementVisitor; | ||
import net.sf.jsqlparser.statement.select.PlainSelect; | ||
|
||
/** | ||
* The replace statement. | ||
*/ | ||
public class ValuesStatement implements Statement { | ||
|
||
private List<Expression> expressions; | ||
|
||
public ValuesStatement(List<Expression> expressions) { | ||
this.expressions = expressions; | ||
} | ||
|
||
@Override | ||
public void accept(StatementVisitor statementVisitor) { | ||
statementVisitor.visit(this); | ||
} | ||
|
||
public List<Expression> getExpressions() { | ||
return expressions; | ||
} | ||
|
||
public void setExpressions(List<Expression> list) { | ||
expressions = list; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sql = new StringBuilder(); | ||
sql.append("VALUES "); | ||
sql.append(PlainSelect.getStringList(expressions, true, true)); | ||
return sql.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/net/sf/jsqlparser/util/deparser/ValuesStatementDeParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* #%L | ||
* JSQLParser library | ||
* %% | ||
* Copyright (C) 2004 - 2017 JSQLParser | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 2.1 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Lesser Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Lesser Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
* #L% | ||
*/ | ||
package net.sf.jsqlparser.util.deparser; | ||
|
||
import net.sf.jsqlparser.expression.Expression; | ||
import net.sf.jsqlparser.expression.ExpressionVisitor; | ||
import net.sf.jsqlparser.statement.values.ValuesStatement; | ||
|
||
public class ValuesStatementDeParser { | ||
|
||
private StringBuilder buffer; | ||
private final ExpressionVisitor expressionVisitor; | ||
|
||
public ValuesStatementDeParser(ExpressionVisitor expressionVisitor, StringBuilder buffer) { | ||
this.buffer = buffer; | ||
this.expressionVisitor = expressionVisitor; | ||
} | ||
|
||
public StringBuilder getBuffer() { | ||
return buffer; | ||
} | ||
|
||
public void setBuffer(StringBuilder buffer) { | ||
this.buffer = buffer; | ||
} | ||
|
||
public void deParse(ValuesStatement values) { | ||
boolean first = true; | ||
buffer.append("VALUES ("); | ||
for (Expression expr : values.getExpressions()) { | ||
if (first) { | ||
first = false; | ||
} else { | ||
buffer.append(", "); | ||
} | ||
expr.accept(expressionVisitor); | ||
} | ||
buffer.append(")"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/test/java/net/sf/jsqlparser/statement/values/ValuesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package net.sf.jsqlparser.statement.values; | ||
|
||
import net.sf.jsqlparser.JSQLParserException; | ||
import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; | ||
import org.junit.Test; | ||
|
||
public class ValuesTest { | ||
|
||
@Test | ||
public void testDuplicateKey() throws JSQLParserException { | ||
assertSqlCanBeParsedAndDeparsed("VALUES (1, 2, 'test')"); | ||
} | ||
} |