1
1
/* -----------------------------------------------------------------------
2
2
* formatting.c
3
3
*
4
- * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.160 2009/08/10 18:29:26 tgl Exp $
4
+ * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.161 2009/08/10 20:16:05 alvherre Exp $
5
5
*
6
6
*
7
7
* Portions Copyright (c) 1999-2009, PostgreSQL Global Development Group
82
82
#include <wctype.h>
83
83
#endif
84
84
85
+ #include "mb/pg_wchar.h"
85
86
#include "utils/builtins.h"
86
87
#include "utils/date.h"
87
88
#include "utils/datetime.h"
88
89
#include "utils/formatting.h"
89
90
#include "utils/int8.h"
90
91
#include "utils/numeric.h"
91
92
#include "utils/pg_locale.h"
92
- #include "mb/pg_wchar.h"
93
93
94
94
/* ----------
95
95
* Routines type
@@ -1046,24 +1046,24 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
1046
1046
if (n -> type != NODE_TYPE_ACTION )
1047
1047
return ;
1048
1048
1049
- if (IS_EEEE (num ) && n -> key -> id != NUM_E )
1049
+ /*
1050
+ * In case of an error, we need to remove the numeric from the cache. Use
1051
+ * a PG_TRY block to ensure that this happens.
1052
+ */
1053
+ PG_TRY ();
1050
1054
{
1051
- NUM_cache_remove ( last_NUMCacheEntry );
1055
+ if ( IS_EEEE ( num ) && n -> key -> id != NUM_E )
1052
1056
ereport (ERROR ,
1053
1057
(errcode (ERRCODE_SYNTAX_ERROR ),
1054
1058
errmsg ("\"EEEE\" must be the last pattern used" )));
1055
- }
1056
1059
1057
1060
switch (n -> key -> id )
1058
1061
{
1059
1062
case NUM_9 :
1060
1063
if (IS_BRACKET (num ))
1061
- {
1062
- NUM_cache_remove (last_NUMCacheEntry );
1063
1064
ereport (ERROR ,
1064
1065
(errcode (ERRCODE_SYNTAX_ERROR ),
1065
1066
errmsg ("\"9\" must be ahead of \"PR\"" )));
1066
- }
1067
1067
if (IS_MULTI (num ))
1068
1068
{
1069
1069
++ num -> multi ;
@@ -1077,12 +1077,9 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
1077
1077
1078
1078
case NUM_0 :
1079
1079
if (IS_BRACKET (num ))
1080
- {
1081
- NUM_cache_remove (last_NUMCacheEntry );
1082
1080
ereport (ERROR ,
1083
1081
(errcode (ERRCODE_SYNTAX_ERROR ),
1084
1082
errmsg ("\"0\" must be ahead of \"PR\"" )));
1085
- }
1086
1083
if (!IS_ZERO (num ) && !IS_DECIMAL (num ))
1087
1084
{
1088
1085
num -> flag |= NUM_F_ZERO ;
@@ -1106,19 +1103,13 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
1106
1103
num -> need_locale = TRUE;
1107
1104
case NUM_DEC :
1108
1105
if (IS_DECIMAL (num ))
1109
- {
1110
- NUM_cache_remove (last_NUMCacheEntry );
1111
1106
ereport (ERROR ,
1112
1107
(errcode (ERRCODE_SYNTAX_ERROR ),
1113
1108
errmsg ("multiple decimal points" )));
1114
- }
1115
1109
if (IS_MULTI (num ))
1116
- {
1117
- NUM_cache_remove (last_NUMCacheEntry );
1118
1110
ereport (ERROR ,
1119
1111
(errcode (ERRCODE_SYNTAX_ERROR ),
1120
1112
errmsg ("cannot use \"V\" and decimal point together" )));
1121
- }
1122
1113
num -> flag |= NUM_F_DECIMAL ;
1123
1114
break ;
1124
1115
@@ -1128,19 +1119,13 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
1128
1119
1129
1120
case NUM_S :
1130
1121
if (IS_LSIGN (num ))
1131
- {
1132
- NUM_cache_remove (last_NUMCacheEntry );
1133
1122
ereport (ERROR ,
1134
1123
(errcode (ERRCODE_SYNTAX_ERROR ),
1135
1124
errmsg ("cannot use \"S\" twice" )));
1136
- }
1137
1125
if (IS_PLUS (num ) || IS_MINUS (num ) || IS_BRACKET (num ))
1138
- {
1139
- NUM_cache_remove (last_NUMCacheEntry );
1140
1126
ereport (ERROR ,
1141
1127
(errcode (ERRCODE_SYNTAX_ERROR ),
1142
1128
errmsg ("cannot use \"S\" and \"PL\"/\"MI\"/\"SG\"/\"PR\" together" )));
1143
- }
1144
1129
if (!IS_DECIMAL (num ))
1145
1130
{
1146
1131
num -> lsign = NUM_LSIGN_PRE ;
@@ -1158,50 +1143,38 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
1158
1143
1159
1144
case NUM_MI :
1160
1145
if (IS_LSIGN (num ))
1161
- {
1162
- NUM_cache_remove (last_NUMCacheEntry );
1163
1146
ereport (ERROR ,
1164
1147
(errcode (ERRCODE_SYNTAX_ERROR ),
1165
1148
errmsg ("cannot use \"S\" and \"MI\" together" )));
1166
- }
1167
1149
num -> flag |= NUM_F_MINUS ;
1168
1150
if (IS_DECIMAL (num ))
1169
1151
num -> flag |= NUM_F_MINUS_POST ;
1170
1152
break ;
1171
1153
1172
1154
case NUM_PL :
1173
1155
if (IS_LSIGN (num ))
1174
- {
1175
- NUM_cache_remove (last_NUMCacheEntry );
1176
1156
ereport (ERROR ,
1177
1157
(errcode (ERRCODE_SYNTAX_ERROR ),
1178
1158
errmsg ("cannot use \"S\" and \"PL\" together" )));
1179
- }
1180
1159
num -> flag |= NUM_F_PLUS ;
1181
1160
if (IS_DECIMAL (num ))
1182
1161
num -> flag |= NUM_F_PLUS_POST ;
1183
1162
break ;
1184
1163
1185
1164
case NUM_SG :
1186
1165
if (IS_LSIGN (num ))
1187
- {
1188
- NUM_cache_remove (last_NUMCacheEntry );
1189
1166
ereport (ERROR ,
1190
1167
(errcode (ERRCODE_SYNTAX_ERROR ),
1191
1168
errmsg ("cannot use \"S\" and \"SG\" together" )));
1192
- }
1193
1169
num -> flag |= NUM_F_MINUS ;
1194
1170
num -> flag |= NUM_F_PLUS ;
1195
1171
break ;
1196
1172
1197
1173
case NUM_PR :
1198
1174
if (IS_LSIGN (num ) || IS_PLUS (num ) || IS_MINUS (num ))
1199
- {
1200
- NUM_cache_remove (last_NUMCacheEntry );
1201
1175
ereport (ERROR ,
1202
1176
(errcode (ERRCODE_SYNTAX_ERROR ),
1203
1177
errmsg ("cannot use \"PR\" and \"S\"/\"PL\"/\"MI\"/\"SG\" together" )));
1204
- }
1205
1178
num -> flag |= NUM_F_BRACKET ;
1206
1179
break ;
1207
1180
@@ -1217,36 +1190,35 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
1217
1190
1218
1191
case NUM_V :
1219
1192
if (IS_DECIMAL (num ))
1220
- {
1221
- NUM_cache_remove (last_NUMCacheEntry );
1222
1193
ereport (ERROR ,
1223
1194
(errcode (ERRCODE_SYNTAX_ERROR ),
1224
1195
errmsg ("cannot use \"V\" and decimal point together" )));
1225
- }
1226
1196
num -> flag |= NUM_F_MULTI ;
1227
1197
break ;
1228
1198
1229
1199
case NUM_E :
1230
1200
if (IS_EEEE (num ))
1231
- {
1232
- NUM_cache_remove (last_NUMCacheEntry );
1233
1201
ereport (ERROR ,
1234
1202
(errcode (ERRCODE_SYNTAX_ERROR ),
1235
1203
errmsg ("cannot use \"EEEE\" twice" )));
1236
- }
1237
1204
if (IS_BLANK (num ) || IS_FILLMODE (num ) || IS_LSIGN (num ) ||
1238
1205
IS_BRACKET (num ) || IS_MINUS (num ) || IS_PLUS (num ) ||
1239
1206
IS_ROMAN (num ) || IS_MULTI (num ))
1240
- {
1241
- NUM_cache_remove (last_NUMCacheEntry );
1242
1207
ereport (ERROR ,
1243
1208
(errcode (ERRCODE_SYNTAX_ERROR ),
1244
1209
errmsg ("\"EEEE\" is incompatible with other formats" ),
1245
1210
errdetail ("\"EEEE\" may only be used together with digit and decimal point patterns." )));
1246
- }
1247
1211
num -> flag |= NUM_F_EEEE ;
1248
1212
break ;
1249
1213
}
1214
+ }
1215
+ PG_CATCH ();
1216
+ {
1217
+ NUM_cache_remove (last_NUMCacheEntry );
1218
+ PG_RE_THROW ();
1219
+ }
1220
+ PG_END_TRY ();
1221
+
1250
1222
1251
1223
return ;
1252
1224
}
0 commit comments