diff --git a/src/main/java/net/sf/jsqlparser/statement/merge/MergeUpdate.java b/src/main/java/net/sf/jsqlparser/statement/merge/MergeUpdate.java index 10df947e7..38e9261a2 100644 --- a/src/main/java/net/sf/jsqlparser/statement/merge/MergeUpdate.java +++ b/src/main/java/net/sf/jsqlparser/statement/merge/MergeUpdate.java @@ -22,8 +22,7 @@ public class MergeUpdate implements Serializable { private Expression whereCondition; private Expression deleteWhereCondition; - public MergeUpdate() { - } + public MergeUpdate() {} public MergeUpdate(List updateSets) { this.updateSets = updateSets; @@ -98,7 +97,7 @@ public MergeUpdate withDeleteWhereCondition(Expression deleteWhereCondition) { public E getAndPredicate(Class type) { return type.cast(getAndPredicate()); -} + } public E getWhereCondition(Class type) { return type.cast(getWhereCondition()); diff --git a/src/main/java/net/sf/jsqlparser/statement/update/UpdateSet.java b/src/main/java/net/sf/jsqlparser/statement/update/UpdateSet.java index 7c6fca540..84299c0fb 100644 --- a/src/main/java/net/sf/jsqlparser/statement/update/UpdateSet.java +++ b/src/main/java/net/sf/jsqlparser/statement/update/UpdateSet.java @@ -72,7 +72,7 @@ public void add(Column column, Expression value) { * @param column */ public void add(Column column) { - if (columns.size() < 2 && !(columns instanceof ParenthesedExpressionList)) { + if (!columns.isEmpty() && !(columns instanceof ParenthesedExpressionList)) { columns = new ParenthesedExpressionList<>(columns); } columns.add(column); @@ -85,7 +85,7 @@ public void add(Column column) { * @param expression */ public void add(Expression expression) { - if (values.size() < 2 && !(values instanceof ParenthesedExpressionList)) { + if (!values.isEmpty() && !(values instanceof ParenthesedExpressionList)) { values = new ParenthesedExpressionList<>(values); } values.add(expression); diff --git a/src/test/java/net/sf/jsqlparser/statement/merge/MergeTest.java b/src/test/java/net/sf/jsqlparser/statement/merge/MergeTest.java index 5034be8cd..edf0baa92 100644 --- a/src/test/java/net/sf/jsqlparser/statement/merge/MergeTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/merge/MergeTest.java @@ -257,9 +257,11 @@ public void testSnowflakeMergeStatementWithMatchedAndPredicate() throws JSQLPars @Test void testSnowflakeMergeStatementWithNotMatchedAndPredicate() throws JSQLParserException { - String sql = "MERGE INTO target USING (select k, max(v) as v from src group by k) AS b ON target.k = b.k\n" + - " WHEN MATCHED THEN UPDATE SET target.v = b.v\n" + - " WHEN NOT MATCHED AND b.v != 11 THEN INSERT (k, v) VALUES (b.k, b.v)"; + String sql = + "MERGE INTO target USING (select k, max(v) as v from src group by k) AS b ON target.k = b.k\n" + + + " WHEN MATCHED THEN UPDATE SET target.v = b.v\n" + + " WHEN NOT MATCHED AND b.v != 11 THEN INSERT (k, v) VALUES (b.k, b.v)"; assertSqlCanBeParsedAndDeparsed(sql, true); } diff --git a/src/test/java/net/sf/jsqlparser/statement/update/UpdateTest.java b/src/test/java/net/sf/jsqlparser/statement/update/UpdateTest.java index 00de44dc2..342d1eea6 100644 --- a/src/test/java/net/sf/jsqlparser/statement/update/UpdateTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/update/UpdateTest.java @@ -18,6 +18,8 @@ import net.sf.jsqlparser.parser.CCJSqlParserManager; import net.sf.jsqlparser.parser.CCJSqlParserUtil; import net.sf.jsqlparser.schema.Column; +import net.sf.jsqlparser.schema.Table; +import net.sf.jsqlparser.test.TestUtils; import org.junit.jupiter.api.Test; import java.io.StringReader; @@ -362,4 +364,20 @@ void testArrayColumnsIssue1083() throws JSQLParserException { sqlStr = "update utilisateur set listes[0:3] = (1,2,3,4)"; assertSqlCanBeParsedAndDeparsed(sqlStr, true); } + + @Test + void testIssue1910() throws JSQLParserException { + Update update = new Update(); + update.setTable(new Table("sys_dept")); + + UpdateSet updateSet = new UpdateSet(new Column("deleted"), new LongValue(1L)); + update.addUpdateSet(updateSet); + + TestUtils.assertStatementCanBeDeparsedAs(update, "UPDATE sys_dept SET deleted = 1", true); + + updateSet.add(new Column("created"), new LongValue(2L)); + + TestUtils.assertStatementCanBeDeparsedAs(update, + "UPDATE sys_dept SET (deleted, created) = (1,2)", true); + } } diff --git a/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java b/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java index e08c5032c..1cf2b90be 100644 --- a/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java +++ b/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java @@ -490,10 +490,10 @@ public void testConnectedByRootOperator() throws JSQLParserException { void testJoinSubSelect() throws JSQLParserException { String sqlStr = "select * from A left join B on A.id=B.id and A.age = (select age from C)"; Set tableNames = TablesNamesFinder.findTables(sqlStr); - assertThat( tableNames ).containsExactlyInAnyOrder("A", "B", "C"); + assertThat(tableNames).containsExactlyInAnyOrder("A", "B", "C"); String exprStr = "A.id=B.id and A.age = (select age from C)"; tableNames = TablesNamesFinder.findTablesInExpression(exprStr); - assertThat( tableNames ).containsExactlyInAnyOrder("A", "B", "C"); + assertThat(tableNames).containsExactlyInAnyOrder("A", "B", "C"); } }