33 * procedural language
44 *
55 * IDENTIFICATION
6- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.102 2004/05/30 23:40:41 neilc Exp $
6+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.103 2004/06/04 00:07:52 tgl Exp $
77 *
88 * This software is copyrighted by Jan Wieck - Hamburg.
99 *
@@ -2969,17 +2969,12 @@ exec_eval_datum(PLpgSQL_execstate * estate,
29692969 Datum * value ,
29702970 bool * isnull )
29712971{
2972- PLpgSQL_var * var ;
2973- PLpgSQL_rec * rec ;
2974- PLpgSQL_recfield * recfield ;
2975- PLpgSQL_trigarg * trigarg ;
2976- int tgargno ;
2977- int fno ;
2978-
29792972 switch (datum -> dtype )
29802973 {
29812974 case PLPGSQL_DTYPE_VAR :
2982- var = (PLpgSQL_var * ) datum ;
2975+ {
2976+ PLpgSQL_var * var = (PLpgSQL_var * ) datum ;
2977+
29832978 * typeid = var -> datatype -> typoid ;
29842979 * value = var -> value ;
29852980 * isnull = var -> isnull ;
@@ -2989,9 +2984,56 @@ exec_eval_datum(PLpgSQL_execstate * estate,
29892984 errmsg ("type of \"%s\" does not match that when preparing the plan" ,
29902985 var -> refname )));
29912986 break ;
2987+ }
2988+
2989+ case PLPGSQL_DTYPE_ROW :
2990+ {
2991+ PLpgSQL_row * row = (PLpgSQL_row * ) datum ;
2992+ HeapTuple tup ;
2993+
2994+ if (!row -> rowtupdesc ) /* should not happen */
2995+ elog (ERROR , "row variable has no tupdesc" );
2996+ tup = make_tuple_from_row (estate , row , row -> rowtupdesc );
2997+ if (tup == NULL ) /* should not happen */
2998+ elog (ERROR , "row not compatible with its own tupdesc" );
2999+ * typeid = row -> rowtupdesc -> tdtypeid ;
3000+ * value = HeapTupleGetDatum (tup );
3001+ * isnull = false;
3002+ if (expectedtypeid != InvalidOid && expectedtypeid != * typeid )
3003+ ereport (ERROR ,
3004+ (errcode (ERRCODE_DATATYPE_MISMATCH ),
3005+ errmsg ("type of \"%s\" does not match that when preparing the plan" ,
3006+ row -> refname )));
3007+ break ;
3008+ }
3009+
3010+ case PLPGSQL_DTYPE_REC :
3011+ {
3012+ PLpgSQL_rec * rec = (PLpgSQL_rec * ) datum ;
3013+
3014+ if (!HeapTupleIsValid (rec -> tup ))
3015+ ereport (ERROR ,
3016+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
3017+ errmsg ("record \"%s\" is not assigned yet" ,
3018+ rec -> refname ),
3019+ errdetail ("The tuple structure of a not-yet-assigned record is indeterminate." )));
3020+ * typeid = rec -> tupdesc -> tdtypeid ;
3021+ * value = HeapTupleGetDatum (rec -> tup );
3022+ * isnull = false;
3023+ if (expectedtypeid != InvalidOid && expectedtypeid != * typeid )
3024+ ereport (ERROR ,
3025+ (errcode (ERRCODE_DATATYPE_MISMATCH ),
3026+ errmsg ("type of \"%s\" does not match that when preparing the plan" ,
3027+ rec -> refname )));
3028+ break ;
3029+ }
29923030
29933031 case PLPGSQL_DTYPE_RECFIELD :
2994- recfield = (PLpgSQL_recfield * ) datum ;
3032+ {
3033+ PLpgSQL_recfield * recfield = (PLpgSQL_recfield * ) datum ;
3034+ PLpgSQL_rec * rec ;
3035+ int fno ;
3036+
29953037 rec = (PLpgSQL_rec * ) (estate -> datums [recfield -> recparentno ]);
29963038 if (!HeapTupleIsValid (rec -> tup ))
29973039 ereport (ERROR ,
@@ -3013,9 +3055,13 @@ exec_eval_datum(PLpgSQL_execstate * estate,
30133055 errmsg ("type of \"%s.%s\" does not match that when preparing the plan" ,
30143056 rec -> refname , recfield -> fieldname )));
30153057 break ;
3058+ }
30163059
30173060 case PLPGSQL_DTYPE_TRIGARG :
3018- trigarg = (PLpgSQL_trigarg * ) datum ;
3061+ {
3062+ PLpgSQL_trigarg * trigarg = (PLpgSQL_trigarg * ) datum ;
3063+ int tgargno ;
3064+
30193065 * typeid = TEXTOID ;
30203066 tgargno = exec_eval_integer (estate , trigarg -> argnum , isnull );
30213067 if (* isnull || tgargno < 0 || tgargno >= estate -> trig_nargs )
@@ -3034,6 +3080,7 @@ exec_eval_datum(PLpgSQL_execstate * estate,
30343080 errmsg ("type of tgargv[%d] does not match that when preparing the plan" ,
30353081 tgargno )));
30363082 break ;
3083+ }
30373084
30383085 default :
30393086 elog (ERROR , "unrecognized dtype: %d" , datum -> dtype );
0 commit comments