* plpgsql_recognize_err_condition * Check condition name and translate it to SQLSTATE. * * Note: there are some cases where the same condition name has multiple * entries in the table. We arbitrarily return the first match. */
| 2246 | * entries in the table. We arbitrarily return the first match. |
| 2247 | */ |
| 2248 | int |
| 2249 | plpgsql_recognize_err_condition(const char *condname, bool allow_sqlstate) |
| 2250 | { |
| 2251 | int i; |
| 2252 | |
| 2253 | if (allow_sqlstate) |
| 2254 | { |
| 2255 | if (strlen(condname) == 5 && |
| 2256 | strspn(condname, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") == 5) |
| 2257 | return MAKE_SQLSTATE(condname[0], |
| 2258 | condname[1], |
| 2259 | condname[2], |
| 2260 | condname[3], |
| 2261 | condname[4]); |
| 2262 | } |
| 2263 | |
| 2264 | for (i = 0; exception_label_map[i].label != NULL; i++) |
| 2265 | { |
| 2266 | if (strcmp(condname, exception_label_map[i].label) == 0) |
| 2267 | return exception_label_map[i].sqlerrstate; |
| 2268 | } |
| 2269 | |
| 2270 | ereport(ERROR, |
| 2271 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 2272 | errmsg("unrecognized exception condition \"%s\"", |
| 2273 | condname))); |
| 2274 | return 0; /* keep compiler quiet */ |
| 2275 | } |
| 2276 | |
| 2277 | /* |
| 2278 | * plpgsql_parse_err_condition |
no test coverage detected