8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.184 2007/01/28 16:15:49 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.185 2007/01/28 17:58:13 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -267,6 +267,8 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo)
267
267
}
268
268
}
269
269
270
+ estate .err_text = gettext_noop ("during function entry" );
271
+
270
272
/*
271
273
* Set the magic variable FOUND to false
272
274
*/
@@ -414,6 +416,8 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo)
414
416
}
415
417
}
416
418
419
+ estate .err_text = gettext_noop ("during function exit" );
420
+
417
421
/*
418
422
* Let the instrumentation plugin peek at this function
419
423
*/
@@ -608,6 +612,8 @@ plpgsql_exec_trigger(PLpgSQL_function *func,
608
612
CStringGetDatum (trigdata -> tg_trigger -> tgargs [i ]));
609
613
}
610
614
615
+ estate .err_text = gettext_noop ("during function entry" );
616
+
611
617
/*
612
618
* Set the magic variable FOUND to false
613
619
*/
@@ -644,6 +650,9 @@ plpgsql_exec_trigger(PLpgSQL_function *func,
644
650
errmsg ("control reached end of trigger procedure without RETURN" )));
645
651
}
646
652
653
+ estate .err_stmt = NULL ;
654
+ estate .err_text = gettext_noop ("during function exit" );
655
+
647
656
if (estate .retisset )
648
657
ereport (ERROR ,
649
658
(errcode (ERRCODE_DATATYPE_MISMATCH ),
@@ -711,30 +720,48 @@ plpgsql_exec_error_callback(void *arg)
711
720
if (estate -> err_text == raise_skip_msg )
712
721
return ;
713
722
714
- if (estate -> err_stmt != NULL )
715
- {
716
- /* translator: last %s is a plpgsql statement type name */
717
- errcontext ("PL/pgSQL function \"%s\" line %d at %s" ,
718
- estate -> err_func -> fn_name ,
719
- estate -> err_stmt -> lineno ,
720
- plpgsql_stmt_typename (estate -> err_stmt ));
721
- }
722
- else if (estate -> err_text != NULL )
723
+ if (estate -> err_text != NULL )
723
724
{
724
725
/*
725
726
* We don't expend the cycles to run gettext() on err_text unless we
726
727
* actually need it. Therefore, places that set up err_text should
727
728
* use gettext_noop() to ensure the strings get recorded in the
728
729
* message dictionary.
730
+ *
731
+ * If both err_text and err_stmt are set, use the err_text as
732
+ * description, but report the err_stmt's line number. When
733
+ * err_stmt is not set, we're in function entry/exit, or some such
734
+ * place not attached to a specific line number.
729
735
*/
730
-
731
- /*
732
- * translator: last %s is a phrase such as "while storing call
733
- * arguments into local variables"
734
- */
735
- errcontext ("PL/pgSQL function \"%s\" %s" ,
736
+ if (estate -> err_stmt != NULL )
737
+ {
738
+ /*
739
+ * translator: last %s is a phrase such as "during statement
740
+ * block local variable initialization"
741
+ */
742
+ errcontext ("PL/pgSQL function \"%s\" line %d %s" ,
743
+ estate -> err_func -> fn_name ,
744
+ estate -> err_stmt -> lineno ,
745
+ gettext (estate -> err_text ));
746
+ }
747
+ else
748
+ {
749
+ /*
750
+ * translator: last %s is a phrase such as "while storing call
751
+ * arguments into local variables"
752
+ */
753
+ errcontext ("PL/pgSQL function \"%s\" %s" ,
754
+ estate -> err_func -> fn_name ,
755
+ gettext (estate -> err_text ));
756
+ }
757
+ }
758
+ else if (estate -> err_stmt != NULL )
759
+ {
760
+ /* translator: last %s is a plpgsql statement type name */
761
+ errcontext ("PL/pgSQL function \"%s\" line %d at %s" ,
736
762
estate -> err_func -> fn_name ,
737
- gettext (estate -> err_text ));
763
+ estate -> err_stmt -> lineno ,
764
+ plpgsql_stmt_typename (estate -> err_stmt ));
738
765
}
739
766
else
740
767
errcontext ("PL/pgSQL function \"%s\"" ,
@@ -846,6 +873,8 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
846
873
/*
847
874
* First initialize all variables declared in this block
848
875
*/
876
+ estate -> err_text = gettext_noop ("during statement block local variable initialization" );
877
+
849
878
for (i = 0 ; i < block -> n_initvars ; i ++ )
850
879
{
851
880
n = block -> initvarnos [i ];
@@ -915,6 +944,8 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
915
944
EState * old_eval_estate = estate -> eval_estate ;
916
945
long int old_eval_estate_simple_id = estate -> eval_estate_simple_id ;
917
946
947
+ estate -> err_text = gettext_noop ("during statement block entry" );
948
+
918
949
BeginInternalSubTransaction (NULL );
919
950
/* Want to run statements inside function's memory context */
920
951
MemoryContextSwitchTo (oldcontext );
@@ -929,9 +960,13 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
929
960
*/
930
961
plpgsql_create_econtext (estate );
931
962
963
+ estate -> err_text = NULL ;
964
+
932
965
/* Run the block's statements */
933
966
rc = exec_stmts (estate , block -> body );
934
967
968
+ estate -> err_text = gettext_noop ("during statement block exit" );
969
+
935
970
/* Commit the inner transaction, return to outer xact context */
936
971
ReleaseCurrentSubTransaction ();
937
972
MemoryContextSwitchTo (oldcontext );
@@ -953,6 +988,8 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
953
988
ErrorData * edata ;
954
989
ListCell * e ;
955
990
991
+ estate -> err_text = gettext_noop ("during exception cleanup" );
992
+
956
993
/* Save error info */
957
994
MemoryContextSwitchTo (oldcontext );
958
995
edata = CopyErrorData ();
@@ -1004,6 +1041,8 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
1004
1041
errm_var -> freeval = true;
1005
1042
errm_var -> isnull = false;
1006
1043
1044
+ estate -> err_text = NULL ;
1045
+
1007
1046
rc = exec_stmts (estate , exception -> action );
1008
1047
1009
1048
free_var (state_var );
@@ -1025,9 +1064,13 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
1025
1064
/*
1026
1065
* Just execute the statements in the block's body
1027
1066
*/
1067
+ estate -> err_text = NULL ;
1068
+
1028
1069
rc = exec_stmts (estate , block -> body );
1029
1070
}
1030
1071
1072
+ estate -> err_text = NULL ;
1073
+
1031
1074
/*
1032
1075
* Handle the return code.
1033
1076
*/
0 commit comments