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

Commit9f4e9bf

Browse files
committed
Code review for \df rewrite: fix assorted bugs, make type and
volatility columns localizable.
1 parent0e19884 commit9f4e9bf

File tree

1 file changed

+59
-32
lines changed

1 file changed

+59
-32
lines changed

‎src/bin/psql/describe.c

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
1010
*
11-
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.211 2009/05/04 17:31:35 heikki Exp $
11+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.212 2009/05/05 02:29:06 tgl Exp $
1212
*/
1313
#include"postgres_fe.h"
1414

@@ -197,14 +197,15 @@ describeTablespaces(const char *pattern, bool verbose)
197197
bool
198198
describeFunctions(constchar*functypes,constchar*pattern,boolverbose,boolshowSystem)
199199
{
200-
boolshowAggregate=strchr(functypes,'a')!=NULL;
201-
boolshowNormal=strchr(functypes,'n')!=NULL;
202-
boolshowTrigger=strchr(functypes,'t')!=NULL;
203-
boolshowWindow=strchr(functypes,'w')!=NULL;
204-
200+
boolshowAggregate=strchr(functypes,'a')!=NULL;
201+
boolshowNormal=strchr(functypes,'n')!=NULL;
202+
boolshowTrigger=strchr(functypes,'t')!=NULL;
203+
boolshowWindow=strchr(functypes,'w')!=NULL;
204+
boolhave_where;
205205
PQExpBufferDatabuf;
206206
PGresult*res;
207207
printQueryOptmyopt=pset.popt;
208+
staticconstbooltranslate_columns[]= {false, false, false, false, true, true, false, false, false, false};
208209

209210
if (strlen(functypes)!=strspn(functypes,"antwS+"))
210211
{
@@ -241,7 +242,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
241242
" CASE\n"
242243
" WHEN p.proisagg THEN '%s'\n"
243244
" WHEN p.proiswindow THEN '%s'\n"
244-
" WHENpg_catalog.pg_get_function_result(p.oid) = 'trigger' THEN '%s'\n"
245+
" WHENp.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
245246
" ELSE '%s'\n"
246247
"END as \"%s\"",
247248
gettext_noop("Result data type"),
@@ -287,7 +288,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
287288
" END AS \"%s\",\n"
288289
" CASE\n"
289290
" WHEN p.proisagg THEN '%s'\n"
290-
" WHEN'trigger' = pg_catalog.format_type(p.prorettype, NULL) THEN '%s'\n"
291+
" WHENp.prorettype ='pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
291292
" ELSE '%s'\n"
292293
" END AS \"%s\"",
293294
gettext_noop("Result data type"),
@@ -304,7 +305,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
304305
" pg_catalog.oidvectortypes(p.proargtypes) as \"%s\",\n"
305306
" CASE\n"
306307
" WHEN p.proisagg THEN '%s'\n"
307-
" WHEN'trigger' = pg_catalog.format_type(p.prorettype, NULL) THEN '%s'\n"
308+
" WHENp.prorettype ='pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
308309
" ELSE '%s'\n"
309310
" END AS \"%s\"",
310311
gettext_noop("Result data type"),
@@ -318,14 +319,17 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
318319
if (verbose)
319320
appendPQExpBuffer(&buf,
320321
",\n CASE\n"
321-
" WHEN p.provolatile = 'i' THEN 'immutable'\n"
322-
" WHEN p.provolatile = 's' THEN 'stable'\n"
323-
" WHEN p.provolatile = 'v' THEN 'volatile'\n"
322+
" WHEN p.provolatile = 'i' THEN '%s'\n"
323+
" WHEN p.provolatile = 's' THEN '%s'\n"
324+
" WHEN p.provolatile = 'v' THEN '%s'\n"
324325
"END as \"%s\""
325326
",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\",\n"
326327
" l.lanname as \"%s\",\n"
327328
" p.prosrc as \"%s\",\n"
328329
" pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
330+
gettext_noop("immutable"),
331+
gettext_noop("stable"),
332+
gettext_noop("volatile"),
329333
gettext_noop("Volatility"),
330334
gettext_noop("Owner"),
331335
gettext_noop("Language"),
@@ -340,33 +344,54 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
340344
appendPQExpBuffer(&buf,
341345
" LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
342346

343-
processSQLNamePattern(pset.db,&buf,pattern, false, true,
344-
"n.nspname","p.proname",NULL,
345-
"pg_catalog.pg_function_is_visible(p.oid)");
347+
have_where= false;
346348

349+
/* filter by function type, if requested */
347350
if (showNormal&&showAggregate&&showTrigger&&showWindow)
348351
/* Do nothing */;
349352
elseif (showNormal)
350353
{
351-
if (!showWindow&&pset.sversion >=80400)
352-
appendPQExpBuffer(&buf," AND NOT p.proiswindow\n");
353354
if (!showAggregate)
354-
appendPQExpBuffer(&buf," AND NOT p.proisagg\n");
355+
{
356+
if (have_where)
357+
appendPQExpBuffer(&buf," AND ");
358+
else
359+
{
360+
appendPQExpBuffer(&buf,"WHERE ");
361+
have_where= true;
362+
}
363+
appendPQExpBuffer(&buf,"NOT p.proisagg\n");
364+
}
355365
if (!showTrigger)
356366
{
357-
if (pset.sversion >=80400)
358-
appendPQExpBuffer(&buf,
359-
" AND pg_catalog.pg_get_function_result(p.oid) <> 'trigger'\n");
367+
if (have_where)
368+
appendPQExpBuffer(&buf," AND ");
360369
else
361-
appendPQExpBuffer(&buf,
362-
" AND pg_catalog.format_type(p.prorettype, NULL) <> 'trigger'\n");
370+
{
371+
appendPQExpBuffer(&buf,"WHERE ");
372+
have_where= true;
373+
}
374+
appendPQExpBuffer(&buf,"p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype\n");
375+
}
376+
if (!showWindow&&pset.sversion >=80400)
377+
{
378+
if (have_where)
379+
appendPQExpBuffer(&buf," AND ");
380+
else
381+
{
382+
appendPQExpBuffer(&buf,"WHERE ");
383+
have_where= true;
384+
}
385+
appendPQExpBuffer(&buf,"NOT p.proiswindow\n");
363386
}
364387
}
365388
else
366389
{
367390
boolneeds_or= false;
368391

369-
appendPQExpBuffer(&buf," AND (\n ");
392+
appendPQExpBuffer(&buf,"WHERE (\n ");
393+
have_where= true;
394+
/* Note: at least one of these must be true ... */
370395
if (showAggregate)
371396
{
372397
appendPQExpBuffer(&buf,"p.proisagg\n");
@@ -375,24 +400,25 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
375400
if (showTrigger)
376401
{
377402
if (needs_or)
378-
appendPQExpBuffer(&buf," OR ");
379-
if (pset.sversion >=80400)
380-
appendPQExpBuffer(&buf,
381-
"pg_catalog.pg_get_function_result(p.oid) = 'trigger'\n");
382-
else
383-
appendPQExpBuffer(&buf,
384-
"'trigger' <> pg_catalog.format_type(p.prorettype, NULL)\n");
403+
appendPQExpBuffer(&buf," OR ");
404+
appendPQExpBuffer(&buf,
405+
"p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
385406
needs_or= true;
386407
}
387408
if (showWindow)
388409
{
389410
if (needs_or)
390-
appendPQExpBuffer(&buf," OR ");
411+
appendPQExpBuffer(&buf,"OR ");
391412
appendPQExpBuffer(&buf,"p.proiswindow\n");
413+
needs_or= true;
392414
}
393415
appendPQExpBuffer(&buf," )\n");
394416
}
395417

418+
processSQLNamePattern(pset.db,&buf,pattern,have_where, true,
419+
"n.nspname","p.proname",NULL,
420+
"pg_catalog.pg_function_is_visible(p.oid)");
421+
396422
if (!showSystem&& !pattern)
397423
appendPQExpBuffer(&buf," AND n.nspname <> 'pg_catalog'\n"
398424
" AND n.nspname <> 'information_schema'\n");
@@ -407,6 +433,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
407433
myopt.nullPrint=NULL;
408434
myopt.title=_("List of functions");
409435
myopt.translate_header= true;
436+
myopt.translate_columns=translate_columns;
410437

411438
printQuery(res,&myopt,pset.queryFout,pset.logfile);
412439

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp