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

Commit95708e1

Browse files
committed
Further tweaking of print_aligned_vertical().
Don't force the data width to extend all the way to the right margin if itdoesn't need to. This reverts the behavior in non-wrapping cases to bewhat it was in 9.4. Also, make the logic that ensures the data line widthis at least equal to the record-header line width a little less obscure.In passing, avoid possible calculation of log10(0). Probably that'sharmless, given the lack of field complaints, but it seems risky:conversion of NaN to an integer isn't well defined.
1 parentdb4a5cf commit95708e1

File tree

2 files changed

+55
-41
lines changed

2 files changed

+55
-41
lines changed

‎src/bin/psql/print.c

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
12651265
/*
12661266
* Deal with the pager here instead of in printTable(), because we could
12671267
* get here via print_aligned_text() in expanded auto mode, and so we have
1268-
* torecalcuate the pager requirement based on vertical output.
1268+
* torecalculate the pager requirement based on vertical output.
12691269
*/
12701270
IsPagerNeeded(cont,0, true,&fout,&is_pager);
12711271

@@ -1400,7 +1400,8 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
14001400
/* Determine width required for record header lines */
14011401
if (!opt_tuples_only)
14021402
{
1403-
rwidth=1+log10(cont->nrows);
1403+
if (cont->nrows>0)
1404+
rwidth=1+ (int)log10(cont->nrows);
14041405
if (opt_border==0)
14051406
rwidth+=9;/* "* RECORD " */
14061407
elseif (opt_border==1)
@@ -1412,33 +1413,46 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
14121413
/* We might need to do the rest of the calculation twice */
14131414
for (;;)
14141415
{
1415-
unsignedintwidth,
1416-
min_width;
1416+
unsignedintwidth;
14171417

14181418
/* Total width required to not wrap data */
14191419
width=hwidth+swidth+dwidth;
1420+
/* ... and not the header lines, either */
1421+
if (width<rwidth)
1422+
width=rwidth;
14201423

1421-
/* Minimum acceptable width: room for just 3 columns of data */
1422-
min_width=hwidth+swidth+3;
1423-
/* ... but not less than what the record header lines need */
1424-
if (rwidth>min_width)
1425-
min_width=rwidth;
1426-
1427-
if (width<min_width||
1428-
(output_columns>0&&output_columns<min_width))
1429-
{
1430-
/* Set data width to match min_width */
1431-
newdwidth=min_width-hwidth-swidth;
1432-
}
1433-
elseif (output_columns>0)
1424+
if (output_columns>0)
14341425
{
1435-
/* Set data width to match output_columns */
1436-
newdwidth=output_columns-hwidth-swidth;
1426+
unsignedintmin_width;
1427+
1428+
/* Minimum acceptable width: room for just 3 columns of data */
1429+
min_width=hwidth+swidth+3;
1430+
/* ... but not less than what the record header lines need */
1431+
if (min_width<rwidth)
1432+
min_width=rwidth;
1433+
1434+
if (output_columns >=width)
1435+
{
1436+
/* Plenty of room, use native data width */
1437+
/* (but at least enough for the record header lines) */
1438+
newdwidth=width-hwidth-swidth;
1439+
}
1440+
elseif (output_columns<min_width)
1441+
{
1442+
/* Set data width to match min_width */
1443+
newdwidth=min_width-hwidth-swidth;
1444+
}
1445+
else
1446+
{
1447+
/* Set data width to match output_columns */
1448+
newdwidth=output_columns-hwidth-swidth;
1449+
}
14371450
}
14381451
else
14391452
{
1440-
/* Use native data width */
1441-
newdwidth=dwidth;
1453+
/* Don't know the wrap limit, so use native data width */
1454+
/* (but at least enough for the record header lines) */
1455+
newdwidth=width-hwidth-swidth;
14421456
}
14431457

14441458
/*

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,34 +2198,34 @@ execute q;
21982198

21992199
\pset format wrapped
22002200
execute q;
2201-
* Record 1
2201+
* Record 1
22022202
0123456789abcdef xx
22032203
0123456789 yyyyyyyyyyyyyyyyyy
2204-
* Record 2
2204+
* Record 2
22052205
0123456789abcdef xxxx
22062206
0123456789 yyyyyyyyyyyyyyyy
2207-
* Record 3
2207+
* Record 3
22082208
0123456789abcdef xxxxxx
22092209
0123456789 yyyyyyyyyyyyyy
2210-
* Record 4
2210+
* Record 4
22112211
0123456789abcdef xxxxxxxx
22122212
0123456789 yyyyyyyyyyyy
2213-
* Record 5
2213+
* Record 5
22142214
0123456789abcdef xxxxxxxxxx
22152215
0123456789 yyyyyyyyyy
2216-
* Record 6
2216+
* Record 6
22172217
0123456789abcdef xxxxxxxxxxxx
22182218
0123456789 yyyyyyyy
2219-
* Record 7
2219+
* Record 7
22202220
0123456789abcdef xxxxxxxxxxxxxx
22212221
0123456789 yyyyyy
2222-
* Record 8
2222+
* Record 8
22232223
0123456789abcdef xxxxxxxxxxxxxxxx
22242224
0123456789 yyyy
2225-
* Record 9
2225+
* Record 9
22262226
0123456789abcdef xxxxxxxxxxxxxxxxxx
22272227
0123456789 yy
2228-
* Record 10
2228+
* Record 10
22292229
0123456789abcdef xxxxxxxxxxxxxxxxxxxx
22302230
0123456789
22312231

@@ -2296,34 +2296,34 @@ execute q;
22962296

22972297
\pset format wrapped
22982298
execute q;
2299-
-[ RECORD 1 ]----+----------------------
2299+
-[ RECORD 1 ]----+---------------------
23002300
0123456789abcdef | xx
23012301
0123456789 | yyyyyyyyyyyyyyyyyy
2302-
-[ RECORD 2 ]----+----------------------
2302+
-[ RECORD 2 ]----+---------------------
23032303
0123456789abcdef | xxxx
23042304
0123456789 | yyyyyyyyyyyyyyyy
2305-
-[ RECORD 3 ]----+----------------------
2305+
-[ RECORD 3 ]----+---------------------
23062306
0123456789abcdef | xxxxxx
23072307
0123456789 | yyyyyyyyyyyyyy
2308-
-[ RECORD 4 ]----+----------------------
2308+
-[ RECORD 4 ]----+---------------------
23092309
0123456789abcdef | xxxxxxxx
23102310
0123456789 | yyyyyyyyyyyy
2311-
-[ RECORD 5 ]----+----------------------
2311+
-[ RECORD 5 ]----+---------------------
23122312
0123456789abcdef | xxxxxxxxxx
23132313
0123456789 | yyyyyyyyyy
2314-
-[ RECORD 6 ]----+----------------------
2314+
-[ RECORD 6 ]----+---------------------
23152315
0123456789abcdef | xxxxxxxxxxxx
23162316
0123456789 | yyyyyyyy
2317-
-[ RECORD 7 ]----+----------------------
2317+
-[ RECORD 7 ]----+---------------------
23182318
0123456789abcdef | xxxxxxxxxxxxxx
23192319
0123456789 | yyyyyy
2320-
-[ RECORD 8 ]----+----------------------
2320+
-[ RECORD 8 ]----+---------------------
23212321
0123456789abcdef | xxxxxxxxxxxxxxxx
23222322
0123456789 | yyyy
2323-
-[ RECORD 9 ]----+----------------------
2323+
-[ RECORD 9 ]----+---------------------
23242324
0123456789abcdef | xxxxxxxxxxxxxxxxxx
23252325
0123456789 | yy
2326-
-[ RECORD 10 ]---+----------------------
2326+
-[ RECORD 10 ]---+---------------------
23272327
0123456789abcdef | xxxxxxxxxxxxxxxxxxxx
23282328
0123456789 |
23292329

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp