diff options
| author | Tom Lane | 2009-06-04 18:33:08 +0000 |
|---|---|---|
| committer | Tom Lane | 2009-06-04 18:33:08 +0000 |
| commit | 76d4abf2d974ffa578ddc7ff40984cc05c1d48b1 (patch) | |
| tree | c3f8bab555f06d141026d34df4c7402f279f8ab8 /src/pl | |
| parent | fd416db406f9efdbbdbd7b63ea4f9ccf47eec8b3 (diff) | |
Improve the recently-added support for properly pluralized error messages
by extending the ereport() API to cater for pluralization directly. This
is better than the original method of calling ngettext outside the elog.c
code because (1) it avoids double translation, which wastes cycles and in
the worst case could give a wrong result; and (2) it avoids having to use
a different coding method in PL code than in the core backend. The
client-side uses of ngettext are not touched since neither of these concerns
is very pressing in the client environment. Per my proposal of yesterday.
Diffstat (limited to 'src/pl')
| -rw-r--r-- | src/pl/plperl/nls.mk | 4 | ||||
| -rw-r--r-- | src/pl/plpgsql/src/nls.mk | 4 | ||||
| -rw-r--r-- | src/pl/plpgsql/src/pl_exec.c | 10 | ||||
| -rw-r--r-- | src/pl/plpython/nls.mk | 4 | ||||
| -rw-r--r-- | src/pl/plpython/plpython.c | 42 | ||||
| -rw-r--r-- | src/pl/tcl/nls.mk | 4 |
6 files changed, 48 insertions, 20 deletions
diff --git a/src/pl/plperl/nls.mk b/src/pl/plperl/nls.mk index 8eaf6dd773f..030886c0bb9 100644 --- a/src/pl/plperl/nls.mk +++ b/src/pl/plperl/nls.mk @@ -1,5 +1,5 @@ -# $PostgreSQL: pgsql/src/pl/plperl/nls.mk,v 1.5 2009/05/14 21:41:53 alvherre Exp $ +# $PostgreSQL: pgsql/src/pl/plperl/nls.mk,v 1.6 2009/06/04 18:33:07 tgl Exp $ CATALOG_NAME := plperl AVAIL_LANGUAGES := de es fr pt_BR tr GETTEXT_FILES := plperl.c SPI.c -GETTEXT_TRIGGERS:= errmsg errdetail errdetail_log errhint errcontext +GETTEXT_TRIGGERS:= errmsg errmsg_plural:1,2 errdetail errdetail_log errdetail_plural:1,2 errhint errcontext diff --git a/src/pl/plpgsql/src/nls.mk b/src/pl/plpgsql/src/nls.mk index 7f17b88eece..ffebf4b21e9 100644 --- a/src/pl/plpgsql/src/nls.mk +++ b/src/pl/plpgsql/src/nls.mk @@ -1,8 +1,8 @@ -# $PostgreSQL: pgsql/src/pl/plpgsql/src/nls.mk,v 1.7 2009/05/14 21:41:53 alvherre Exp $ +# $PostgreSQL: pgsql/src/pl/plpgsql/src/nls.mk,v 1.8 2009/06/04 18:33:07 tgl Exp $ CATALOG_NAME := plpgsql AVAIL_LANGUAGES := de es fr ja ro tr GETTEXT_FILES := pl_comp.c pl_exec.c pl_gram.c pl_funcs.c pl_handler.c pl_scan.c -GETTEXT_TRIGGERS:= _ errmsg errdetail errdetail_log errhint errcontext validate_tupdesc_compat:3 yyerror plpgsql_yyerror +GETTEXT_TRIGGERS:= _ errmsg errmsg_plural:1,2 errdetail errdetail_log errdetail_plural:1,2 errhint errcontext validate_tupdesc_compat:3 yyerror plpgsql_yyerror .PHONY: gettext-files gettext-files: distprep diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index e436e053b1b..b5f00069188 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.241 2009/05/02 17:27:57 tgl Exp $ + * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.242 2009/06/04 18:33:07 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -4083,9 +4083,11 @@ exec_eval_expr(PLpgSQL_execstate *estate, if (estate->eval_tuptable->tupdesc->natts != 1) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg(dngettext(TEXTDOMAIN, "query \"%s\" returned %d column", "query \"%s\" returned %d columns", estate->eval_tuptable->tupdesc->natts), - expr->query, - estate->eval_tuptable->tupdesc->natts))); + errmsg_plural("query \"%s\" returned %d column", + "query \"%s\" returned %d columns", + estate->eval_tuptable->tupdesc->natts, + expr->query, + estate->eval_tuptable->tupdesc->natts))); /* * Return the result and its type diff --git a/src/pl/plpython/nls.mk b/src/pl/plpython/nls.mk index 5721dbf445e..6e54a353120 100644 --- a/src/pl/plpython/nls.mk +++ b/src/pl/plpython/nls.mk @@ -1,5 +1,5 @@ -# $PostgreSQL: pgsql/src/pl/plpython/nls.mk,v 1.4 2009/05/14 21:41:53 alvherre Exp $ +# $PostgreSQL: pgsql/src/pl/plpython/nls.mk,v 1.5 2009/06/04 18:33:08 tgl Exp $ CATALOG_NAME := plpython AVAIL_LANGUAGES := de es fr pt_BR tr GETTEXT_FILES := plpython.c -GETTEXT_TRIGGERS:= errmsg errdetail errdetail_log errhint errcontext PLy_elog:2 PLy_exception_set:2 +GETTEXT_TRIGGERS:= errmsg errmsg_plural:1,2 errdetail errdetail_log errdetail_plural:1,2 errhint errcontext PLy_elog:2 PLy_exception_set:2 PLy_exception_set_plural:2,3 diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c index 61e4772e8bc..345f3f65236 100644 --- a/src/pl/plpython/plpython.c +++ b/src/pl/plpython/plpython.c @@ -1,7 +1,7 @@ /********************************************************************** * plpython.c - python as a procedural language for PostgreSQL * - * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.120 2009/04/03 16:59:42 tgl Exp $ + * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.121 2009/06/04 18:33:08 tgl Exp $ * ********************************************************************* */ @@ -205,9 +205,13 @@ static void PLy_init_interp(void); static void PLy_init_plpy(void); /* call PyErr_SetString with a vprint interface and translation support */ -static void -PLy_exception_set(PyObject *, const char *,...) +static void PLy_exception_set(PyObject *, const char *,...) __attribute__((format(printf, 2, 3))); +/* same, with pluralized message */ +static void PLy_exception_set_plural(PyObject *, const char *, const char *, + unsigned long n,...) +__attribute__((format(printf, 2, 5))) +__attribute__((format(printf, 3, 5))); /* Get the innermost python procedure called from the backend */ static char *PLy_procedure_name(PLyProcedure *); @@ -2525,9 +2529,11 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, long limit) PLy_elog(ERROR, "PL/Python function \"%s\" could not execute plan", PLy_procedure_name(PLy_curr_procedure)); sv = PyString_AsString(so); - PLy_exception_set(PLy_exc_spi_error, - dngettext(TEXTDOMAIN, "Expected sequence of %d argument, got %d: %s", "Expected sequence of %d arguments, got %d: %s", plan->nargs), - plan->nargs, nargs, sv); + PLy_exception_set_plural(PLy_exc_spi_error, + "Expected sequence of %d argument, got %d: %s", + "Expected sequence of %d arguments, got %d: %s", + plan->nargs, + plan->nargs, nargs, sv); Py_DECREF(so); return NULL; @@ -2941,8 +2947,8 @@ PLy_procedure_name(PLyProcedure * proc) return proc->proname; } -/* output a python traceback/exception via the postgresql elog - * function. not pretty. +/* + * Call PyErr_SetString with a vprint interface and translation support */ static void PLy_exception_set(PyObject * exc, const char *fmt,...) @@ -2957,6 +2963,26 @@ PLy_exception_set(PyObject * exc, const char *fmt,...) PyErr_SetString(exc, buf); } +/* + * The same, pluralized. + */ +static void +PLy_exception_set_plural(PyObject *exc, + const char *fmt_singular, const char *fmt_plural, + unsigned long n,...) +{ + char buf[1024]; + va_list ap; + + va_start(ap, n); + vsnprintf(buf, sizeof(buf), + dngettext(TEXTDOMAIN, fmt_singular, fmt_plural, n), + ap); + va_end(ap); + + PyErr_SetString(exc, buf); +} + /* Emit a PG error or notice, together with any available info about the * current Python error. This should be used to propagate Python errors * into PG. diff --git a/src/pl/tcl/nls.mk b/src/pl/tcl/nls.mk index 9188911f762..f331e658a98 100644 --- a/src/pl/tcl/nls.mk +++ b/src/pl/tcl/nls.mk @@ -1,5 +1,5 @@ -# $PostgreSQL: pgsql/src/pl/tcl/nls.mk,v 1.4 2009/05/14 21:41:53 alvherre Exp $ +# $PostgreSQL: pgsql/src/pl/tcl/nls.mk,v 1.5 2009/06/04 18:33:08 tgl Exp $ CATALOG_NAME := pltcl AVAIL_LANGUAGES := de es fr pt_BR tr GETTEXT_FILES := pltcl.c -GETTEXT_TRIGGERS:= errmsg errdetail errdetail_log errhint errcontext +GETTEXT_TRIGGERS:= errmsg errmsg_plural:1,2 errdetail errdetail_log errdetail_plural:1,2 errhint errcontext |
