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

Commit91c5a8c

Browse files
committed
Add errhint_plural() function and make use of it
Similar to existing errmsg_plural() and errdetail_plural(). Someerrhint() calls hadn't received the proper plural treatment yet.
1 parent287d2a9 commit91c5a8c

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

‎doc/src/sgml/sources.sgml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ ereport(ERROR,
282282
<function>errmsg</function>.
283283
</para>
284284
</listitem>
285+
<listitem>
286+
<para>
287+
<function>errhint_plural(const char *fmt_singular, const char *fmt_plural,
288+
unsigned long n, ...)</function> is like <function>errhint</function>, but with
289+
support for various plural forms of the message.
290+
For more information see <xref linkend="nls-guidelines"/>.
291+
</para>
292+
</listitem>
285293
<listitem>
286294
<para>
287295
<function>errcontext(const char *msg, ...)</function> is not normally called

‎src/backend/parser/parse_func.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
417417
func_signature_string(funcname,nargs,
418418
argnames,
419419
actual_arg_types)),
420-
errhint("There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
421-
NameListToString(funcname),
422-
catDirectArgs,numDirectArgs),
420+
errhint_plural("There is an ordered-set aggregate %s, but it requires %d direct argument, not %d.",
421+
"There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
422+
catDirectArgs,
423+
NameListToString(funcname),
424+
catDirectArgs,numDirectArgs),
423425
parser_errposition(pstate,location)));
424426
}
425427
else
@@ -446,9 +448,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
446448
func_signature_string(funcname,nargs,
447449
argnames,
448450
actual_arg_types)),
449-
errhint("There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
450-
NameListToString(funcname),
451-
catDirectArgs,numDirectArgs),
451+
errhint_plural("There is an ordered-set aggregate %s, but it requires %d direct argument, not %d.",
452+
"There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
453+
catDirectArgs,
454+
NameListToString(funcname),
455+
catDirectArgs,numDirectArgs),
452456
parser_errposition(pstate,location)));
453457
}
454458
else
@@ -485,9 +489,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
485489
func_signature_string(funcname,nargs,
486490
argnames,
487491
actual_arg_types)),
488-
errhint("There is an ordered-set aggregate %s, but it requires at least %d direct arguments.",
489-
NameListToString(funcname),
490-
catDirectArgs),
492+
errhint_plural("There is an ordered-set aggregate %s, but it requires at least %d direct argument.",
493+
"There is an ordered-set aggregate %s, but it requires at least %d direct arguments.",
494+
catDirectArgs,
495+
NameListToString(funcname),
496+
catDirectArgs),
491497
parser_errposition(pstate,location)));
492498
}
493499
}

‎src/backend/utils/error/elog.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,29 @@ errhint(const char *fmt,...)
11661166
}
11671167

11681168

1169+
/*
1170+
* errhint_plural --- add a hint error message text to the current error,
1171+
* with support for pluralization of the message text
1172+
*/
1173+
int
1174+
errhint_plural(constchar*fmt_singular,constchar*fmt_plural,
1175+
unsigned longn,...)
1176+
{
1177+
ErrorData*edata=&errordata[errordata_stack_depth];
1178+
MemoryContextoldcontext;
1179+
1180+
recursion_depth++;
1181+
CHECK_STACK_DEPTH();
1182+
oldcontext=MemoryContextSwitchTo(edata->assoc_context);
1183+
1184+
EVALUATE_MESSAGE_PLURAL(edata->domain,hint, false);
1185+
1186+
MemoryContextSwitchTo(oldcontext);
1187+
recursion_depth--;
1188+
return0;/* return value does not matter */
1189+
}
1190+
1191+
11691192
/*
11701193
* errcontext_msg --- add a context error message text to the current error
11711194
*

‎src/include/utils/elog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ extern interrdetail_plural(const char *fmt_singular, const char *fmt_plural,
188188

189189
externinterrhint(constchar*fmt,...)pg_attribute_printf(1,2);
190190

191+
externinterrhint_plural(constchar*fmt_singular,constchar*fmt_plural,
192+
unsigned longn,...)pg_attribute_printf(1,4)pg_attribute_printf(2,4);
193+
191194
/*
192195
* errcontext() is typically called in error context callback functions, not
193196
* within an ereport() invocation. The callback function can be in a different

‎src/nls-global.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ BACKEND_COMMON_GETTEXT_TRIGGERS = \
5757
$(FRONTEND_COMMON_GETTEXT_TRIGGERS)\
5858
errmsg errmsg_plural:1,2\
5959
errdetail errdetail_log errdetail_plural:1,2\
60-
errhint\
60+
errhinterrhint_plural:1,2\
6161
errcontext\
6262
XactLockTableWait:4\
6363
MultiXactIdWait:6\
@@ -66,7 +66,7 @@ BACKEND_COMMON_GETTEXT_FLAGS = \
6666
$(FRONTEND_COMMON_GETTEXT_FLAGS)\
6767
errmsg:1:c-format errmsg_plural:1:c-format errmsg_plural:2:c-format\
6868
errdetail:1:c-format errdetail_log:1:c-format errdetail_plural:1:c-format errdetail_plural:2:c-format\
69-
errhint:1:c-format\
69+
errhint:1:c-formaterrhint_plural:1:c-format errhint_plural:2:c-format\
7070
errcontext:1:c-format
7171

7272
FRONTEND_COMMON_GETTEXT_FILES =$(top_srcdir)/src/common/logging.c

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp