33
33
* ENHANCEMENTS, OR MODIFICATIONS.
34
34
*
35
35
* IDENTIFICATION
36
- * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.64 2004/11/24 18:47:38 tgl Exp $
36
+ * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.65 2004/11/29 20:11:05 tgl Exp $
37
37
*
38
38
**********************************************************************/
39
39
@@ -200,7 +200,7 @@ plperl_init_interp(void)
200
200
201
201
plperl_interp = perl_alloc ();
202
202
if (!plperl_interp )
203
- elog (ERROR , "could not allocate perl interpreter" );
203
+ elog (ERROR , "could not allocate Perl interpreter" );
204
204
205
205
perl_construct (plperl_interp );
206
206
perl_parse (plperl_interp , plperl_init_shared_libs , 3 , embedding , NULL );
@@ -233,8 +233,8 @@ plperl_safe_init(void)
233
233
"$PLContainer->permit_only(':default');"
234
234
"$PLContainer->share(qw[&elog &ERROR ]);"
235
235
"sub ::mksafefunc { return $PLContainer->reval(qq[sub { "
236
- "elog(ERROR,'trusted perl functions disabled - "
237
- "please upgrade perl Safe module to at least 2.09');}]); }"
236
+ "elog(ERROR,'trusted Perl functions disabled - "
237
+ "please upgrade Perl Safe module to version 2.09 or later ');}]); }"
238
238
;
239
239
240
240
SV * res ;
@@ -291,7 +291,10 @@ plperl_build_tuple_result(HV *perlhash, AttInMetadata *attinmeta)
291
291
int attn = SPI_fnumber (td , key );
292
292
293
293
if (attn <= 0 || td -> attrs [attn - 1 ]-> attisdropped )
294
- elog (ERROR , "plperl: invalid attribute \"%s\" in hash" , key );
294
+ ereport (ERROR ,
295
+ (errcode (ERRCODE_UNDEFINED_COLUMN ),
296
+ errmsg ("Perl hash contains nonexistent column \"%s\"" ,
297
+ key )));
295
298
if (SvTYPE (val ) != SVt_NULL )
296
299
values [attn - 1 ] = SvPV (val , PL_na );
297
300
}
@@ -408,8 +411,9 @@ get_function_tupdesc(Oid result_type, ReturnSetInfo *rsinfo)
408
411
if (!rsinfo || !IsA (rsinfo , ReturnSetInfo ) ||
409
412
rsinfo -> expectedDesc == NULL )
410
413
ereport (ERROR ,
411
- (errcode (ERRCODE_DATATYPE_MISMATCH ),
412
- errmsg ("could not determine row description for function returning record" )));
414
+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
415
+ errmsg ("function returning record called in context "
416
+ "that cannot accept type record" )));
413
417
return rsinfo -> expectedDesc ;
414
418
}
415
419
else /* ordinary composite type */
@@ -439,9 +443,13 @@ plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup)
439
443
440
444
svp = hv_fetch (hvTD , "new" , 3 , FALSE);
441
445
if (!svp )
442
- elog (ERROR , "plperl: key \"new\" not found" );
446
+ ereport (ERROR ,
447
+ (errcode (ERRCODE_UNDEFINED_COLUMN ),
448
+ errmsg ("$_TD->{new} does not exist" )));
443
449
if (SvTYPE (* svp ) != SVt_RV || SvTYPE (SvRV (* svp )) != SVt_PVHV )
444
- elog (ERROR , "plperl: $_TD->{new} is not a hash reference" );
450
+ ereport (ERROR ,
451
+ (errcode (ERRCODE_DATATYPE_MISMATCH ),
452
+ errmsg ("$_TD->{new} is not a hash reference" )));
445
453
hvNew = (HV * ) SvRV (* svp );
446
454
447
455
modattrs = palloc (tupdesc -> natts * sizeof (int ));
@@ -455,7 +463,10 @@ plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup)
455
463
int attn = SPI_fnumber (tupdesc , key );
456
464
457
465
if (attn <= 0 || tupdesc -> attrs [attn - 1 ]-> attisdropped )
458
- elog (ERROR , "plperl: invalid attribute \"%s\" in hash" , key );
466
+ ereport (ERROR ,
467
+ (errcode (ERRCODE_UNDEFINED_COLUMN ),
468
+ errmsg ("Perl hash contains nonexistent column \"%s\"" ,
469
+ key )));
459
470
if (SvTYPE (val ) != SVt_NULL )
460
471
{
461
472
Oid typinput ;
@@ -490,7 +501,7 @@ plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup)
490
501
pfree (modnulls );
491
502
492
503
if (rtup == NULL )
493
- elog (ERROR , "plperl: SPI_modifytuple failed: %s" ,
504
+ elog (ERROR , "SPI_modifytuple failed: %s" ,
494
505
SPI_result_code_string (SPI_result ));
495
506
496
507
return rtup ;
@@ -594,8 +605,10 @@ plperl_create_sub(char *s, bool trusted)
594
605
PUTBACK ;
595
606
FREETMPS ;
596
607
LEAVE ;
597
- elog (ERROR , "creation of function failed: %s" ,
598
- strip_trailing_ws (SvPV (ERRSV , PL_na )));
608
+ ereport (ERROR ,
609
+ (errcode (ERRCODE_SYNTAX_ERROR ),
610
+ errmsg ("creation of Perl function failed: %s" ,
611
+ strip_trailing_ws (SvPV (ERRSV , PL_na )))));
599
612
}
600
613
601
614
/*
@@ -722,8 +735,10 @@ plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo)
722
735
PUTBACK ;
723
736
FREETMPS ;
724
737
LEAVE ;
725
- elog (ERROR , "error from function: %s" ,
726
- strip_trailing_ws (SvPV (ERRSV , PL_na )));
738
+ /* XXX need to find a way to assign an errcode here */
739
+ ereport (ERROR ,
740
+ (errmsg ("error from Perl function: %s" ,
741
+ strip_trailing_ws (SvPV (ERRSV , PL_na )))));
727
742
}
728
743
729
744
retval = newSVsv (POPs );
@@ -780,8 +795,10 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo,
780
795
PUTBACK ;
781
796
FREETMPS ;
782
797
LEAVE ;
783
- elog (ERROR , "error from trigger function: %s" ,
784
- strip_trailing_ws (SvPV (ERRSV , PL_na )));
798
+ /* XXX need to find a way to assign an errcode here */
799
+ ereport (ERROR ,
800
+ (errmsg ("error from Perl trigger function: %s" ,
801
+ strip_trailing_ws (SvPV (ERRSV , PL_na )))));
785
802
}
786
803
787
804
retval = newSVsv (POPs );
@@ -857,7 +874,9 @@ plperl_func_handler(PG_FUNCTION_ARGS)
857
874
AttInMetadata * attinmeta ;
858
875
859
876
if (SvTYPE (perlret ) != SVt_RV || SvTYPE (SvRV (perlret )) != SVt_PVAV )
860
- elog (ERROR , "plperl: set-returning function must return reference to array" );
877
+ ereport (ERROR ,
878
+ (errcode (ERRCODE_DATATYPE_MISMATCH ),
879
+ errmsg ("set-returning Perl function must return reference to array" )));
861
880
ret_av = (AV * ) SvRV (perlret );
862
881
863
882
if (SRF_IS_FIRSTCALL ())
@@ -893,7 +912,9 @@ plperl_func_handler(PG_FUNCTION_ARGS)
893
912
Assert (svp != NULL );
894
913
895
914
if (SvTYPE (* svp ) != SVt_RV || SvTYPE (SvRV (* svp )) != SVt_PVHV )
896
- elog (ERROR , "plperl: element of result array is not a reference to hash" );
915
+ ereport (ERROR ,
916
+ (errcode (ERRCODE_DATATYPE_MISMATCH ),
917
+ errmsg ("elements of Perl result array must be reference to hash" )));
897
918
row_hv = (HV * ) SvRV (* svp );
898
919
899
920
tuple = plperl_build_tuple_result (row_hv , attinmeta );
@@ -913,7 +934,9 @@ plperl_func_handler(PG_FUNCTION_ARGS)
913
934
FuncCallContext * funcctx ;
914
935
915
936
if (SvTYPE (perlret ) != SVt_RV || SvTYPE (SvRV (perlret )) != SVt_PVAV )
916
- elog (ERROR , "plperl: set-returning function must return reference to array" );
937
+ ereport (ERROR ,
938
+ (errcode (ERRCODE_DATATYPE_MISMATCH ),
939
+ errmsg ("set-returning Perl function must return reference to array" )));
917
940
ret_av = (AV * ) SvRV (perlret );
918
941
919
942
if (SRF_IS_FIRSTCALL ())
@@ -966,7 +989,9 @@ plperl_func_handler(PG_FUNCTION_ARGS)
966
989
HeapTuple tup ;
967
990
968
991
if (SvTYPE (perlret ) != SVt_RV || SvTYPE (SvRV (perlret )) != SVt_PVHV )
969
- elog (ERROR , "plperl: composite-returning function must return a reference to hash" );
992
+ ereport (ERROR ,
993
+ (errcode (ERRCODE_DATATYPE_MISMATCH ),
994
+ errmsg ("composite-returning Perl function must return reference to hash" )));
970
995
perlhash = (HV * ) SvRV (perlret );
971
996
972
997
/*
@@ -1036,7 +1061,7 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
1036
1061
* because SPI_finish would free it).
1037
1062
************************************************************/
1038
1063
if (SPI_finish () != SPI_OK_FINISH )
1039
- elog (ERROR , "plperl: SPI_finish() failed" );
1064
+ elog (ERROR , "SPI_finish() failed" );
1040
1065
1041
1066
if (!(perlret && SvOK (perlret ) && SvTYPE (perlret ) != SVt_NULL ))
1042
1067
{
@@ -1073,13 +1098,17 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
1073
1098
trigdata -> tg_newtuple );
1074
1099
else
1075
1100
{
1076
- elog (WARNING , "plperl: ignoring modified tuple in DELETE trigger" );
1101
+ ereport (WARNING ,
1102
+ (errcode (ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED ),
1103
+ errmsg ("ignoring modified tuple in DELETE trigger" )));
1077
1104
trv = NULL ;
1078
1105
}
1079
1106
}
1080
1107
else
1081
1108
{
1082
- elog (ERROR , "plperl: expected trigger result to be undef, \"SKIP\" or \"MODIFY\"" );
1109
+ ereport (ERROR ,
1110
+ (errcode (ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED ),
1111
+ errmsg ("result of Perl trigger function must be undef, \"SKIP\" or \"MODIFY\"" )));
1083
1112
trv = NULL ;
1084
1113
}
1085
1114
retval = PointerGetDatum (trv );
@@ -1318,7 +1347,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
1318
1347
************************************************************/
1319
1348
prodesc -> reference = plperl_create_sub (proc_source , prodesc -> lanpltrusted );
1320
1349
pfree (proc_source );
1321
- if (!prodesc -> reference )
1350
+ if (!prodesc -> reference ) /* can this happen? */
1322
1351
{
1323
1352
free (prodesc -> proname );
1324
1353
free (prodesc );
0 commit comments