mirror of
https://github.com/postgres/postgres.git
synced 2025-05-09 18:21:05 +03:00
Standardize describe.c's behavior for no-matching-objects a bit more.
Most functions in this file are content to print an empty table if there are no matching objects. In some, the behavior is to loop over all matching objects and print a table for each one; therefore, without any extra logic, nothing at all would be printed if no objects match. We accept that outcome in QUIET mode, but in normal mode it seems better to print a helpful message. The new \dRp+ command had not gotten that memo; fix it. listDbRoleSettings() is out of step on this, but I think it's better for it to print a custom message rather than an empty table, because of the possibility that the user is confused about what the pattern arguments mean or which is which. The original message wording was entirely useless for clarifying that, though, not to mention being unlike the wordings used elsewhere. Improve the text, and also print the messages with psql_error as is the general custom here. listTables() is also out in left field, but since it's such a heavily used function, I'm hesitant to change its behavior so much as to print an empty table rather than a custom message. People are probably used to getting a message. But we can make the wording more standardized and helpful, and print it with psql_error rather than printing to stdout. In both listDbRoleSettings and listTables, we play dumb and emit an empty table, not a custom message, in QUIET mode. That was true before and I see no need to change it. Several of the places printing such messages risked dumping core if no pattern string had been provided; make them more wary. (This case is presently unreachable in describeTableDetails; but it shouldn't be assuming that command.c will never pass it a null. The text search functions would only reach the case if a database contained no text search objects, which is also currently impossible since we pin the built-in objects, but again it seems unwise to assume that here.) Daniel Gustafsson, tweaked a bit by me Discussion: https://postgr.es/m/3641F19B-336A-431A-86CE-A80562505C5E@yesql.se
This commit is contained in:
parent
1e2f941db1
commit
77cb4a1d67
@ -1322,8 +1322,13 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem)
|
|||||||
if (PQntuples(res) == 0)
|
if (PQntuples(res) == 0)
|
||||||
{
|
{
|
||||||
if (!pset.quiet)
|
if (!pset.quiet)
|
||||||
psql_error("Did not find any relation named \"%s\".\n",
|
{
|
||||||
pattern);
|
if (pattern)
|
||||||
|
psql_error("Did not find any relation named \"%s\".\n",
|
||||||
|
pattern);
|
||||||
|
else
|
||||||
|
psql_error("Did not find any relations.\n");
|
||||||
|
}
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -3250,12 +3255,22 @@ listDbRoleSettings(const char *pattern, const char *pattern2)
|
|||||||
if (!res)
|
if (!res)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Most functions in this file are content to print an empty table when
|
||||||
|
* there are no matching objects. We intentionally deviate from that
|
||||||
|
* here, but only in !quiet mode, because of the possibility that the user
|
||||||
|
* is confused about what the two pattern arguments mean.
|
||||||
|
*/
|
||||||
if (PQntuples(res) == 0 && !pset.quiet)
|
if (PQntuples(res) == 0 && !pset.quiet)
|
||||||
{
|
{
|
||||||
if (pattern)
|
if (pattern && pattern2)
|
||||||
fprintf(pset.queryFout, _("No matching settings found.\n"));
|
psql_error("Did not find any settings for role \"%s\" and database \"%s\".\n",
|
||||||
|
pattern, pattern2);
|
||||||
|
else if (pattern)
|
||||||
|
psql_error("Did not find any settings for role \"%s\".\n",
|
||||||
|
pattern);
|
||||||
else
|
else
|
||||||
fprintf(pset.queryFout, _("No settings found.\n"));
|
psql_error("Did not find any settings.\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3414,12 +3429,18 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
|
|||||||
if (!res)
|
if (!res)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Most functions in this file are content to print an empty table when
|
||||||
|
* there are no matching objects. We intentionally deviate from that
|
||||||
|
* here, but only in !quiet mode, for historical reasons.
|
||||||
|
*/
|
||||||
if (PQntuples(res) == 0 && !pset.quiet)
|
if (PQntuples(res) == 0 && !pset.quiet)
|
||||||
{
|
{
|
||||||
if (pattern)
|
if (pattern)
|
||||||
fprintf(pset.queryFout, _("No matching relations found.\n"));
|
psql_error("Did not find any relation named \"%s\".\n",
|
||||||
|
pattern);
|
||||||
else
|
else
|
||||||
fprintf(pset.queryFout, _("No relations found.\n"));
|
psql_error("Did not find any relations.\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -4074,8 +4095,13 @@ listTSParsersVerbose(const char *pattern)
|
|||||||
if (PQntuples(res) == 0)
|
if (PQntuples(res) == 0)
|
||||||
{
|
{
|
||||||
if (!pset.quiet)
|
if (!pset.quiet)
|
||||||
psql_error("Did not find any text search parser named \"%s\".\n",
|
{
|
||||||
pattern);
|
if (pattern)
|
||||||
|
psql_error("Did not find any text search parser named \"%s\".\n",
|
||||||
|
pattern);
|
||||||
|
else
|
||||||
|
psql_error("Did not find any text search parsers.\n");
|
||||||
|
}
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -4459,8 +4485,13 @@ listTSConfigsVerbose(const char *pattern)
|
|||||||
if (PQntuples(res) == 0)
|
if (PQntuples(res) == 0)
|
||||||
{
|
{
|
||||||
if (!pset.quiet)
|
if (!pset.quiet)
|
||||||
psql_error("Did not find any text search configuration named \"%s\".\n",
|
{
|
||||||
pattern);
|
if (pattern)
|
||||||
|
psql_error("Did not find any text search configuration named \"%s\".\n",
|
||||||
|
pattern);
|
||||||
|
else
|
||||||
|
psql_error("Did not find any text search configurations.\n");
|
||||||
|
}
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -5148,6 +5179,22 @@ describePublications(const char *pattern)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PQntuples(res) == 0)
|
||||||
|
{
|
||||||
|
if (!pset.quiet)
|
||||||
|
{
|
||||||
|
if (pattern)
|
||||||
|
psql_error("Did not find any publication named \"%s\".\n",
|
||||||
|
pattern);
|
||||||
|
else
|
||||||
|
psql_error("Did not find any publications.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
termPQExpBuffer(&buf);
|
||||||
|
PQclear(res);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < PQntuples(res); i++)
|
for (i = 0; i < PQntuples(res); i++)
|
||||||
{
|
{
|
||||||
const char align = 'l';
|
const char align = 'l';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user