|
3 | 3 | * procedural language
|
4 | 4 | *
|
5 | 5 | * IDENTIFICATION
|
6 |
| - * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.78 2004/07/31 00:45:46 tgl Exp $ |
| 6 | + * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.79 2004/08/20 22:00:14 tgl Exp $ |
7 | 7 | *
|
8 | 8 | * This software is copyrighted by Jan Wieck - Hamburg.
|
9 | 9 | *
|
@@ -94,6 +94,20 @@ typedef struct plpgsql_hashent
|
94 | 94 |
|
95 | 95 | #define FUNCS_PER_USER 128 /* initial table size */
|
96 | 96 |
|
| 97 | +/* ---------- |
| 98 | + * Lookup table for EXCEPTION condition names |
| 99 | + * ---------- |
| 100 | + */ |
| 101 | +typedef struct { |
| 102 | + const char *label; |
| 103 | + int sqlerrstate; |
| 104 | +} ExceptionLabelMap; |
| 105 | + |
| 106 | +static const ExceptionLabelMap exception_label_map[] = { |
| 107 | +#include "plerrcodes.h" |
| 108 | + { NULL, 0 } |
| 109 | +}; |
| 110 | + |
97 | 111 |
|
98 | 112 | /* ----------
|
99 | 113 | * static prototypes
|
@@ -1710,6 +1724,59 @@ build_datatype(HeapTuple typeTup, int32 typmod)
|
1710 | 1724 | return typ;
|
1711 | 1725 | }
|
1712 | 1726 |
|
| 1727 | +/* |
| 1728 | + * plpgsql_parse_err_condition |
| 1729 | + * Generate PLpgSQL_condition entry(s) for an exception condition name |
| 1730 | + * |
| 1731 | + * This has to be able to return a list because there are some duplicate |
| 1732 | + * names in the table of error code names. |
| 1733 | + */ |
| 1734 | +PLpgSQL_condition * |
| 1735 | +plpgsql_parse_err_condition(char *condname) |
| 1736 | +{ |
| 1737 | + int i; |
| 1738 | + PLpgSQL_condition *new; |
| 1739 | + PLpgSQL_condition *prev; |
| 1740 | + |
| 1741 | + /* |
| 1742 | + * XXX Eventually we will want to look for user-defined exception names |
| 1743 | + * here. |
| 1744 | + */ |
| 1745 | + |
| 1746 | + /* |
| 1747 | + * OTHERS is represented as code 0 (which would map to '00000', but |
| 1748 | + * we have no need to represent that as an exception condition). |
| 1749 | + */ |
| 1750 | + if (strcmp(condname, "others") == 0) |
| 1751 | + { |
| 1752 | + new = malloc(sizeof(PLpgSQL_condition)); |
| 1753 | + new->sqlerrstate = 0; |
| 1754 | + new->condname = condname; |
| 1755 | + new->next = NULL; |
| 1756 | + return new; |
| 1757 | + } |
| 1758 | + |
| 1759 | + prev = NULL; |
| 1760 | + for (i = 0; exception_label_map[i].label != NULL; i++) |
| 1761 | + { |
| 1762 | + if (strcmp(condname, exception_label_map[i].label) == 0) |
| 1763 | + { |
| 1764 | + new = malloc(sizeof(PLpgSQL_condition)); |
| 1765 | + new->sqlerrstate = exception_label_map[i].sqlerrstate; |
| 1766 | + new->condname = condname; |
| 1767 | + new->next = prev; |
| 1768 | + prev = new; |
| 1769 | + } |
| 1770 | + } |
| 1771 | + |
| 1772 | + if (!prev) |
| 1773 | + ereport(ERROR, |
| 1774 | + (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 1775 | + errmsg("unrecognized exception condition \"%s\"", |
| 1776 | + condname))); |
| 1777 | + |
| 1778 | + return prev; |
| 1779 | +} |
1713 | 1780 |
|
1714 | 1781 | /* ----------
|
1715 | 1782 | * plpgsql_adddatum Add a variable, record or row
|
|
0 commit comments