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

Commit48b2d88

Browse files
committed
psql: Improve \pset without arguments
Revert the output of the individual backslash commands that change printsettings back to the 9.3 way (not showing the command name inparentheses). Implement \pset without arguments separately, showing allsettings with values in a table form.
1 parent5c8758e commit48b2d88

File tree

2 files changed

+152
-61
lines changed

2 files changed

+152
-61
lines changed

‎src/bin/psql/command.c

Lines changed: 136 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static void minimal_error_message(PGresult *res);
6969

7070
staticvoidprintSSLInfo(void);
7171
staticboolprintPsetInfo(constchar*param,structprintQueryOpt*popt);
72+
staticchar*pset_value_string(constchar*param,structprintQueryOpt*popt);
7273

7374
#ifdefWIN32
7475
staticvoidcheckWin32Codepage(void);
@@ -1050,15 +1051,19 @@ exec_command(const char *cmd,
10501051

10511052
inti;
10521053
staticconstchar*constmy_list[]= {
1053-
"border","columns","expanded","fieldsep",
1054+
"border","columns","expanded","fieldsep","fieldsep_zero",
10541055
"footer","format","linestyle","null",
1055-
"numericlocale","pager","recordsep",
1056+
"numericlocale","pager","recordsep","recordsep_zero",
10561057
"tableattr","title","tuples_only",
10571058
NULL
10581059
};
10591060

10601061
for (i=0;my_list[i]!=NULL;i++)
1061-
printPsetInfo(my_list[i],&pset.popt);
1062+
{
1063+
char*val=pset_value_string(my_list[i],&pset.popt);
1064+
printf("%-14s %s\n",my_list[i],val);
1065+
free(val);
1066+
}
10621067

10631068
success= true;
10641069
}
@@ -2199,10 +2204,6 @@ process_file(char *filename, bool single_txn, bool use_relative_path)
21992204

22002205

22012206

2202-
/*
2203-
* do_pset
2204-
*
2205-
*/
22062207
staticconstchar*
22072208
_align2string(enumprintFormatin)
22082209
{
@@ -2237,6 +2238,10 @@ _align2string(enum printFormat in)
22372238
}
22382239

22392240

2241+
/*
2242+
* do_pset
2243+
*
2244+
*/
22402245
bool
22412246
do_pset(constchar*param,constchar*value,printQueryOpt*popt,boolquiet)
22422247
{
@@ -2447,146 +2452,135 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
24472452

24482453
/* show border style/width */
24492454
if (strcmp(param,"border")==0)
2450-
{
2451-
if (!popt->topt.border)
2452-
printf(_("Border style (%s) unset.\n"),param);
2453-
else
2454-
printf(_("Border style (%s) is %d.\n"),param,
2455-
popt->topt.border);
2456-
}
2455+
printf(_("Border style is %d.\n"),popt->topt.border);
24572456

24582457
/* show the target width for the wrapped format */
24592458
elseif (strcmp(param,"columns")==0)
24602459
{
24612460
if (!popt->topt.columns)
2462-
printf(_("Target width(%s) unset.\n"),param);
2461+
printf(_("Target widthis unset.\n"));
24632462
else
2464-
printf(_("Target width (%s) is %d.\n"),param,
2465-
popt->topt.columns);
2463+
printf(_("Target width is %d.\n"),popt->topt.columns);
24662464
}
24672465

24682466
/* show expanded/vertical mode */
24692467
elseif (strcmp(param,"x")==0||strcmp(param,"expanded")==0||strcmp(param,"vertical")==0)
24702468
{
24712469
if (popt->topt.expanded==1)
2472-
printf(_("Expanded display(%s)is on.\n"),param);
2470+
printf(_("Expanded display is on.\n"));
24732471
elseif (popt->topt.expanded==2)
2474-
printf(_("Expanded display(%s)is used automatically.\n"),param);
2472+
printf(_("Expanded display is used automatically.\n"));
24752473
else
2476-
printf(_("Expanded display(%s)is off.\n"),param);
2474+
printf(_("Expanded display is off.\n"));
24772475
}
24782476

24792477
/* show field separator for unaligned text */
24802478
elseif (strcmp(param,"fieldsep")==0)
24812479
{
24822480
if (popt->topt.fieldSep.separator_zero)
2483-
printf(_("Field separator(%s)is zero byte.\n"),param);
2481+
printf(_("Field separator is zero byte.\n"));
24842482
else
2485-
printf(_("Field separator(%s)is \"%s\".\n"),param,
2483+
printf(_("Field separator is \"%s\".\n"),
24862484
popt->topt.fieldSep.separator);
24872485
}
24882486

24892487
elseif (strcmp(param,"fieldsep_zero")==0)
24902488
{
2491-
printf(_("Field separator(%s)is zero byte.\n"),param);
2489+
printf(_("Field separator is zero byte.\n"));
24922490
}
24932491

24942492
/* show disable "(x rows)" footer */
24952493
elseif (strcmp(param,"footer")==0)
24962494
{
24972495
if (popt->topt.default_footer)
2498-
printf(_("Default footer(%s)is on.\n"),param);
2496+
printf(_("Default footer is on.\n"));
24992497
else
2500-
printf(_("Default footer(%s)is off.\n"),param);
2498+
printf(_("Default footer is off.\n"));
25012499
}
25022500

25032501
/* show format */
25042502
elseif (strcmp(param,"format")==0)
25052503
{
2506-
if (!popt->topt.format)
2507-
printf(_("Output format (%s) is aligned.\n"),param);
2508-
else
2509-
printf(_("Output format (%s) is %s.\n"),param,
2510-
_align2string(popt->topt.format));
2504+
printf(_("Output format is %s.\n"),_align2string(popt->topt.format));
25112505
}
25122506

25132507
/* show table line style */
25142508
elseif (strcmp(param,"linestyle")==0)
25152509
{
2516-
printf(_("Line style(%s)is %s.\n"),param,
2510+
printf(_("Line style is %s.\n"),
25172511
get_line_style(&popt->topt)->name);
25182512
}
25192513

25202514
/* show null display */
25212515
elseif (strcmp(param,"null")==0)
25222516
{
2523-
printf(_("Null display(%s)is \"%s\".\n"),param,
2517+
printf(_("Null display is \"%s\".\n"),
25242518
popt->nullPrint ?popt->nullPrint :"");
25252519
}
25262520

25272521
/* show locale-aware numeric output */
25282522
elseif (strcmp(param,"numericlocale")==0)
25292523
{
25302524
if (popt->topt.numericLocale)
2531-
printf(_("Locale-adjusted numeric output(%s)is on.\n"),param);
2525+
printf(_("Locale-adjusted numeric output is on.\n"));
25322526
else
2533-
printf(_("Locale-adjusted numeric output(%s)is off.\n"),param);
2527+
printf(_("Locale-adjusted numeric output is off.\n"));
25342528
}
25352529

25362530
/* show toggle use of pager */
25372531
elseif (strcmp(param,"pager")==0)
25382532
{
25392533
if (popt->topt.pager==1)
2540-
printf(_("Pager(%s)is used for long output.\n"),param);
2534+
printf(_("Pager is used for long output.\n"));
25412535
elseif (popt->topt.pager==2)
2542-
printf(_("Pager(%s)is always used.\n"),param);
2536+
printf(_("Pager is always used.\n"));
25432537
else
2544-
printf(_("Pager usage(%s)is off.\n"),param);
2538+
printf(_("Pager usage is off.\n"));
25452539
}
25462540

25472541
/* show record separator for unaligned text */
25482542
elseif (strcmp(param,"recordsep")==0)
25492543
{
25502544
if (popt->topt.recordSep.separator_zero)
2551-
printf(_("Record separator(%s)is zero byte.\n"),param);
2545+
printf(_("Record separator is zero byte.\n"));
25522546
elseif (strcmp(popt->topt.recordSep.separator,"\n")==0)
2553-
printf(_("Record separator(%s)is <newline>.\n"),param);
2547+
printf(_("Record separator is <newline>.\n"));
25542548
else
2555-
printf(_("Record separator(%s)is \"%s\".\n"),param,
2549+
printf(_("Record separator is \"%s\".\n"),
25562550
popt->topt.recordSep.separator);
25572551
}
25582552

25592553
elseif (strcmp(param,"recordsep_zero")==0)
25602554
{
2561-
printf(_("Record separator(%s)is zero byte.\n"),param);
2555+
printf(_("Record separator is zero byte.\n"));
25622556
}
25632557

25642558
/* show HTML table tag options */
25652559
elseif (strcmp(param,"T")==0||strcmp(param,"tableattr")==0)
25662560
{
25672561
if (popt->topt.tableAttr)
2568-
printf(_("Table attributes(%s)are \"%s\".\n"),param,
2562+
printf(_("Table attributes are \"%s\".\n"),
25692563
popt->topt.tableAttr);
25702564
else
2571-
printf(_("Table attributes(%s)unset.\n"),param);
2565+
printf(_("Table attributes unset.\n"));
25722566
}
25732567

25742568
/* show title override */
25752569
elseif (strcmp(param,"title")==0)
25762570
{
25772571
if (popt->title)
2578-
printf(_("Title(%s)is \"%s\".\n"),param,popt->title);
2572+
printf(_("Title is \"%s\".\n"),popt->title);
25792573
else
2580-
printf(_("Title(%s) unset.\n"),param);
2574+
printf(_("Titleis unset.\n"));
25812575
}
25822576

25832577
/* show toggle between full and tuples-only format */
25842578
elseif (strcmp(param,"t")==0||strcmp(param,"tuples_only")==0)
25852579
{
25862580
if (popt->topt.tuples_only)
2587-
printf(_("Tuples only(%s)is on.\n"),param);
2581+
printf(_("Tuples only is on.\n"));
25882582
else
2589-
printf(_("Tuples only(%s)is off.\n"),param);
2583+
printf(_("Tuples only is off.\n"));
25902584
}
25912585

25922586
else
@@ -2599,6 +2593,101 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
25992593
}
26002594

26012595

2596+
staticconstchar*
2597+
pset_bool_string(boolval)
2598+
{
2599+
returnval ?"on" :"off";
2600+
}
2601+
2602+
2603+
staticchar*
2604+
pset_quoted_string(constchar*str)
2605+
{
2606+
char*ret=pg_malloc(strlen(str)*2+2);
2607+
char*r=ret;
2608+
2609+
*r++='\'';
2610+
2611+
for (;*str;str++)
2612+
{
2613+
if (*str=='\n')
2614+
{
2615+
*r++='\\';
2616+
*r++='n';
2617+
}
2618+
elseif (*str=='\'')
2619+
{
2620+
*r++='\\';
2621+
*r++='\'';
2622+
}
2623+
else
2624+
*r++=*str;
2625+
}
2626+
2627+
*r++='\'';
2628+
*r='\0';
2629+
2630+
returnret;
2631+
}
2632+
2633+
2634+
/*
2635+
* Return a malloc'ed string for the \pset value.
2636+
*
2637+
* Note that for some string parameters, print.c distinguishes between unset
2638+
* and empty string, but for others it doesn't. This function should produce
2639+
* output that produces the correct setting when fed back into \pset.
2640+
*/
2641+
staticchar*
2642+
pset_value_string(constchar*param,structprintQueryOpt*popt)
2643+
{
2644+
Assert(param!=NULL);
2645+
2646+
if (strcmp(param,"border")==0)
2647+
returnpsprintf("%d",popt->topt.border);
2648+
elseif (strcmp(param,"columns")==0)
2649+
returnpsprintf("%d",popt->topt.columns);
2650+
elseif (strcmp(param,"expanded")==0)
2651+
returnpstrdup(popt->topt.expanded==2
2652+
?"auto"
2653+
:pset_bool_string(popt->topt.expanded));
2654+
elseif (strcmp(param,"fieldsep")==0)
2655+
returnpset_quoted_string(popt->topt.fieldSep.separator
2656+
?popt->topt.fieldSep.separator
2657+
:"");
2658+
elseif (strcmp(param,"fieldsep_zero")==0)
2659+
returnpstrdup(pset_bool_string(popt->topt.fieldSep.separator_zero));
2660+
elseif (strcmp(param,"footer")==0)
2661+
returnpstrdup(pset_bool_string(popt->topt.default_footer));
2662+
elseif (strcmp(param,"format")==0)
2663+
returnpsprintf("%s",_align2string(popt->topt.format));
2664+
elseif (strcmp(param,"linestyle")==0)
2665+
returnpsprintf("%s",get_line_style(&popt->topt)->name);
2666+
elseif (strcmp(param,"null")==0)
2667+
returnpset_quoted_string(popt->nullPrint
2668+
?popt->nullPrint
2669+
:"");
2670+
elseif (strcmp(param,"numericlocale")==0)
2671+
returnpstrdup(pset_bool_string(popt->topt.numericLocale));
2672+
elseif (strcmp(param,"pager")==0)
2673+
returnpsprintf("%d",popt->topt.pager);
2674+
elseif (strcmp(param,"recordsep")==0)
2675+
returnpset_quoted_string(popt->topt.recordSep.separator
2676+
?popt->topt.recordSep.separator
2677+
:"");
2678+
elseif (strcmp(param,"recordsep_zero")==0)
2679+
returnpstrdup(pset_bool_string(popt->topt.recordSep.separator_zero));
2680+
elseif (strcmp(param,"tableattr")==0)
2681+
returnpopt->topt.tableAttr ?pset_quoted_string(popt->topt.tableAttr) :pstrdup("");
2682+
elseif (strcmp(param,"title")==0)
2683+
returnpopt->title ?pset_quoted_string(popt->title) :pstrdup("");
2684+
elseif (strcmp(param,"tuples_only")==0)
2685+
returnpstrdup(pset_bool_string(popt->topt.tuples_only));
2686+
else
2687+
returnpstrdup("ERROR");
2688+
}
2689+
2690+
26022691

26032692
#ifndefWIN32
26042693
#defineDEFAULT_SHELL "/bin/sh"

‎src/test/regress/expected/psql.out

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,19 @@ no rows returned for \gset
5454
\unset FETCH_COUNT
5555
-- show all pset options
5656
\pset
57-
Border style (border) is 1.
58-
Target width (columns) unset.
59-
Expanded display (expanded) is off.
60-
Field separator (fieldsep) is "|".
61-
Default footer (footer) is on.
62-
Output format (format) is aligned.
63-
Line style (linestyle) is ascii.
64-
Null display (null) is "".
65-
Locale-adjusted numeric output (numericlocale) is off.
66-
Pager (pager) is used for long output.
67-
Record separator (recordsep) is <newline>.
68-
Table attributes (tableattr) unset.
69-
Title (title) unset.
70-
Tuples only (tuples_only) is off.
57+
border 1
58+
columns 0
59+
expanded off
60+
fieldsep '|'
61+
fieldsep_zero off
62+
footer on
63+
format aligned
64+
linestyle ascii
65+
null ''
66+
numericlocale off
67+
pager 1
68+
recordsep '\n'
69+
recordsep_zero off
70+
tableattr
71+
title
72+
tuples_only off

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp