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

Commit7e81c4b

Browse files
committed
Revert psql changes to support wrapped expanded mode. That feature is
nice and we'll keep it in 9.5 but it'll take more time to iron out thecollateral damage on other queries and also on tools likecheck_postgres.revertdbe3161revert6513633
1 parentf304ddc commit7e81c4b

File tree

3 files changed

+23
-1232
lines changed

3 files changed

+23
-1232
lines changed

‎src/bin/psql/print.c

Lines changed: 23 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,6 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
11611161
structlineptr*hlineptr,
11621162
*dlineptr;
11631163
boolis_pager= false;
1164-
intoutput_columns=0;/* Width of interactive console */
11651164

11661165
if (cancel_pressed)
11671166
return;
@@ -1235,90 +1234,24 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
12351234
fprintf(fout,"%s\n",cont->title);
12361235
}
12371236

1238-
/*
1239-
* Choose target output width: \pset columns, or $COLUMNS, or ioctl
1240-
*/
1241-
if (cont->opt->columns>0)
1242-
output_columns=cont->opt->columns;
1243-
elseif ((fout==stdout&&isatty(fileno(stdout)))||is_pager)
1244-
{
1245-
if (cont->opt->env_columns>0)
1246-
output_columns=cont->opt->env_columns;
1247-
#ifdefTIOCGWINSZ
1248-
else
1249-
{
1250-
structwinsizescreen_size;
1251-
1252-
if (ioctl(fileno(stdout),TIOCGWINSZ,&screen_size)!=-1)
1253-
output_columns=screen_size.ws_col;
1254-
}
1255-
#endif
1256-
}
1257-
1258-
if (cont->opt->format==PRINT_WRAPPED)
1259-
{
1260-
/*
1261-
* Calculate the available width to wrap the columns to after
1262-
* subtracting the maximum header width and separators. At a minimum
1263-
* enough to print "[ RECORD N ]"
1264-
*/
1265-
unsignedintwidth,
1266-
swidth;
1267-
1268-
if (opt_border==0)
1269-
swidth=1;/* "header data" */
1270-
elseif (opt_border==1)
1271-
swidth=3;/* "header | data" */
1272-
else
1273-
swidth=7;/* "| header | data |" */
1274-
1275-
/* Wrap to maximum width */
1276-
width=dwidth+swidth+hwidth;
1277-
if ((output_columns>0)&& (width>output_columns))
1278-
{
1279-
dwidth=output_columns-hwidth-swidth;
1280-
width=output_columns;
1281-
}
1282-
1283-
/* Wrap to minimum width */
1284-
if (!opt_tuples_only)
1285-
{
1286-
intdelta=1+log10(cont->nrows)-width;
1287-
1288-
if (opt_border==0)
1289-
delta+=6;/* "* RECORD " */
1290-
elseif (opt_border==1)
1291-
delta+=10;/* "-[ RECORD ]" */
1292-
else
1293-
delta+=15;/* "+-[ RECORD ]-+" */
1294-
1295-
if (delta>0)
1296-
dwidth+=delta;
1297-
}
1298-
elseif (dwidth<3)
1299-
dwidth=3;
1300-
}
1301-
13021237
/* print records */
13031238
for (i=0,ptr=cont->cells;*ptr;i++,ptr++)
13041239
{
13051240
printTextRulepos;
1306-
intdline,
1307-
hline,
1241+
intline_count,
13081242
dcomplete,
1309-
hcomplete,
1310-
offset,
1311-
chars_to_output;
1243+
hcomplete;
13121244

13131245
if (cancel_pressed)
13141246
break;
13151247

13161248
if (i==0)
13171249
pos=PRINT_RULE_TOP;
1250+
elseif (!(*(ptr+1)))
1251+
pos=PRINT_RULE_BOTTOM;
13181252
else
13191253
pos=PRINT_RULE_MIDDLE;
13201254

1321-
/* Print record header (e.g. "[ RECORD N ]") above each record */
13221255
if (i %cont->ncolumns==0)
13231256
{
13241257
if (!opt_tuples_only)
@@ -1337,126 +1270,48 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
13371270
pg_wcsformat((constunsignedchar*)*ptr,strlen(*ptr),encoding,
13381271
dlineptr,dheight);
13391272

1340-
/*
1341-
* Loop through header and data in parallel dealing with newlines and
1342-
* wrapped lines until they're both exhausted
1343-
*/
1344-
dline=hline=0;
1273+
line_count=0;
13451274
dcomplete=hcomplete=0;
1346-
offset=0;
1347-
chars_to_output=dlineptr[dline].width;
13481275
while (!dcomplete|| !hcomplete)
13491276
{
1350-
/* Left border */
13511277
if (opt_border==2)
1352-
fprintf(fout,"%s",dformat->leftvrule);
1353-
1354-
/* Header (never wrapped so just need to deal with newlines) */
1278+
fprintf(fout,"%s ",dformat->leftvrule);
13551279
if (!hcomplete)
13561280
{
1357-
intswidth,
1358-
twidth=hwidth+1;
1359-
1360-
fputs(hline ?format->header_nl_left :" ",fout);
1361-
strlen_max_width(hlineptr[hline].ptr,&twidth,
1362-
encoding);
1363-
fprintf(fout,"%-s",hlineptr[hline].ptr);
1364-
1365-
swidth=hwidth-twidth;
1366-
if (swidth>0)/* spacer */
1367-
fprintf(fout,"%*s",swidth," ");
1281+
fprintf(fout,"%-s%*s",hlineptr[line_count].ptr,
1282+
hwidth-hlineptr[line_count].width,"");
13681283

1369-
if (hlineptr[hline+1].ptr)
1370-
{
1371-
/* More lines after this one due to a newline */
1372-
fputs(format->header_nl_right,fout);
1373-
hline++;
1374-
}
1375-
else
1376-
{
1377-
/* This was the last line of the header */
1378-
fputs(" ",fout);
1284+
if (!hlineptr[line_count+1].ptr)
13791285
hcomplete=1;
1380-
}
13811286
}
13821287
else
1383-
{
1384-
/* Header exhausted but more data for column */
1385-
fprintf(fout,"%*s",hwidth+2,"");
1386-
}
1288+
fprintf(fout,"%*s",hwidth,"");
13871289

1388-
/* Separator */
13891290
if (opt_border>0)
1390-
{
1391-
if (offset)
1392-
fputs(format->midvrule_wrap,fout);
1393-
elseif (!dline)
1394-
fputs(dformat->midvrule,fout);
1395-
elseif (dline)
1396-
fputs(format->midvrule_nl,fout);
1397-
else
1398-
fputs(format->midvrule_blank,fout);
1399-
}
1291+
fprintf(fout," %s ",dformat->midvrule);
1292+
else
1293+
fputc(' ',fout);
14001294

1401-
/* Data */
14021295
if (!dcomplete)
14031296
{
1404-
inttarget_width,
1405-
bytes_to_output,
1406-
swidth;
1407-
1408-
fputs(!dcomplete&& !offset ?" " :format->wrap_left,fout);
1409-
1410-
target_width=dwidth;
1411-
bytes_to_output=strlen_max_width(dlineptr[dline].ptr+offset,
1412-
&target_width,encoding);
1413-
fputnbytes(fout, (char*) (dlineptr[dline].ptr+offset),
1414-
bytes_to_output);
1415-
1416-
chars_to_output-=target_width;
1417-
offset+=bytes_to_output;
1418-
1419-
/* spacer */
1420-
swidth=dwidth-target_width;
1421-
if (swidth>0)
1422-
fprintf(fout,"%*s",swidth,"");
1423-
1424-
if (chars_to_output)
1425-
{
1426-
/* continuing a wrapped column */
1427-
fputs(format->wrap_right,fout);
1428-
}
1429-
elseif (dlineptr[dline+1].ptr)
1430-
{
1431-
/* reached a newline in the column */
1432-
fputs(format->nl_right,fout);
1433-
dline++;
1434-
offset=0;
1435-
chars_to_output=dlineptr[dline].width;
1436-
}
1297+
if (opt_border<2)
1298+
fprintf(fout,"%s\n",dlineptr[line_count].ptr);
14371299
else
1438-
{
1439-
/* reached the end of the cell */
1440-
fputs(" ",fout);
1441-
dcomplete=1;
1442-
}
1443-
1444-
if (opt_border==2)
1445-
fputs(dformat->rightvrule,fout);
1300+
fprintf(fout,"%-s%*s %s\n",dlineptr[line_count].ptr,
1301+
dwidth-dlineptr[line_count].width,"",
1302+
dformat->rightvrule);
14461303

1447-
fputs("\n",fout);
1304+
if (!dlineptr[line_count+1].ptr)
1305+
dcomplete=1;
14481306
}
14491307
else
14501308
{
1451-
/*
1452-
* data exhausted (this can occur if header is longer than the
1453-
* data due to newlines in the header)
1454-
*/
14551309
if (opt_border<2)
1456-
fputs("\n",fout);
1310+
fputc('\n',fout);
14571311
else
1458-
fprintf(fout,"%*s%s\n",dwidth,"",dformat->rightvrule);
1312+
fprintf(fout,"%*s %s\n",dwidth,"",dformat->rightvrule);
14591313
}
1314+
line_count++;
14601315
}
14611316
}
14621317

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp