mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-02-03 13:21:32 +02:00
Fix error reporting for queries with no results.
If a query that expected no results returned an error then it would incorrectly report that no results were expected because the error was interpreted as a result. Switch the order of the checks so that an error is reported instead and add a test to prevent regression.
This commit is contained in:
parent
d50b01b485
commit
d5cefb7290
@ -11,6 +11,18 @@
|
||||
|
||||
<p>Do not set <br-option>recovery_target_timeline=current</br-option> for PostgreSQL &lt; 12.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<github-pull-request id="2539"/>
|
||||
|
||||
<release-item-contributor-list>
|
||||
<release-item-ideator id="susantha.bathige"/>
|
||||
<release-item-contributor id="david.steele"/>
|
||||
<release-item-reviewer id="stefan.fercot"/>
|
||||
</release-item-contributor-list>
|
||||
|
||||
<p>Fix error reporting for queries with no results.</p>
|
||||
</release-item>
|
||||
</release-bug-list>
|
||||
|
||||
<release-improvement-list>
|
||||
|
@ -1000,6 +1000,10 @@
|
||||
<contributor-id type="github">sfrost</contributor-id>
|
||||
</contributor>
|
||||
|
||||
<contributor id="susantha.bathige">
|
||||
<contributor-name-display>Susantha Bathige</contributor-name-display>
|
||||
</contributor>
|
||||
|
||||
<contributor id="t.anastacio">
|
||||
<contributor-name-display>T.Anastacio</contributor-name-display>
|
||||
<contributor-id type="github">Tiago-Anastacio</contributor-id>
|
||||
|
@ -243,10 +243,7 @@ pgClientQuery(PgClient *const this, const String *const query, const PgClientQue
|
||||
}
|
||||
else
|
||||
{
|
||||
if (resultType == pgClientQueryResultNone)
|
||||
THROW_FMT(DbQueryError, "no result expected from '%s'", strZ(query));
|
||||
|
||||
// Expect some rows to be returned
|
||||
// If no tuples then the result is an error
|
||||
if (resultStatus != PGRES_TUPLES_OK)
|
||||
{
|
||||
THROW_FMT(
|
||||
@ -254,6 +251,10 @@ pgClientQuery(PgClient *const this, const String *const query, const PgClientQue
|
||||
strZ(strTrim(strNewZ(PQresultErrorMessage(pgResult)))));
|
||||
}
|
||||
|
||||
// Expect some rows to be returned
|
||||
if (resultType == pgClientQueryResultNone)
|
||||
THROW_FMT(DbQueryError, "no result expected from '%s'", strZ(query));
|
||||
|
||||
// Fetch row and column values
|
||||
PackWrite *const pack = pckWriteNewP();
|
||||
|
||||
|
@ -143,6 +143,32 @@ testRun(void)
|
||||
#undef TEST_PQ_ERROR
|
||||
#undef TEST_QUERY
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("unable to execute query that returns no results");
|
||||
|
||||
#define TEST_PQ_ERROR \
|
||||
"ERROR: must be superuser or have privileges of pg_checkpoint to do CHECKPOINT"
|
||||
#define TEST_QUERY "checkpoint"
|
||||
|
||||
#ifndef HARNESS_PQ_REAL
|
||||
HRN_PQ_SCRIPT_SET(
|
||||
{.function = HRN_PQ_SENDQUERY, .param = "[\"" TEST_QUERY "\"]", .resultInt = 1},
|
||||
{.function = HRN_PQ_CONSUMEINPUT},
|
||||
{.function = HRN_PQ_ISBUSY},
|
||||
{.function = HRN_PQ_GETRESULT},
|
||||
{.function = HRN_PQ_RESULTSTATUS, .resultInt = PGRES_FATAL_ERROR},
|
||||
{.function = HRN_PQ_RESULTERRORMESSAGE, .resultZ = TEST_PQ_ERROR},
|
||||
{.function = HRN_PQ_CLEAR},
|
||||
{.function = HRN_PQ_GETRESULT, .resultNull = true});
|
||||
#endif
|
||||
|
||||
TEST_ERROR(
|
||||
pgClientQuery(client, STRDEF(TEST_QUERY), pgClientQueryResultNone), DbQueryError,
|
||||
"unable to execute query '" TEST_QUERY "': " TEST_PQ_ERROR);
|
||||
|
||||
#undef TEST_PQ_ERROR
|
||||
#undef TEST_QUERY
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("query timeout");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user