Permalink
Browse files

fix: throw TOO_MANY_RESULTS (0100E) instead of "PgResultSet: tuples m…

…ust be non-null"

When expecting no rows (e.g. executeUpdate with NO_GENERATED_KEYS) a query might still return one row
as "max rows" in Execute message does not allow to limit the resultset completely.

The returned tuples are ignored all the way up via "noResults / QueryExecutor.QUERY_NO_RESULTS", however
it fails when it meets handler.handleResultRows and tries to create a resultSet.

The corrective action is to create empty tuples list so empty resultSet is created.

The issue is reproduced in binary=FORCE in GeneratedKeysTest
  • Loading branch information...
vlsi committed Jan 2, 2018
1 parent 3e0491a commit 0d31d46adff4e9772db843195e1638531bc703e0
@@ -2067,8 +2067,10 @@ protected void processResults(ResultHandler handler, int flags) throws IOExcepti
Portal currentPortal = executeData.portal;

Field[] fields = currentQuery.getFields();
if (fields != null && !noResults && tuples == null) {
tuples = new ArrayList<byte[][]>();
if (fields != null && tuples == null) {
// When no results expected, pretend an empty resultset was returned
// Not sure if new ArrayList can be always replaced with emptyList
tuples = noResults ? Collections.emptyList() : new ArrayList<byte[][]>();
}

handler.handleResultRows(currentQuery, fields, tuples, currentPortal);
@@ -2115,8 +2117,10 @@ protected void processResults(ResultHandler handler, int flags) throws IOExcepti
}

Field[] fields = currentQuery.getFields();
if (fields != null && !noResults && tuples == null) {
tuples = new ArrayList<byte[][]>();
if (fields != null && tuples == null) {
// When no results expected, pretend an empty resultset was returned
// Not sure if new ArrayList can be always replaced with emptyList
tuples = noResults ? Collections.emptyList() : new ArrayList<byte[][]>();
}

// If we received tuples we must know the structure of the
@@ -66,16 +66,19 @@ public String getClause() {
private final ReturningInQuery returningInQuery;
private final String returningClause;

public GeneratedKeysTest(ReturningInQuery returningInQuery) throws Exception {
public GeneratedKeysTest(ReturningInQuery returningInQuery, BinaryMode binaryMode) throws Exception {
this.returningInQuery = returningInQuery;
this.returningClause = returningInQuery.getClause();
setBinaryMode(binaryMode);
}

@Parameterized.Parameters(name = "returningInQuery = {0}")
@Parameterized.Parameters(name = "returningInQuery = {0}, binary = {1}")
public static Iterable<Object[]> data() {
Collection<Object[]> ids = new ArrayList<Object[]>();
for (ReturningInQuery returningInQuery : ReturningInQuery.values()) {
ids.add(new Object[]{returningInQuery});
for (BinaryMode binaryMode : BinaryMode.values()) {
ids.add(new Object[]{returningInQuery, binaryMode});
}
}
return ids;
}

0 comments on commit 0d31d46

Please sign in to comment.