88 * Portions Copyright (c) 1994, Regents of the University of California
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.26 2003/06/29 00:33:42 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.27 2003/07/21 01:59:07 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -168,9 +168,11 @@ performDeletion(const ObjectAddress *object,
168168
169169if (!recursiveDeletion (object ,behavior ,NOTICE ,
170170NULL ,& oktodelete ,depRel ))
171- elog (ERROR ,"Cannot drop %s because other objects depend on it"
172- "\n\tUse DROP ... CASCADE to drop the dependent objects too" ,
173- objDescription );
171+ ereport (ERROR ,
172+ (errcode (ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST ),
173+ errmsg ("cannot drop %s because other objects depend on it" ,
174+ objDescription ),
175+ errhint ("Use DROP ... CASCADE to drop the dependent objects too." )));
174176
175177term_object_addresses (& oktodelete );
176178
@@ -226,8 +228,10 @@ deleteWhatDependsOn(const ObjectAddress *object,
226228DROP_CASCADE ,
227229showNotices ?NOTICE :DEBUG2 ,
228230& oktodelete ,depRel ))
229- elog (ERROR ,"Failed to drop all objects depending on %s" ,
230- objDescription );
231+ ereport (ERROR ,
232+ (errcode (ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST ),
233+ errmsg ("failed to drop all objects depending on %s" ,
234+ objDescription )));
231235
232236/*
233237 * We do not need CommandCounterIncrement here, since if step 2 did
@@ -316,15 +320,17 @@ findAutoDeletableObjects(const ObjectAddress *object,
316320break ;
317321case DEPENDENCY_PIN :
318322/*
319- * For a PIN dependency we justelog immediately; there
323+ * For a PIN dependency we justereport immediately; there
320324 * won't be any others to examine, and we aren't ever
321325 * going to let the user delete it.
322326 */
323- elog (ERROR ,"Cannot drop %s because it is required by the database system" ,
324- getObjectDescription (object ));
327+ ereport (ERROR ,
328+ (errcode (ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST ),
329+ errmsg ("cannot drop %s because it is required by the database system" ,
330+ getObjectDescription (object ))));
325331break ;
326332default :
327- elog (ERROR ,"findAutoDeletableObjects: unknown dependency type '%c' for %s" ,
333+ elog (ERROR ,"unrecognized dependency type '%c' for %s" ,
328334foundDep -> deptype ,getObjectDescription (object ));
329335break ;
330336}
@@ -349,7 +355,7 @@ findAutoDeletableObjects(const ObjectAddress *object,
349355 * depRel is the already-open pg_depend relation.
350356 *
351357 *
352- * In RESTRICT mode, we perform all the deletions anyway, butelog a message
358+ * In RESTRICT mode, we perform all the deletions anyway, butereport a message
353359 * and return FALSE if we find a restriction violation. performDeletion
354360 * will then abort the transaction to nullify the deletions. We have to
355361 * do it this way to (a) report all the direct and indirect dependencies
@@ -447,16 +453,19 @@ recursiveDeletion(const ObjectAddress *object,
447453 * another object.We have three cases:
448454 *
449455 * 1. At the outermost recursion level, disallow the DROP.
450- * (We justelog here, rather than proceeding, since no
456+ * (We justereport here, rather than proceeding, since no
451457 * other dependencies are likely to be interesting.)
452458 */
453459if (callingObject == NULL )
454460{
455461char * otherObjDesc = getObjectDescription (& otherObject );
456462
457- elog (ERROR ,"Cannot drop %s because %s requires it"
458- "\n\tYou may drop %s instead" ,
459- objDescription ,otherObjDesc ,otherObjDesc );
463+ ereport (ERROR ,
464+ (errcode (ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST ),
465+ errmsg ("cannot drop %s because %s requires it" ,
466+ objDescription ,otherObjDesc ),
467+ errhint ("You may drop %s instead." ,
468+ otherObjDesc )));
460469}
461470
462471/*
@@ -480,7 +489,7 @@ recursiveDeletion(const ObjectAddress *object,
480489 * owning object to recurse back to me.
481490 */
482491if (amOwned )/* shouldn't happen */
483- elog (ERROR ,"recursiveDeletion: multiple INTERNAL dependencies for %s" ,
492+ elog (ERROR ,"multiple INTERNAL dependencies for %s" ,
484493objDescription );
485494owningObject = otherObject ;
486495amOwned = true;
@@ -492,11 +501,11 @@ recursiveDeletion(const ObjectAddress *object,
492501 * Should not happen; PIN dependencies should have zeroes
493502 * in the depender fields...
494503 */
495- elog (ERROR ,"recursiveDeletion: incorrect use of PIN dependency with %s" ,
504+ elog (ERROR ,"incorrect use of PIN dependency with %s" ,
496505objDescription );
497506break ;
498507default :
499- elog (ERROR ,"recursiveDeletion: unknown dependency type '%c' for %s" ,
508+ elog (ERROR ,"unrecognized dependency type '%c' for %s" ,
500509foundDep -> deptype ,objDescription );
501510break ;
502511}
@@ -522,18 +531,21 @@ recursiveDeletion(const ObjectAddress *object,
522531if (amOwned )
523532{
524533if (object_address_present (& owningObject ,oktodelete ))
525- elog (DEBUG2 ,"Drop auto-cascades to %s" ,
526- getObjectDescription (& owningObject ));
534+ ereport (DEBUG2 ,
535+ (errmsg ("drop auto-cascades to %s" ,
536+ getObjectDescription (& owningObject ))));
527537else if (behavior == DROP_RESTRICT )
528538{
529- elog (msglevel ,"%s depends on %s" ,
530- getObjectDescription (& owningObject ),
531- objDescription );
539+ ereport (msglevel ,
540+ (errmsg ("%s depends on %s" ,
541+ getObjectDescription (& owningObject ),
542+ objDescription )));
532543ok = false;
533544}
534545else
535- elog (msglevel ,"Drop cascades to %s" ,
536- getObjectDescription (& owningObject ));
546+ ereport (msglevel ,
547+ (errmsg ("drop cascades to %s" ,
548+ getObjectDescription (& owningObject ))));
537549
538550if (!recursiveDeletion (& owningObject ,behavior ,msglevel ,
539551object ,oktodelete ,depRel ))
@@ -669,18 +681,21 @@ deleteDependentObjects(const ObjectAddress *object,
669681 * In that case, act like this link is AUTO, too.
670682 */
671683if (object_address_present (& otherObject ,oktodelete ))
672- elog (DEBUG2 ,"Drop auto-cascades to %s" ,
673- getObjectDescription (& otherObject ));
684+ ereport (DEBUG2 ,
685+ (errmsg ("drop auto-cascades to %s" ,
686+ getObjectDescription (& otherObject ))));
674687else if (behavior == DROP_RESTRICT )
675688{
676- elog (msglevel ,"%s depends on %s" ,
677- getObjectDescription (& otherObject ),
678- objDescription );
689+ ereport (msglevel ,
690+ (errmsg ("%s depends on %s" ,
691+ getObjectDescription (& otherObject ),
692+ objDescription )));
679693ok = false;
680694}
681695else
682- elog (msglevel ,"Drop cascades to %s" ,
683- getObjectDescription (& otherObject ));
696+ ereport (msglevel ,
697+ (errmsg ("drop cascades to %s" ,
698+ getObjectDescription (& otherObject ))));
684699
685700if (!recursiveDeletion (& otherObject ,behavior ,msglevel ,
686701object ,oktodelete ,depRel ))
@@ -694,8 +709,9 @@ deleteDependentObjects(const ObjectAddress *object,
694709 * RESTRICT case. (However, normal dependencies on the
695710 * component object could still cause failure.)
696711 */
697- elog (DEBUG2 ,"Drop auto-cascades to %s" ,
698- getObjectDescription (& otherObject ));
712+ ereport (DEBUG2 ,
713+ (errmsg ("drop auto-cascades to %s" ,
714+ getObjectDescription (& otherObject ))));
699715
700716if (!recursiveDeletion (& otherObject ,behavior ,msglevel ,
701717object ,oktodelete ,depRel ))
@@ -704,14 +720,16 @@ deleteDependentObjects(const ObjectAddress *object,
704720case DEPENDENCY_PIN :
705721
706722/*
707- * For a PIN dependency we justelog immediately; there
723+ * For a PIN dependency we justereport immediately; there
708724 * won't be any others to report.
709725 */
710- elog (ERROR ,"Cannot drop %s because it is required by the database system" ,
711- objDescription );
726+ ereport (ERROR ,
727+ (errcode (ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST ),
728+ errmsg ("cannot drop %s because it is required by the database system" ,
729+ objDescription )));
712730break ;
713731default :
714- elog (ERROR ,"recursiveDeletion: unknown dependency type '%c' for %s" ,
732+ elog (ERROR ,"unrecognized dependency type '%c' for %s" ,
715733foundDep -> deptype ,objDescription );
716734break ;
717735}
@@ -800,7 +818,7 @@ doDeletion(const ObjectAddress *object)
800818break ;
801819
802820default :
803- elog (ERROR ,"doDeletion: Unsupported object class %u" ,
821+ elog (ERROR ,"unrecognized object class: %u" ,
804822object -> classId );
805823}
806824}
@@ -968,12 +986,10 @@ find_expr_references_walker(Node *node,
968986rtables = lnext (rtables );
969987}
970988if (rtables == NIL )
971- elog (ERROR ,"find_expr_references_walker: bogus varlevelsup %d" ,
972- var -> varlevelsup );
989+ elog (ERROR ,"invalid varlevelsup %d" ,var -> varlevelsup );
973990rtable = lfirst (rtables );
974991if (var -> varno <=0 || var -> varno > length (rtable ))
975- elog (ERROR ,"find_expr_references_walker: bogus varno %d" ,
976- var -> varno );
992+ elog (ERROR ,"invalid varno %d" ,var -> varno );
977993rte = rt_fetch (var -> varno ,rtable );
978994if (rte -> rtekind == RTE_RELATION )
979995{
@@ -992,8 +1008,7 @@ find_expr_references_walker(Node *node,
9921008context -> rtables = rtables ;
9931009if (var -> varattno <=0 ||
9941010var -> varattno > length (rte -> joinaliasvars ))
995- elog (ERROR ,"find_expr_references_walker: bogus varattno %d" ,
996- var -> varattno );
1011+ elog (ERROR ,"invalid varattno %d" ,var -> varattno );
9971012find_expr_references_walker ((Node * )nth (var -> varattno - 1 ,
9981013rte -> joinaliasvars ),
9991014context );
@@ -1064,7 +1079,7 @@ find_expr_references_walker(Node *node,
10641079if (is_subplan (node ))
10651080{
10661081/* Extra work needed here if we ever need this case */
1067- elog (ERROR ,"find_expr_references_walker: already-planned subqueries not supported" );
1082+ elog (ERROR ,"already-planned subqueries not supported" );
10681083}
10691084if (IsA (node ,Query ))
10701085{
@@ -1400,8 +1415,7 @@ getObjectClass(const ObjectAddress *object)
14001415return OCLASS_SCHEMA ;
14011416}
14021417
1403- elog (ERROR ,"getObjectClass: Unknown object class %u" ,
1404- object -> classId );
1418+ elog (ERROR ,"unrecognized object class: %u" ,object -> classId );
14051419return OCLASS_CLASS ;/* keep compiler quiet */
14061420}
14071421
@@ -1457,7 +1471,7 @@ getObjectDescription(const ObjectAddress *object)
14571471tup = systable_getnext (rcscan );
14581472
14591473if (!HeapTupleIsValid (tup ))
1460- elog (ERROR ,"getObjectDescription: Cast %u does not exist " ,
1474+ elog (ERROR ,"could not find tuple for cast %u " ,
14611475object -> objectId );
14621476
14631477castForm = (Form_pg_cast )GETSTRUCT (tup );
@@ -1491,7 +1505,7 @@ getObjectDescription(const ObjectAddress *object)
14911505tup = systable_getnext (rcscan );
14921506
14931507if (!HeapTupleIsValid (tup ))
1494- elog (ERROR ,"getObjectDescription: Constraint %u does not exist " ,
1508+ elog (ERROR ,"could not find tuple for constraint %u " ,
14951509object -> objectId );
14961510
14971511con = (Form_pg_constraint )GETSTRUCT (tup );
@@ -1521,7 +1535,7 @@ getObjectDescription(const ObjectAddress *object)
15211535ObjectIdGetDatum (object -> objectId ),
152215360 ,0 ,0 );
15231537if (!HeapTupleIsValid (conTup ))
1524- elog (ERROR ,"getObjectDescription: Conversion %u does not exist " ,
1538+ elog (ERROR ,"cache lookup failed for conversion %u " ,
15251539object -> objectId );
15261540appendStringInfo (& buffer ,"conversion %s" ,
15271541NameStr (((Form_pg_conversion )GETSTRUCT (conTup ))-> conname ));
@@ -1550,7 +1564,7 @@ getObjectDescription(const ObjectAddress *object)
15501564tup = systable_getnext (adscan );
15511565
15521566if (!HeapTupleIsValid (tup ))
1553- elog (ERROR ,"getObjectDescription: Default %u does not exist " ,
1567+ elog (ERROR ,"could not find tuple for attrdef %u " ,
15541568object -> objectId );
15551569
15561570attrdef = (Form_pg_attrdef )GETSTRUCT (tup );
@@ -1575,7 +1589,7 @@ getObjectDescription(const ObjectAddress *object)
15751589ObjectIdGetDatum (object -> objectId ),
157615900 ,0 ,0 );
15771591if (!HeapTupleIsValid (langTup ))
1578- elog (ERROR ,"getObjectDescription: Language %u does not exist " ,
1592+ elog (ERROR ,"cache lookup failed for language %u " ,
15791593object -> objectId );
15801594appendStringInfo (& buffer ,"language %s" ,
15811595NameStr (((Form_pg_language )GETSTRUCT (langTup ))-> lanname ));
@@ -1600,7 +1614,7 @@ getObjectDescription(const ObjectAddress *object)
16001614ObjectIdGetDatum (object -> objectId ),
160116150 ,0 ,0 );
16021616if (!HeapTupleIsValid (opcTup ))
1603- elog (ERROR ,"cache lookupof opclass %u failed " ,
1617+ elog (ERROR ,"cache lookupfailed for opclass %u" ,
16041618object -> objectId );
16051619opcForm = (Form_pg_opclass )GETSTRUCT (opcTup );
16061620
@@ -1618,7 +1632,7 @@ getObjectDescription(const ObjectAddress *object)
16181632ObjectIdGetDatum (opcForm -> opcamid ),
161916330 ,0 ,0 );
16201634if (!HeapTupleIsValid (amTup ))
1621- elog (ERROR ,"syscache lookup forAM %u failed " ,
1635+ elog (ERROR ,"cache lookupfailed foraccess method %u " ,
16221636opcForm -> opcamid );
16231637amForm = (Form_pg_am )GETSTRUCT (amTup );
16241638
@@ -1650,7 +1664,7 @@ getObjectDescription(const ObjectAddress *object)
16501664tup = systable_getnext (rcscan );
16511665
16521666if (!HeapTupleIsValid (tup ))
1653- elog (ERROR ,"getObjectDescription: Rule %u does not exist " ,
1667+ elog (ERROR ,"could not find tuple for rule %u " ,
16541668object -> objectId );
16551669
16561670rule = (Form_pg_rewrite )GETSTRUCT (tup );
@@ -1684,7 +1698,7 @@ getObjectDescription(const ObjectAddress *object)
16841698tup = systable_getnext (tgscan );
16851699
16861700if (!HeapTupleIsValid (tup ))
1687- elog (ERROR ,"getObjectDescription: Trigger %u does not exist " ,
1701+ elog (ERROR ,"could not find tuple for trigger %u " ,
16881702object -> objectId );
16891703
16901704trig = (Form_pg_trigger )GETSTRUCT (tup );
@@ -1704,7 +1718,7 @@ getObjectDescription(const ObjectAddress *object)
17041718
17051719nspname = get_namespace_name (object -> objectId );
17061720if (!nspname )
1707- elog (ERROR ,"getObjectDescription: Schema %u does not exist " ,
1721+ elog (ERROR ,"cache lookup failed for namespace %u " ,
17081722object -> objectId );
17091723appendStringInfo (& buffer ,"schema %s" ,nspname );
17101724break ;
@@ -1736,7 +1750,7 @@ getRelationDescription(StringInfo buffer, Oid relid)
17361750ObjectIdGetDatum (relid ),
173717510 ,0 ,0 );
17381752if (!HeapTupleIsValid (relTup ))
1739- elog (ERROR ,"cache lookupof relation %u failed " ,relid );
1753+ elog (ERROR ,"cache lookupfailed for relation %u" ,relid );
17401754relForm = (Form_pg_class )GETSTRUCT (relTup );
17411755
17421756/* Qualify the name if not visible in search path */