3333 * ENHANCEMENTS, OR MODIFICATIONS.
3434 *
3535 * IDENTIFICATION
36- * $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.36 2003/04/20 21:15:34 tgl Exp $
36+ * $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.37 2003/07/25 23:37:28 tgl Exp $
3737 *
3838 **********************************************************************/
3939
4747/* postgreSQL stuff */
4848#include "executor/spi.h"
4949#include "commands/trigger.h"
50- #include "utils/elog.h"
5150#include "fmgr.h"
5251#include "access/heapam.h"
5352#include "tcop/tcopprot.h"
@@ -193,7 +192,7 @@ plperl_init_interp(void)
193192
194193plperl_interp = perl_alloc ();
195194if (!plperl_interp )
196- elog (ERROR ,"plperl_init_interp(): could not allocate perl interpreter" );
195+ elog (ERROR ,"could not allocate perl interpreter" );
197196
198197perl_construct (plperl_interp );
199198perl_parse (plperl_interp ,plperl_init_shared_libs ,3 ,embedding ,NULL );
@@ -232,15 +231,17 @@ plperl_call_handler(PG_FUNCTION_ARGS)
232231 * Connect to SPI manager
233232 ************************************************************/
234233if (SPI_connect ()!= SPI_OK_CONNECT )
235- elog (ERROR ,"plperl: cannot connect to SPI manager" );
234+ elog (ERROR ,"could not connect to SPI manager" );
236235
237236/************************************************************
238237 * Determine if called as function or trigger and
239238 * call appropriate subhandler
240239 ************************************************************/
241240if (CALLED_AS_TRIGGER (fcinfo ))
242241{
243- elog (ERROR ,"plperl: can't use perl in triggers yet." );
242+ ereport (ERROR ,
243+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
244+ errmsg ("cannot use perl in triggers yet" )));
244245
245246/*
246247 * retval = PointerGetDatum(plperl_trigger_handler(fcinfo));
@@ -286,7 +287,7 @@ plperl_create_sub(char *s, bool trusted)
286287PUTBACK ;
287288FREETMPS ;
288289LEAVE ;
289- elog (ERROR ,"plperl: didn't get a return item from mksafefunc" );
290+ elog (ERROR ,"didn't get a return item from mksafefunc" );
290291}
291292
292293if (SvTRUE (ERRSV ))
@@ -314,7 +315,7 @@ plperl_create_sub(char *s, bool trusted)
314315 * subref is our responsibility because it is not mortal
315316 */
316317SvREFCNT_dec (subref );
317- elog (ERROR ,"plperl_create_sub: didn't get a code ref" );
318+ elog (ERROR ,"didn't get a code ref" );
318319}
319320
320321PUTBACK ;
@@ -406,7 +407,7 @@ plperl_call_perl_func(plperl_proc_desc * desc, FunctionCallInfo fcinfo)
406407PUTBACK ;
407408FREETMPS ;
408409LEAVE ;
409- elog (ERROR ,"plperl: didn't get a return item from function" );
410+ elog (ERROR ,"didn't get a return item from function" );
410411}
411412
412413if (SvTRUE (ERRSV ))
@@ -415,7 +416,7 @@ plperl_call_perl_func(plperl_proc_desc * desc, FunctionCallInfo fcinfo)
415416PUTBACK ;
416417FREETMPS ;
417418LEAVE ;
418- elog (ERROR ,"plperl: error from function: %s" ,SvPV (ERRSV ,PL_na ));
419+ elog (ERROR ,"error from function: %s" ,SvPV (ERRSV ,PL_na ));
419420}
420421
421422retval = newSVsv (POPs );
@@ -453,7 +454,7 @@ plperl_func_handler(PG_FUNCTION_ARGS)
453454 * because SPI_finish would free it).
454455 ************************************************************/
455456if (SPI_finish ()!= SPI_OK_FINISH )
456- elog (ERROR ,"plperl: SPI_finish() failed" );
457+ elog (ERROR ,"SPI_finish() failed" );
457458
458459if (!(perlret && SvOK (perlret )))
459460{
@@ -493,7 +494,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
493494ObjectIdGetDatum (fn_oid ),
4944950 ,0 ,0 );
495496if (!HeapTupleIsValid (procTup ))
496- elog (ERROR ,"plperl: cache lookup forproc %u failed " ,fn_oid );
497+ elog (ERROR ,"cache lookupfailed forfunction %u" ,fn_oid );
497498procStruct = (Form_pg_proc )GETSTRUCT (procTup );
498499
499500/************************************************************
@@ -551,7 +552,9 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
551552 ************************************************************/
552553prodesc = (plperl_proc_desc * )malloc (sizeof (plperl_proc_desc ));
553554if (prodesc == NULL )
554- elog (ERROR ,"plperl: out of memory" );
555+ ereport (ERROR ,
556+ (errcode (ERRCODE_OUT_OF_MEMORY ),
557+ errmsg ("out of memory" )));
555558MemSet (prodesc ,0 ,sizeof (plperl_proc_desc ));
556559prodesc -> proname = strdup (internal_proname );
557560prodesc -> fn_xmin = HeapTupleHeaderGetXmin (procTup -> t_data );
@@ -567,7 +570,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
567570{
568571free (prodesc -> proname );
569572free (prodesc );
570- elog (ERROR ,"plperl: cache lookup for language %u failed " ,
573+ elog (ERROR ,"cache lookupfailed for language %u" ,
571574procStruct -> prolang );
572575}
573576langStruct = (Form_pg_language )GETSTRUCT (langTup );
@@ -587,7 +590,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
587590{
588591free (prodesc -> proname );
589592free (prodesc );
590- elog (ERROR ,"plperl: cache lookup forreturn type %u failed " ,
593+ elog (ERROR ,"cache lookupfailed for type %u" ,
591594procStruct -> prorettype );
592595}
593596typeStruct = (Form_pg_type )GETSTRUCT (typeTup );
@@ -601,24 +604,28 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
601604{
602605free (prodesc -> proname );
603606free (prodesc );
604- elog (ERROR ,"plperl functions cannot return type %s"
605- "\n\texcept when used as triggers" ,
606- format_type_be ( procStruct -> prorettype ));
607+ ereport (ERROR ,
608+ ( errcode ( ERRCODE_FEATURE_NOT_SUPPORTED ) ,
609+ errmsg ( "trigger functions may only be called as triggers" ) ));
607610}
608611else
609612{
610613free (prodesc -> proname );
611614free (prodesc );
612- elog (ERROR ,"plperl functions cannot return type %s" ,
613- format_type_be (procStruct -> prorettype ));
615+ ereport (ERROR ,
616+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
617+ errmsg ("plperl functions cannot return type %s" ,
618+ format_type_be (procStruct -> prorettype ))));
614619}
615620}
616621
617622if (typeStruct -> typrelid != InvalidOid )
618623{
619624free (prodesc -> proname );
620625free (prodesc );
621- elog (ERROR ,"plperl: return types of tuples not supported yet" );
626+ ereport (ERROR ,
627+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
628+ errmsg ("plperl functions cannot return tuples yet" )));
622629}
623630
624631perm_fmgr_info (typeStruct -> typinput ,& (prodesc -> result_in_func ));
@@ -643,7 +650,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
643650{
644651free (prodesc -> proname );
645652free (prodesc );
646- elog (ERROR ,"plperl: cache lookup forargument type %u failed " ,
653+ elog (ERROR ,"cache lookupfailed for type %u" ,
647654procStruct -> proargtypes [i ]);
648655}
649656typeStruct = (Form_pg_type )GETSTRUCT (typeTup );
@@ -653,8 +660,10 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
653660{
654661free (prodesc -> proname );
655662free (prodesc );
656- elog (ERROR ,"plperl functions cannot take type %s" ,
657- format_type_be (procStruct -> proargtypes [i ]));
663+ ereport (ERROR ,
664+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
665+ errmsg ("plperl functions cannot take type %s" ,
666+ format_type_be (procStruct -> proargtypes [i ]))));
658667}
659668
660669if (typeStruct -> typrelid != InvalidOid )
@@ -686,7 +695,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
686695{
687696free (prodesc -> proname );
688697free (prodesc );
689- elog (ERROR ,"plperl: cannot create internal procedure%s " ,
698+ elog (ERROR ,"could not create internal procedure\"%s\" " ,
690699internal_proname );
691700}
692701
@@ -751,8 +760,8 @@ plperl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc)
751760ObjectIdGetDatum (tupdesc -> attrs [i ]-> atttypid ),
7527610 ,0 ,0 );
753762if (!HeapTupleIsValid (typeTup ))
754- elog (ERROR ,"plperl: Cache lookup forattribute '%s' type %u failed " ,
755- attname , tupdesc -> attrs [i ]-> atttypid );
763+ elog (ERROR ,"cache lookupfailed for type %u" ,
764+ tupdesc -> attrs [i ]-> atttypid );
756765
757766typoutput = ((Form_pg_type )GETSTRUCT (typeTup ))-> typoutput ;
758767typelem = ((Form_pg_type )GETSTRUCT (typeTup ))-> typelem ;