2626 *
2727 *
2828 * IDENTIFICATION
29- * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.209 2003/05/08 18:16:36 tgl Exp $
29+ * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.210 2003/07/21 17:05:08 tgl Exp $
3030 *
3131 *-------------------------------------------------------------------------
3232 */
@@ -410,8 +410,8 @@ ExecCheckRTEPerms(RangeTblEntry *rte, CmdType operation)
410410aclcheck_result = CHECK (ACL_DELETE );
411411break ;
412412default :
413- elog (ERROR ,"ExecCheckRTEPerms: bogus operation %d" ,
414- operation );
413+ elog (ERROR ,"unrecognized operation code: %d" ,
414+ ( int ) operation );
415415aclcheck_result = ACLCHECK_OK ;/* keep compiler quiet */
416416break ;
417417}
@@ -455,7 +455,9 @@ ExecCheckXactReadOnly(Query *parsetree, CmdType operation)
455455return ;
456456
457457fail :
458- elog (ERROR ,"transaction is read-only" );
458+ ereport (ERROR ,
459+ (errcode (ERRCODE_READ_ONLY_SQL_TRANSACTION ),
460+ errmsg ("transaction is read-only" )));
459461}
460462
461463
@@ -833,16 +835,22 @@ initResultRelInfo(ResultRelInfo *resultRelInfo,
833835switch (resultRelationDesc -> rd_rel -> relkind )
834836{
835837case RELKIND_SEQUENCE :
836- elog (ERROR ,"You can't change sequence relation %s" ,
837- RelationGetRelationName (resultRelationDesc ));
838+ ereport (ERROR ,
839+ (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
840+ errmsg ("cannot change sequence relation \"%s\"" ,
841+ RelationGetRelationName (resultRelationDesc ))));
838842break ;
839843case RELKIND_TOASTVALUE :
840- elog (ERROR ,"You can't change toast relation %s" ,
841- RelationGetRelationName (resultRelationDesc ));
844+ ereport (ERROR ,
845+ (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
846+ errmsg ("cannot change toast relation \"%s\"" ,
847+ RelationGetRelationName (resultRelationDesc ))));
842848break ;
843849case RELKIND_VIEW :
844- elog (ERROR ,"You can't change view relation %s" ,
845- RelationGetRelationName (resultRelationDesc ));
850+ ereport (ERROR ,
851+ (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
852+ errmsg ("cannot change view relation \"%s\"" ,
853+ RelationGetRelationName (resultRelationDesc ))));
846854break ;
847855}
848856
@@ -1056,11 +1064,11 @@ lnext:;
10561064"ctid" ,
10571065& datum ,
10581066& isNull ))
1059- elog (ERROR ,"ExecutePlan: NO ( junk) ` ctid' was found! " );
1067+ elog (ERROR ,"could not find junk ctid column " );
10601068
10611069/* shouldn't ever get a null result... */
10621070if (isNull )
1063- elog (ERROR ,"ExecutePlan: (junk) ` ctid' is NULL! " );
1071+ elog (ERROR ,"ctid is NULL" );
10641072
10651073tupleid = (ItemPointer )DatumGetPointer (datum );
10661074tuple_ctid = * tupleid ;/* make sure we don't free the
@@ -1085,13 +1093,12 @@ lnext:;
10851093erm -> resname ,
10861094& datum ,
10871095& isNull ))
1088- elog (ERROR ,"ExecutePlan: NO ( junk) `%s' was found! " ,
1096+ elog (ERROR ,"could not find junk \"%s\" column " ,
10891097erm -> resname );
10901098
10911099/* shouldn't ever get a null result... */
10921100if (isNull )
1093- elog (ERROR ,"ExecutePlan: (junk) `%s' is NULL!" ,
1094- erm -> resname );
1101+ elog (ERROR ,"\"%s\" is NULL" ,erm -> resname );
10951102
10961103tuple .t_self = * ((ItemPointer )DatumGetPointer (datum ));
10971104test = heap_mark4update (erm -> relation ,& tuple ,& buffer ,
@@ -1108,7 +1115,9 @@ lnext:;
11081115
11091116case HeapTupleUpdated :
11101117if (XactIsoLevel == XACT_SERIALIZABLE )
1111- elog (ERROR ,"Can't serialize access due to concurrent update" );
1118+ ereport (ERROR ,
1119+ (errcode (ERRCODE_T_R_SERIALIZATION_FAILURE ),
1120+ errmsg ("cannot serialize access due to concurrent update" )));
11121121if (!(ItemPointerEquals (& (tuple .t_self ),
11131122 (ItemPointer )DatumGetPointer (datum ))))
11141123{
@@ -1129,7 +1138,8 @@ lnext:;
11291138gotolnext ;
11301139
11311140default :
1132- elog (ERROR ,"Unknown status %u from heap_mark4update" ,test );
1141+ elog (ERROR ,"unrecognized heap_mark4update status: %u" ,
1142+ test );
11331143return (NULL );
11341144}
11351145}
@@ -1178,7 +1188,8 @@ lnext:;
11781188break ;
11791189
11801190default :
1181- elog (LOG ,"ExecutePlan: unknown operation in queryDesc" );
1191+ elog (ERROR ,"unrecognized operation code: %d" ,
1192+ (int )operation );
11821193result = NULL ;
11831194break ;
11841195}
@@ -1321,7 +1332,7 @@ ExecInsert(TupleTableSlot *slot,
13211332 * Check the constraints of the tuple
13221333 */
13231334if (resultRelationDesc -> rd_att -> constr )
1324- ExecConstraints ("ExecInsert" , resultRelInfo ,slot ,estate );
1335+ ExecConstraints (resultRelInfo ,slot ,estate );
13251336
13261337/*
13271338 * insert the tuple
@@ -1403,7 +1414,9 @@ ldelete:;
14031414
14041415case HeapTupleUpdated :
14051416if (XactIsoLevel == XACT_SERIALIZABLE )
1406- elog (ERROR ,"Can't serialize access due to concurrent update" );
1417+ ereport (ERROR ,
1418+ (errcode (ERRCODE_T_R_SERIALIZATION_FAILURE ),
1419+ errmsg ("cannot serialize access due to concurrent update" )));
14071420else if (!(ItemPointerEquals (tupleid ,& ctid )))
14081421{
14091422TupleTableSlot * epqslot = EvalPlanQual (estate ,
@@ -1419,7 +1432,7 @@ ldelete:;
14191432return ;
14201433
14211434default :
1422- elog (ERROR ,"Unknown status %u from heap_delete " ,result );
1435+ elog (ERROR ,"unrecognized heap_delete status: %u" ,result );
14231436return ;
14241437}
14251438
@@ -1466,10 +1479,7 @@ ExecUpdate(TupleTableSlot *slot,
14661479 * abort the operation if not running transactions
14671480 */
14681481if (IsBootstrapProcessingMode ())
1469- {
1470- elog (WARNING ,"ExecUpdate: UPDATE can't run without transactions" );
1471- return ;
1472- }
1482+ elog (ERROR ,"cannot UPDATE during bootstrap" );
14731483
14741484/*
14751485 * get the heap tuple out of the tuple table slot
@@ -1519,7 +1529,7 @@ ExecUpdate(TupleTableSlot *slot,
15191529 */
15201530lreplace :;
15211531if (resultRelationDesc -> rd_att -> constr )
1522- ExecConstraints ("ExecUpdate" , resultRelInfo ,slot ,estate );
1532+ ExecConstraints (resultRelInfo ,slot ,estate );
15231533
15241534/*
15251535 * replace the heap tuple
@@ -1538,7 +1548,9 @@ lreplace:;
15381548
15391549case HeapTupleUpdated :
15401550if (XactIsoLevel == XACT_SERIALIZABLE )
1541- elog (ERROR ,"Can't serialize access due to concurrent update" );
1551+ ereport (ERROR ,
1552+ (errcode (ERRCODE_T_R_SERIALIZATION_FAILURE ),
1553+ errmsg ("cannot serialize access due to concurrent update" )));
15421554else if (!(ItemPointerEquals (tupleid ,& ctid )))
15431555{
15441556TupleTableSlot * epqslot = EvalPlanQual (estate ,
@@ -1558,7 +1570,7 @@ lreplace:;
15581570return ;
15591571
15601572default :
1561- elog (ERROR ,"Unknown status %u from heap_update " ,result );
1573+ elog (ERROR ,"unrecognized heap_update status: %u" ,result );
15621574return ;
15631575}
15641576
@@ -1591,7 +1603,7 @@ lreplace:;
15911603ExecARUpdateTriggers (estate ,resultRelInfo ,tupleid ,tuple );
15921604}
15931605
1594- static char *
1606+ static const char *
15951607ExecRelCheck (ResultRelInfo * resultRelInfo ,
15961608TupleTableSlot * slot ,EState * estate )
15971609{
@@ -1646,11 +1658,11 @@ ExecRelCheck(ResultRelInfo *resultRelInfo,
16461658}
16471659
16481660/* NULL result means no error */
1649- return ( char * ) NULL ;
1661+ return NULL ;
16501662}
16511663
16521664void
1653- ExecConstraints (const char * caller , ResultRelInfo * resultRelInfo ,
1665+ ExecConstraints (ResultRelInfo * resultRelInfo ,
16541666TupleTableSlot * slot ,EState * estate )
16551667{
16561668Relation rel = resultRelInfo -> ri_RelationDesc ;
@@ -1668,18 +1680,22 @@ ExecConstraints(const char *caller, ResultRelInfo *resultRelInfo,
16681680{
16691681if (rel -> rd_att -> attrs [attrChk - 1 ]-> attnotnull &&
16701682heap_attisnull (tuple ,attrChk ))
1671- elog (ERROR ,"%s: Fail to add null value in not null attribute %s" ,
1672- caller ,NameStr (rel -> rd_att -> attrs [attrChk - 1 ]-> attname ));
1683+ ereport (ERROR ,
1684+ (errcode (ERRCODE_NOT_NULL_VIOLATION ),
1685+ errmsg ("null value for attribute \"%s\" violates NOT NULL constraint" ,
1686+ NameStr (rel -> rd_att -> attrs [attrChk - 1 ]-> attname ))));
16731687}
16741688}
16751689
16761690if (constr -> num_check > 0 )
16771691{
1678- char * failed ;
1692+ const char * failed ;
16791693
16801694if ((failed = ExecRelCheck (resultRelInfo ,slot ,estate ))!= NULL )
1681- elog (ERROR ,"%s: rejected due to CHECK constraint \"%s\" on \"%s\"" ,
1682- caller ,failed ,RelationGetRelationName (rel ));
1695+ ereport (ERROR ,
1696+ (errcode (ERRCODE_CHECK_VIOLATION ),
1697+ errmsg ("new row for relation \"%s\" violates CHECK constraint \"%s\"" ,
1698+ RelationGetRelationName (rel ),failed )));
16831699}
16841700}
16851701
@@ -1721,7 +1737,7 @@ EvalPlanQual(EState *estate, Index rti, ItemPointer tid)
17211737}
17221738}
17231739if (relation == NULL )
1724- elog (ERROR ,"EvalPlanQual: can't findRTE %d" , ( int ) rti );
1740+ elog (ERROR ,"cannot findRowMark for RT index %u" , rti );
17251741}
17261742
17271743/*
@@ -1738,8 +1754,9 @@ EvalPlanQual(EState *estate, Index rti, ItemPointer tid)
17381754{
17391755TransactionId xwait = SnapshotDirty -> xmax ;
17401756
1757+ /* xmin should not be dirty... */
17411758if (TransactionIdIsValid (SnapshotDirty -> xmin ))
1742- elog (ERROR ,"EvalPlanQual: t_xmin is uncommitted?! " );
1759+ elog (ERROR ,"t_xmin is uncommittedin tuple to be updated " );
17431760
17441761/*
17451762 * If tuple is being updated by other transaction then we have