Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit77cb4a1

Browse files
committed
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 thereare no matching objects. In some, the behavior is to loop over allmatching objects and print a table for each one; therefore, without anyextra logic, nothing at all would be printed if no objects match.We accept that outcome in QUIET mode, but in normal mode it seems betterto print a helpful message. The new \dRp+ command had not gotten thatmemo; fix it.listDbRoleSettings() is out of step on this, but I think it's better forit to print a custom message rather than an empty table, because of thepossibility that the user is confused about what the pattern arguments meanor which is which. The original message wording was entirely useless forclarifying that, though, not to mention being unlike the wordings usedelsewhere. Improve the text, and also print the messages with psql_erroras is the general custom here.listTables() is also out in left field, but since it's such a heavilyused function, I'm hesitant to change its behavior so much as to printan empty table rather than a custom message. People are probably usedto getting a message. But we can make the wording more standardized andhelpful, and print it with psql_error rather than printing to stdout.In both listDbRoleSettings and listTables, we play dumb and emit anempty table, not a custom message, in QUIET mode. That was true beforeand I see no need to change it.Several of the places printing such messages risked dumping core ifno pattern string had been provided; make them more wary. (This caseis presently unreachable in describeTableDetails; but it shouldn't beassuming that command.c will never pass it a null. The text searchfunctions would only reach the case if a database contained no textsearch objects, which is also currently impossible since we pin thebuilt-in objects, but again it seems unwise to assume that here.)Daniel Gustafsson, tweaked a bit by meDiscussion:https://postgr.es/m/3641F19B-336A-431A-86CE-A80562505C5E@yesql.se
1 parent1e2f941 commit77cb4a1

File tree

1 file changed

+58
-11
lines changed

1 file changed

+58
-11
lines changed

‎src/bin/psql/describe.c

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,8 +1322,13 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem)
13221322
if (PQntuples(res)==0)
13231323
{
13241324
if (!pset.quiet)
1325-
psql_error("Did not find any relation named \"%s\".\n",
1326-
pattern);
1325+
{
1326+
if (pattern)
1327+
psql_error("Did not find any relation named \"%s\".\n",
1328+
pattern);
1329+
else
1330+
psql_error("Did not find any relations.\n");
1331+
}
13271332
PQclear(res);
13281333
return false;
13291334
}
@@ -3250,12 +3255,22 @@ listDbRoleSettings(const char *pattern, const char *pattern2)
32503255
if (!res)
32513256
return false;
32523257

3258+
/*
3259+
* Most functions in this file are content to print an empty table when
3260+
* there are no matching objects. We intentionally deviate from that
3261+
* here, but only in !quiet mode, because of the possibility that the user
3262+
* is confused about what the two pattern arguments mean.
3263+
*/
32533264
if (PQntuples(res)==0&& !pset.quiet)
32543265
{
3255-
if (pattern)
3256-
fprintf(pset.queryFout,_("No matching settings found.\n"));
3266+
if (pattern&&pattern2)
3267+
psql_error("Did not find any settings for role \"%s\" and database \"%s\".\n",
3268+
pattern,pattern2);
3269+
elseif (pattern)
3270+
psql_error("Did not find any settings for role \"%s\".\n",
3271+
pattern);
32573272
else
3258-
fprintf(pset.queryFout,_("No settings found.\n"));
3273+
psql_error("Did not find any settings.\n");
32593274
}
32603275
else
32613276
{
@@ -3414,12 +3429,18 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
34143429
if (!res)
34153430
return false;
34163431

3432+
/*
3433+
* Most functions in this file are content to print an empty table when
3434+
* there are no matching objects. We intentionally deviate from that
3435+
* here, but only in !quiet mode, for historical reasons.
3436+
*/
34173437
if (PQntuples(res)==0&& !pset.quiet)
34183438
{
34193439
if (pattern)
3420-
fprintf(pset.queryFout,_("No matching relations found.\n"));
3440+
psql_error("Did not find any relation named \"%s\".\n",
3441+
pattern);
34213442
else
3422-
fprintf(pset.queryFout,_("No relations found.\n"));
3443+
psql_error("Did not find any relations.\n");
34233444
}
34243445
else
34253446
{
@@ -4074,8 +4095,13 @@ listTSParsersVerbose(const char *pattern)
40744095
if (PQntuples(res)==0)
40754096
{
40764097
if (!pset.quiet)
4077-
psql_error("Did not find any text search parser named \"%s\".\n",
4078-
pattern);
4098+
{
4099+
if (pattern)
4100+
psql_error("Did not find any text search parser named \"%s\".\n",
4101+
pattern);
4102+
else
4103+
psql_error("Did not find any text search parsers.\n");
4104+
}
40794105
PQclear(res);
40804106
return false;
40814107
}
@@ -4459,8 +4485,13 @@ listTSConfigsVerbose(const char *pattern)
44594485
if (PQntuples(res)==0)
44604486
{
44614487
if (!pset.quiet)
4462-
psql_error("Did not find any text search configuration named \"%s\".\n",
4463-
pattern);
4488+
{
4489+
if (pattern)
4490+
psql_error("Did not find any text search configuration named \"%s\".\n",
4491+
pattern);
4492+
else
4493+
psql_error("Did not find any text search configurations.\n");
4494+
}
44644495
PQclear(res);
44654496
return false;
44664497
}
@@ -5148,6 +5179,22 @@ describePublications(const char *pattern)
51485179
return false;
51495180
}
51505181

5182+
if (PQntuples(res)==0)
5183+
{
5184+
if (!pset.quiet)
5185+
{
5186+
if (pattern)
5187+
psql_error("Did not find any publication named \"%s\".\n",
5188+
pattern);
5189+
else
5190+
psql_error("Did not find any publications.\n");
5191+
}
5192+
5193+
termPQExpBuffer(&buf);
5194+
PQclear(res);
5195+
return false;
5196+
}
5197+
51515198
for (i=0;i<PQntuples(res);i++)
51525199
{
51535200
constcharalign='l';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp