git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 287d2a9)
Add errhint_plural() function and make use of it
2021年3月31日 07:15:51 +0000 (09:15 +0200)
2021年3月31日 07:16:25 +0000 (09:16 +0200)
Similar to existing errmsg_plural() and errdetail_plural(). Some
errhint() calls hadn't received the proper plural treatment yet.


diff --git a/doc/src/sgml/sources.sgml b/doc/src/sgml/sources.sgml
index 62cf2fded401a6a8697dea075e872685a68dd153..3f2c40b7509167131be60ee292e56e01a6434ae9 100644 (file)
--- a/doc/src/sgml/sources.sgml
+++ b/doc/src/sgml/sources.sgml
@@ -282,6 +282,14 @@ ereport(ERROR,
<function>errmsg</function>.
</para>
</listitem>
+ <listitem>
+ <para>
+ <function>errhint_plural(const char *fmt_singular, const char *fmt_plural,
+ unsigned long n, ...)</function> is like <function>errhint</function>, but with
+ support for various plural forms of the message.
+ For more information see <xref linkend="nls-guidelines"/>.
+ </para>
+ </listitem>
<listitem>
<para>
<function>errcontext(const char *msg, ...)</function> is not normally called
diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c
index debef1d14fba1adb0d50b6cd256fc76e1c0ce0e7..baac089d68915b9bb0570c433a765b94c1e1a1e4 100644 (file)
--- a/src/backend/parser/parse_func.c
+++ b/src/backend/parser/parse_func.c
@@ -417,9 +417,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
func_signature_string(funcname, nargs,
argnames,
actual_arg_types)),
- errhint("There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
- NameListToString(funcname),
- catDirectArgs, numDirectArgs),
+ errhint_plural("There is an ordered-set aggregate %s, but it requires %d direct argument, not %d.",
+ "There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
+ catDirectArgs,
+ NameListToString(funcname),
+ catDirectArgs, numDirectArgs),
parser_errposition(pstate, location)));
}
else
@@ -446,9 +448,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
func_signature_string(funcname, nargs,
argnames,
actual_arg_types)),
- errhint("There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
- NameListToString(funcname),
- catDirectArgs, numDirectArgs),
+ errhint_plural("There is an ordered-set aggregate %s, but it requires %d direct argument, not %d.",
+ "There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
+ catDirectArgs,
+ NameListToString(funcname),
+ catDirectArgs, numDirectArgs),
parser_errposition(pstate, location)));
}
else
@@ -485,9 +489,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
func_signature_string(funcname, nargs,
argnames,
actual_arg_types)),
- errhint("There is an ordered-set aggregate %s, but it requires at least %d direct arguments.",
- NameListToString(funcname),
- catDirectArgs),
+ errhint_plural("There is an ordered-set aggregate %s, but it requires at least %d direct argument.",
+ "There is an ordered-set aggregate %s, but it requires at least %d direct arguments.",
+ catDirectArgs,
+ NameListToString(funcname),
+ catDirectArgs),
parser_errposition(pstate, location)));
}
}
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index e729ebece7b949442c6ec9fca878562a6cadf076..9e4ea1b345a8b25079ec971a224e7596d50c6edc 100644 (file)
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -1166,6 +1166,29 @@ errhint(const char *fmt,...)
}
+/*
+ * errhint_plural --- add a hint error message text to the current error,
+ * with support for pluralization of the message text
+ */
+int
+errhint_plural(const char *fmt_singular, const char *fmt_plural,
+ unsigned long n,...)
+{
+ ErrorData *edata = &errordata[errordata_stack_depth];
+ MemoryContext oldcontext;
+
+ recursion_depth++;
+ CHECK_STACK_DEPTH();
+ oldcontext = MemoryContextSwitchTo(edata->assoc_context);
+
+ EVALUATE_MESSAGE_PLURAL(edata->domain, hint, false);
+
+ MemoryContextSwitchTo(oldcontext);
+ recursion_depth--;
+ return 0; /* return value does not matter */
+}
+
+
/*
* errcontext_msg --- add a context error message text to the current error
*
diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h
index b59651289e47ba570d767c7f4bb9a91d8af4651f..9acb57a27b542ec76a0755cd3285c102bac6c329 100644 (file)
--- a/src/include/utils/elog.h
+++ b/src/include/utils/elog.h
@@ -188,6 +188,9 @@ extern int errdetail_plural(const char *fmt_singular, const char *fmt_plural,
extern int errhint(const char *fmt,...) pg_attribute_printf(1, 2);
+extern int errhint_plural(const char *fmt_singular, const char *fmt_plural,
+ unsigned long n,...) pg_attribute_printf(1, 4) pg_attribute_printf(2, 4);
+
/*
* errcontext() is typically called in error context callback functions, not
* within an ereport() invocation. The callback function can be in a different
diff --git a/src/nls-global.mk b/src/nls-global.mk
index 30b40ffe2aba6abb725151618367e162307e1ebe..53129f0a04eb0743a45aed0c23bbd1f936157322 100644 (file)
--- a/src/nls-global.mk
+++ b/src/nls-global.mk
@@ -57,7 +57,7 @@ BACKEND_COMMON_GETTEXT_TRIGGERS = \
$(FRONTEND_COMMON_GETTEXT_TRIGGERS) \
errmsg errmsg_plural:1,2 \
errdetail errdetail_log errdetail_plural:1,2 \
- errhint \
+ errhint errhint_plural:1,2 \
errcontext \
XactLockTableWait:4 \
MultiXactIdWait:6 \
@@ -66,7 +66,7 @@ BACKEND_COMMON_GETTEXT_FLAGS = \
$(FRONTEND_COMMON_GETTEXT_FLAGS) \
errmsg:1:c-format errmsg_plural:1:c-format errmsg_plural:2:c-format \
errdetail:1:c-format errdetail_log:1:c-format errdetail_plural:1:c-format errdetail_plural:2:c-format \
- errhint:1:c-format \
+ errhint:1:c-format errhint_plural:1:c-format errhint_plural:2:c-format \
errcontext:1:c-format
FRONTEND_COMMON_GETTEXT_FILES = $(top_srcdir)/src/common/logging.c
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /