@@ -188,6 +188,20 @@ static HTAB *pltcl_proc_htab = NULL;
188
188
static FunctionCallInfo pltcl_current_fcinfo = NULL ;
189
189
static pltcl_proc_desc * pltcl_current_prodesc = NULL ;
190
190
191
+ /**********************************************************************
192
+ * Lookup table for SQLSTATE condition names
193
+ **********************************************************************/
194
+ typedef struct
195
+ {
196
+ const char * label ;
197
+ int sqlerrstate ;
198
+ } TclExceptionNameMap ;
199
+
200
+ static const TclExceptionNameMap exception_name_map [] = {
201
+ #include "pltclerrcodes.h" /* pgrminclude ignore */
202
+ {NULL , 0 }
203
+ };
204
+
191
205
/**********************************************************************
192
206
* Forward declarations
193
207
**********************************************************************/
@@ -213,6 +227,7 @@ static pltcl_proc_desc *compile_pltcl_function(Oid fn_oid, Oid tgreloid,
213
227
static int pltcl_elog (ClientData cdata , Tcl_Interp * interp ,
214
228
int objc , Tcl_Obj * const objv []);
215
229
static void pltcl_construct_errorCode (Tcl_Interp * interp , ErrorData * edata );
230
+ static const char * pltcl_get_condition_name (int sqlstate );
216
231
static int pltcl_quote (ClientData cdata , Tcl_Interp * interp ,
217
232
int objc , Tcl_Obj * const objv []);
218
233
static int pltcl_argisnull (ClientData cdata , Tcl_Interp * interp ,
@@ -1681,6 +1696,10 @@ pltcl_construct_errorCode(Tcl_Interp *interp, ErrorData *edata)
1681
1696
Tcl_NewStringObj ("SQLSTATE" , -1 ));
1682
1697
Tcl_ListObjAppendElement (interp , obj ,
1683
1698
Tcl_NewStringObj (unpack_sql_state (edata -> sqlerrcode ), -1 ));
1699
+ Tcl_ListObjAppendElement (interp , obj ,
1700
+ Tcl_NewStringObj ("condition" , -1 ));
1701
+ Tcl_ListObjAppendElement (interp , obj ,
1702
+ Tcl_NewStringObj (pltcl_get_condition_name (edata -> sqlerrcode ), -1 ));
1684
1703
Tcl_ListObjAppendElement (interp , obj ,
1685
1704
Tcl_NewStringObj ("message" , -1 ));
1686
1705
UTF_BEGIN ;
@@ -1806,6 +1825,23 @@ pltcl_construct_errorCode(Tcl_Interp *interp, ErrorData *edata)
1806
1825
}
1807
1826
1808
1827
1828
+ /**********************************************************************
1829
+ * pltcl_get_condition_name() - find name for SQLSTATE
1830
+ **********************************************************************/
1831
+ static const char *
1832
+ pltcl_get_condition_name (int sqlstate )
1833
+ {
1834
+ int i ;
1835
+
1836
+ for (i = 0 ; exception_name_map [i ].label != NULL ; i ++ )
1837
+ {
1838
+ if (exception_name_map [i ].sqlerrstate == sqlstate )
1839
+ return exception_name_map [i ].label ;
1840
+ }
1841
+ return "unrecognized_sqlstate" ;
1842
+ }
1843
+
1844
+
1809
1845
/**********************************************************************
1810
1846
* pltcl_quote() - quote literal strings that are to
1811
1847
* be used in SPI_execute query strings
0 commit comments