Commit 55f927a4 authored by Alvaro Herrera's avatar Alvaro Herrera

Refactor NUM_cache_remove calls in error report path to a PG_TRY block.

The code in the new block was not reindented; it will be fixed by pgindent
eventually.
parent e61fd4ac
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* formatting.c * formatting.c
* *
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.160 2009/08/10 18:29:26 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.161 2009/08/10 20:16:05 alvherre Exp $
* *
* *
* Portions Copyright (c) 1999-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1999-2009, PostgreSQL Global Development Group
...@@ -82,6 +82,7 @@ ...@@ -82,6 +82,7 @@
#include <wctype.h> #include <wctype.h>
#endif #endif
#include "mb/pg_wchar.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/date.h" #include "utils/date.h"
#include "utils/datetime.h" #include "utils/datetime.h"
...@@ -89,7 +90,6 @@ ...@@ -89,7 +90,6 @@
#include "utils/int8.h" #include "utils/int8.h"
#include "utils/numeric.h" #include "utils/numeric.h"
#include "utils/pg_locale.h" #include "utils/pg_locale.h"
#include "mb/pg_wchar.h"
/* ---------- /* ----------
* Routines type * Routines type
...@@ -1046,24 +1046,24 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1046,24 +1046,24 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
if (n->type != NODE_TYPE_ACTION) if (n->type != NODE_TYPE_ACTION)
return; return;
if (IS_EEEE(num) && n->key->id != NUM_E) /*
* In case of an error, we need to remove the numeric from the cache. Use
* a PG_TRY block to ensure that this happens.
*/
PG_TRY();
{ {
NUM_cache_remove(last_NUMCacheEntry); if (IS_EEEE(num) && n->key->id != NUM_E)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"EEEE\" must be the last pattern used"))); errmsg("\"EEEE\" must be the last pattern used")));
}
switch (n->key->id) switch (n->key->id)
{ {
case NUM_9: case NUM_9:
if (IS_BRACKET(num)) if (IS_BRACKET(num))
{
NUM_cache_remove(last_NUMCacheEntry);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"9\" must be ahead of \"PR\""))); errmsg("\"9\" must be ahead of \"PR\"")));
}
if (IS_MULTI(num)) if (IS_MULTI(num))
{ {
++num->multi; ++num->multi;
...@@ -1077,12 +1077,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1077,12 +1077,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
case NUM_0: case NUM_0:
if (IS_BRACKET(num)) if (IS_BRACKET(num))
{
NUM_cache_remove(last_NUMCacheEntry);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"0\" must be ahead of \"PR\""))); errmsg("\"0\" must be ahead of \"PR\"")));
}
if (!IS_ZERO(num) && !IS_DECIMAL(num)) if (!IS_ZERO(num) && !IS_DECIMAL(num))
{ {
num->flag |= NUM_F_ZERO; num->flag |= NUM_F_ZERO;
...@@ -1106,19 +1103,13 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1106,19 +1103,13 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
num->need_locale = TRUE; num->need_locale = TRUE;
case NUM_DEC: case NUM_DEC:
if (IS_DECIMAL(num)) if (IS_DECIMAL(num))
{
NUM_cache_remove(last_NUMCacheEntry);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("multiple decimal points"))); errmsg("multiple decimal points")));
}
if (IS_MULTI(num)) if (IS_MULTI(num))
{
NUM_cache_remove(last_NUMCacheEntry);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"V\" and decimal point together"))); errmsg("cannot use \"V\" and decimal point together")));
}
num->flag |= NUM_F_DECIMAL; num->flag |= NUM_F_DECIMAL;
break; break;
...@@ -1128,19 +1119,13 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1128,19 +1119,13 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
case NUM_S: case NUM_S:
if (IS_LSIGN(num)) if (IS_LSIGN(num))
{
NUM_cache_remove(last_NUMCacheEntry);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" twice"))); errmsg("cannot use \"S\" twice")));
}
if (IS_PLUS(num) || IS_MINUS(num) || IS_BRACKET(num)) if (IS_PLUS(num) || IS_MINUS(num) || IS_BRACKET(num))
{
NUM_cache_remove(last_NUMCacheEntry);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" and \"PL\"/\"MI\"/\"SG\"/\"PR\" together"))); errmsg("cannot use \"S\" and \"PL\"/\"MI\"/\"SG\"/\"PR\" together")));
}
if (!IS_DECIMAL(num)) if (!IS_DECIMAL(num))
{ {
num->lsign = NUM_LSIGN_PRE; num->lsign = NUM_LSIGN_PRE;
...@@ -1158,12 +1143,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1158,12 +1143,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
case NUM_MI: case NUM_MI:
if (IS_LSIGN(num)) if (IS_LSIGN(num))
{
NUM_cache_remove(last_NUMCacheEntry);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" and \"MI\" together"))); errmsg("cannot use \"S\" and \"MI\" together")));
}
num->flag |= NUM_F_MINUS; num->flag |= NUM_F_MINUS;
if (IS_DECIMAL(num)) if (IS_DECIMAL(num))
num->flag |= NUM_F_MINUS_POST; num->flag |= NUM_F_MINUS_POST;
...@@ -1171,12 +1153,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1171,12 +1153,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
case NUM_PL: case NUM_PL:
if (IS_LSIGN(num)) if (IS_LSIGN(num))
{
NUM_cache_remove(last_NUMCacheEntry);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" and \"PL\" together"))); errmsg("cannot use \"S\" and \"PL\" together")));
}
num->flag |= NUM_F_PLUS; num->flag |= NUM_F_PLUS;
if (IS_DECIMAL(num)) if (IS_DECIMAL(num))
num->flag |= NUM_F_PLUS_POST; num->flag |= NUM_F_PLUS_POST;
...@@ -1184,24 +1163,18 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1184,24 +1163,18 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
case NUM_SG: case NUM_SG:
if (IS_LSIGN(num)) if (IS_LSIGN(num))
{
NUM_cache_remove(last_NUMCacheEntry);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"S\" and \"SG\" together"))); errmsg("cannot use \"S\" and \"SG\" together")));
}
num->flag |= NUM_F_MINUS; num->flag |= NUM_F_MINUS;
num->flag |= NUM_F_PLUS; num->flag |= NUM_F_PLUS;
break; break;
case NUM_PR: case NUM_PR:
if (IS_LSIGN(num) || IS_PLUS(num) || IS_MINUS(num)) if (IS_LSIGN(num) || IS_PLUS(num) || IS_MINUS(num))
{
NUM_cache_remove(last_NUMCacheEntry);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"PR\" and \"S\"/\"PL\"/\"MI\"/\"SG\" together"))); errmsg("cannot use \"PR\" and \"S\"/\"PL\"/\"MI\"/\"SG\" together")));
}
num->flag |= NUM_F_BRACKET; num->flag |= NUM_F_BRACKET;
break; break;
...@@ -1217,36 +1190,35 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n) ...@@ -1217,36 +1190,35 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
case NUM_V: case NUM_V:
if (IS_DECIMAL(num)) if (IS_DECIMAL(num))
{
NUM_cache_remove(last_NUMCacheEntry);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"V\" and decimal point together"))); errmsg("cannot use \"V\" and decimal point together")));
}
num->flag |= NUM_F_MULTI; num->flag |= NUM_F_MULTI;
break; break;
case NUM_E: case NUM_E:
if (IS_EEEE(num)) if (IS_EEEE(num))
{
NUM_cache_remove(last_NUMCacheEntry);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("cannot use \"EEEE\" twice"))); errmsg("cannot use \"EEEE\" twice")));
}
if (IS_BLANK(num) || IS_FILLMODE(num) || IS_LSIGN(num) || if (IS_BLANK(num) || IS_FILLMODE(num) || IS_LSIGN(num) ||
IS_BRACKET(num) || IS_MINUS(num) || IS_PLUS(num) || IS_BRACKET(num) || IS_MINUS(num) || IS_PLUS(num) ||
IS_ROMAN(num) || IS_MULTI(num)) IS_ROMAN(num) || IS_MULTI(num))
{
NUM_cache_remove(last_NUMCacheEntry);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("\"EEEE\" is incompatible with other formats"), errmsg("\"EEEE\" is incompatible with other formats"),
errdetail("\"EEEE\" may only be used together with digit and decimal point patterns."))); errdetail("\"EEEE\" may only be used together with digit and decimal point patterns.")));
}
num->flag |= NUM_F_EEEE; num->flag |= NUM_F_EEEE;
break; break;
} }
}
PG_CATCH();
{
NUM_cache_remove(last_NUMCacheEntry);
PG_RE_THROW();
}
PG_END_TRY();
return; return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment