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

Commiteaf746a

Browse files
committed
Make psql's "\pset format" command reject non-unique abbreviations.
The previous behavior of preferring the oldest match had the advantageof not breaking existing scripts when we add a conflicting format name;but that behavior was undocumented and fragile (it seems just luck thatcommitadd9182 didn't break it). Let's go over to the less mistake-prone approach of complaining when there are multiple matches.Since this is a small compatibility break, no back-patch.Daniel VéritéDiscussion:https://postgr.es/m/cb7e1caf-3ea6-450d-af28-f524903a030c@manitou-mail.org
1 parent51eaaaf commiteaf746a

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

‎src/bin/psql/command.c

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3637,28 +3637,51 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
36373637
/* set format */
36383638
if (strcmp(param,"format")==0)
36393639
{
3640+
staticconststructfmt
3641+
{
3642+
constchar*name;
3643+
enumprintFormatnumber;
3644+
}formats[]=
3645+
{
3646+
/* remember to update error message below when adding more */
3647+
{"aligned",PRINT_ALIGNED},
3648+
{"asciidoc",PRINT_ASCIIDOC},
3649+
{"html",PRINT_HTML},
3650+
{"latex",PRINT_LATEX},
3651+
{"latex-longtable",PRINT_LATEX_LONGTABLE},
3652+
{"troff-ms",PRINT_TROFF_MS},
3653+
{"unaligned",PRINT_UNALIGNED},
3654+
{"wrapped",PRINT_WRAPPED}
3655+
};
3656+
36403657
if (!value)
36413658
;
3642-
elseif (pg_strncasecmp("aligned",value,vallen)==0)
3643-
popt->topt.format=PRINT_ALIGNED;
3644-
elseif (pg_strncasecmp("asciidoc",value,vallen)==0)
3645-
popt->topt.format=PRINT_ASCIIDOC;
3646-
elseif (pg_strncasecmp("html",value,vallen)==0)
3647-
popt->topt.format=PRINT_HTML;
3648-
elseif (pg_strncasecmp("latex",value,vallen)==0)
3649-
popt->topt.format=PRINT_LATEX;
3650-
elseif (pg_strncasecmp("latex-longtable",value,vallen)==0)
3651-
popt->topt.format=PRINT_LATEX_LONGTABLE;
3652-
elseif (pg_strncasecmp("troff-ms",value,vallen)==0)
3653-
popt->topt.format=PRINT_TROFF_MS;
3654-
elseif (pg_strncasecmp("unaligned",value,vallen)==0)
3655-
popt->topt.format=PRINT_UNALIGNED;
3656-
elseif (pg_strncasecmp("wrapped",value,vallen)==0)
3657-
popt->topt.format=PRINT_WRAPPED;
36583659
else
36593660
{
3660-
psql_error("\\pset: allowed formats are aligned, asciidoc, html, latex, latex-longtable, troff-ms, unaligned, wrapped\n");
3661-
return false;
3661+
intmatch_pos=-1;
3662+
3663+
for (inti=0;i<lengthof(formats);i++)
3664+
{
3665+
if (pg_strncasecmp(formats[i].name,value,vallen)==0)
3666+
{
3667+
if (match_pos<0)
3668+
match_pos=i;
3669+
else
3670+
{
3671+
psql_error("\\pset: ambiguous abbreviation \"%s\" matches both \"%s\" and \"%s\"\n",
3672+
value,
3673+
formats[match_pos].name,formats[i].name);
3674+
return false;
3675+
}
3676+
}
3677+
}
3678+
if (match_pos<0)
3679+
{
3680+
psql_error("\\pset: allowed formats are aligned, asciidoc, html, latex, latex-longtable, troff-ms, unaligned, wrapped\n");
3681+
return false;
3682+
}
3683+
else
3684+
popt->topt.format=formats[match_pos].number;
36623685
}
36633686
}
36643687

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp