Fix bulk update command failing on SQL based storages when tracking operation stats with multiple constraints (#2699)

This commit is contained in:
Federico López 2020-11-02 06:46:45 -03:00 committed by GitHub
parent 7854de8991
commit 5d0c578da1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -103,6 +103,17 @@ public final class BulkUpdate {
// (DELETE FROM or UPDATE)
this.action.appendSql(builder);
return appendConstraintsAsSql(builder);
}
/**
* Appends the constraints of this {@link BulkUpdate} to the provided statement builder in SQL syntax
*
* @param builder the statement builder to append the constraints to
* @return the same statement builder provided as input
*/
public PreparedStatementBuilder appendConstraintsAsSql(PreparedStatementBuilder builder) {
// if there are no constraints, just return without a WHERE clause
if (this.queries.isEmpty()) {
return builder;

View File

@ -261,10 +261,7 @@ public class SqlStorage implements StorageImplementation {
if (bulkUpdate.isTrackingStatistics()) {
PreparedStatementBuilder builder = new PreparedStatementBuilder();
builder.append(USER_PERMISSIONS_SELECT_DISTINCT);
if (!bulkUpdate.getQueries().isEmpty()) {
builder.append(" WHERE ");
bulkUpdate.getQueries().forEach(query -> query.appendSql(builder));
}
bulkUpdate.appendConstraintsAsSql(builder);
try (PreparedStatement lookup = builder.build(c, this.statementProcessor)) {
try (ResultSet rs = lookup.executeQuery()) {
@ -291,10 +288,7 @@ public class SqlStorage implements StorageImplementation {
if (bulkUpdate.isTrackingStatistics()) {
PreparedStatementBuilder builder = new PreparedStatementBuilder();
builder.append(GROUP_PERMISSIONS_SELECT_ALL);
if (!bulkUpdate.getQueries().isEmpty()) {
builder.append(" WHERE ");
bulkUpdate.getQueries().forEach(query -> query.appendSql(builder));
}
bulkUpdate.appendConstraintsAsSql(builder);
try (PreparedStatement lookup = builder.build(c, this.statementProcessor)) {
try (ResultSet rs = lookup.executeQuery()) {