8
8
* Portions Copyright (c) 1994, Regents of the University of California
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -168,9 +168,11 @@ performDeletion(const ObjectAddress *object,
168
168
169
169
if (!recursiveDeletion (object , behavior , NOTICE ,
170
170
NULL , & 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." )));
174
176
175
177
term_object_addresses (& oktodelete );
176
178
@@ -226,8 +228,10 @@ deleteWhatDependsOn(const ObjectAddress *object,
226
228
DROP_CASCADE ,
227
229
showNotices ? NOTICE : DEBUG2 ,
228
230
& 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 )));
231
235
232
236
/*
233
237
* We do not need CommandCounterIncrement here, since if step 2 did
@@ -316,15 +320,17 @@ findAutoDeletableObjects(const ObjectAddress *object,
316
320
break ;
317
321
case DEPENDENCY_PIN :
318
322
/*
319
- * For a PIN dependency we just elog immediately; there
323
+ * For a PIN dependency we just ereport immediately; there
320
324
* won't be any others to examine, and we aren't ever
321
325
* going to let the user delete it.
322
326
*/
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 ))));
325
331
break ;
326
332
default :
327
- elog (ERROR , "findAutoDeletableObjects: unknown dependency type '%c' for %s" ,
333
+ elog (ERROR , "unrecognized dependency type '%c' for %s" ,
328
334
foundDep -> deptype , getObjectDescription (object ));
329
335
break ;
330
336
}
@@ -349,7 +355,7 @@ findAutoDeletableObjects(const ObjectAddress *object,
349
355
* depRel is the already-open pg_depend relation.
350
356
*
351
357
*
352
- * In RESTRICT mode, we perform all the deletions anyway, but elog a message
358
+ * In RESTRICT mode, we perform all the deletions anyway, but ereport a message
353
359
* and return FALSE if we find a restriction violation. performDeletion
354
360
* will then abort the transaction to nullify the deletions. We have to
355
361
* do it this way to (a) report all the direct and indirect dependencies
@@ -447,16 +453,19 @@ recursiveDeletion(const ObjectAddress *object,
447
453
* another object. We have three cases:
448
454
*
449
455
* 1. At the outermost recursion level, disallow the DROP.
450
- * (We just elog here, rather than proceeding, since no
456
+ * (We just ereport here, rather than proceeding, since no
451
457
* other dependencies are likely to be interesting.)
452
458
*/
453
459
if (callingObject == NULL )
454
460
{
455
461
char * otherObjDesc = getObjectDescription (& otherObject );
456
462
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 )));
460
469
}
461
470
462
471
/*
@@ -480,7 +489,7 @@ recursiveDeletion(const ObjectAddress *object,
480
489
* owning object to recurse back to me.
481
490
*/
482
491
if (amOwned ) /* shouldn't happen */
483
- elog (ERROR , "recursiveDeletion: multiple INTERNAL dependencies for %s" ,
492
+ elog (ERROR , "multiple INTERNAL dependencies for %s" ,
484
493
objDescription );
485
494
owningObject = otherObject ;
486
495
amOwned = true;
@@ -492,11 +501,11 @@ recursiveDeletion(const ObjectAddress *object,
492
501
* Should not happen; PIN dependencies should have zeroes
493
502
* in the depender fields...
494
503
*/
495
- elog (ERROR , "recursiveDeletion: incorrect use of PIN dependency with %s" ,
504
+ elog (ERROR , "incorrect use of PIN dependency with %s" ,
496
505
objDescription );
497
506
break ;
498
507
default :
499
- elog (ERROR , "recursiveDeletion: unknown dependency type '%c' for %s" ,
508
+ elog (ERROR , "unrecognized dependency type '%c' for %s" ,
500
509
foundDep -> deptype , objDescription );
501
510
break ;
502
511
}
@@ -522,18 +531,21 @@ recursiveDeletion(const ObjectAddress *object,
522
531
if (amOwned )
523
532
{
524
533
if (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 ))));
527
537
else if (behavior == DROP_RESTRICT )
528
538
{
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 )));
532
543
ok = false;
533
544
}
534
545
else
535
- elog (msglevel , "Drop cascades to %s" ,
536
- getObjectDescription (& owningObject ));
546
+ ereport (msglevel ,
547
+ (errmsg ("drop cascades to %s" ,
548
+ getObjectDescription (& owningObject ))));
537
549
538
550
if (!recursiveDeletion (& owningObject , behavior , msglevel ,
539
551
object , oktodelete , depRel ))
@@ -669,18 +681,21 @@ deleteDependentObjects(const ObjectAddress *object,
669
681
* In that case, act like this link is AUTO, too.
670
682
*/
671
683
if (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 ))));
674
687
else if (behavior == DROP_RESTRICT )
675
688
{
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 )));
679
693
ok = false;
680
694
}
681
695
else
682
- elog (msglevel , "Drop cascades to %s" ,
683
- getObjectDescription (& otherObject ));
696
+ ereport (msglevel ,
697
+ (errmsg ("drop cascades to %s" ,
698
+ getObjectDescription (& otherObject ))));
684
699
685
700
if (!recursiveDeletion (& otherObject , behavior , msglevel ,
686
701
object , oktodelete , depRel ))
@@ -694,8 +709,9 @@ deleteDependentObjects(const ObjectAddress *object,
694
709
* RESTRICT case. (However, normal dependencies on the
695
710
* component object could still cause failure.)
696
711
*/
697
- elog (DEBUG2 , "Drop auto-cascades to %s" ,
698
- getObjectDescription (& otherObject ));
712
+ ereport (DEBUG2 ,
713
+ (errmsg ("drop auto-cascades to %s" ,
714
+ getObjectDescription (& otherObject ))));
699
715
700
716
if (!recursiveDeletion (& otherObject , behavior , msglevel ,
701
717
object , oktodelete , depRel ))
@@ -704,14 +720,16 @@ deleteDependentObjects(const ObjectAddress *object,
704
720
case DEPENDENCY_PIN :
705
721
706
722
/*
707
- * For a PIN dependency we just elog immediately; there
723
+ * For a PIN dependency we just ereport immediately; there
708
724
* won't be any others to report.
709
725
*/
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 )));
712
730
break ;
713
731
default :
714
- elog (ERROR , "recursiveDeletion: unknown dependency type '%c' for %s" ,
732
+ elog (ERROR , "unrecognized dependency type '%c' for %s" ,
715
733
foundDep -> deptype , objDescription );
716
734
break ;
717
735
}
@@ -800,7 +818,7 @@ doDeletion(const ObjectAddress *object)
800
818
break ;
801
819
802
820
default :
803
- elog (ERROR , "doDeletion: Unsupported object class %u" ,
821
+ elog (ERROR , "unrecognized object class: %u" ,
804
822
object -> classId );
805
823
}
806
824
}
@@ -968,12 +986,10 @@ find_expr_references_walker(Node *node,
968
986
rtables = lnext (rtables );
969
987
}
970
988
if (rtables == NIL )
971
- elog (ERROR , "find_expr_references_walker: bogus varlevelsup %d" ,
972
- var -> varlevelsup );
989
+ elog (ERROR , "invalid varlevelsup %d" , var -> varlevelsup );
973
990
rtable = lfirst (rtables );
974
991
if (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 );
977
993
rte = rt_fetch (var -> varno , rtable );
978
994
if (rte -> rtekind == RTE_RELATION )
979
995
{
@@ -992,8 +1008,7 @@ find_expr_references_walker(Node *node,
992
1008
context -> rtables = rtables ;
993
1009
if (var -> varattno <= 0 ||
994
1010
var -> 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 );
997
1012
find_expr_references_walker ((Node * ) nth (var -> varattno - 1 ,
998
1013
rte -> joinaliasvars ),
999
1014
context );
@@ -1064,7 +1079,7 @@ find_expr_references_walker(Node *node,
1064
1079
if (is_subplan (node ))
1065
1080
{
1066
1081
/* 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" );
1068
1083
}
1069
1084
if (IsA (node , Query ))
1070
1085
{
@@ -1400,8 +1415,7 @@ getObjectClass(const ObjectAddress *object)
1400
1415
return OCLASS_SCHEMA ;
1401
1416
}
1402
1417
1403
- elog (ERROR , "getObjectClass: Unknown object class %u" ,
1404
- object -> classId );
1418
+ elog (ERROR , "unrecognized object class: %u" , object -> classId );
1405
1419
return OCLASS_CLASS ; /* keep compiler quiet */
1406
1420
}
1407
1421
@@ -1457,7 +1471,7 @@ getObjectDescription(const ObjectAddress *object)
1457
1471
tup = systable_getnext (rcscan );
1458
1472
1459
1473
if (!HeapTupleIsValid (tup ))
1460
- elog (ERROR , "getObjectDescription: Cast %u does not exist " ,
1474
+ elog (ERROR , "could not find tuple for cast %u " ,
1461
1475
object -> objectId );
1462
1476
1463
1477
castForm = (Form_pg_cast ) GETSTRUCT (tup );
@@ -1491,7 +1505,7 @@ getObjectDescription(const ObjectAddress *object)
1491
1505
tup = systable_getnext (rcscan );
1492
1506
1493
1507
if (!HeapTupleIsValid (tup ))
1494
- elog (ERROR , "getObjectDescription: Constraint %u does not exist " ,
1508
+ elog (ERROR , "could not find tuple for constraint %u " ,
1495
1509
object -> objectId );
1496
1510
1497
1511
con = (Form_pg_constraint ) GETSTRUCT (tup );
@@ -1521,7 +1535,7 @@ getObjectDescription(const ObjectAddress *object)
1521
1535
ObjectIdGetDatum (object -> objectId ),
1522
1536
0 , 0 , 0 );
1523
1537
if (!HeapTupleIsValid (conTup ))
1524
- elog (ERROR , "getObjectDescription: Conversion %u does not exist " ,
1538
+ elog (ERROR , "cache lookup failed for conversion %u " ,
1525
1539
object -> objectId );
1526
1540
appendStringInfo (& buffer , "conversion %s" ,
1527
1541
NameStr (((Form_pg_conversion ) GETSTRUCT (conTup ))-> conname ));
@@ -1550,7 +1564,7 @@ getObjectDescription(const ObjectAddress *object)
1550
1564
tup = systable_getnext (adscan );
1551
1565
1552
1566
if (!HeapTupleIsValid (tup ))
1553
- elog (ERROR , "getObjectDescription: Default %u does not exist " ,
1567
+ elog (ERROR , "could not find tuple for attrdef %u " ,
1554
1568
object -> objectId );
1555
1569
1556
1570
attrdef = (Form_pg_attrdef ) GETSTRUCT (tup );
@@ -1575,7 +1589,7 @@ getObjectDescription(const ObjectAddress *object)
1575
1589
ObjectIdGetDatum (object -> objectId ),
1576
1590
0 , 0 , 0 );
1577
1591
if (!HeapTupleIsValid (langTup ))
1578
- elog (ERROR , "getObjectDescription: Language %u does not exist " ,
1592
+ elog (ERROR , "cache lookup failed for language %u " ,
1579
1593
object -> objectId );
1580
1594
appendStringInfo (& buffer , "language %s" ,
1581
1595
NameStr (((Form_pg_language ) GETSTRUCT (langTup ))-> lanname ));
@@ -1600,7 +1614,7 @@ getObjectDescription(const ObjectAddress *object)
1600
1614
ObjectIdGetDatum (object -> objectId ),
1601
1615
0 , 0 , 0 );
1602
1616
if (!HeapTupleIsValid (opcTup ))
1603
- elog (ERROR , "cache lookup of opclass %u failed " ,
1617
+ elog (ERROR , "cache lookup failed for opclass %u" ,
1604
1618
object -> objectId );
1605
1619
opcForm = (Form_pg_opclass ) GETSTRUCT (opcTup );
1606
1620
@@ -1618,7 +1632,7 @@ getObjectDescription(const ObjectAddress *object)
1618
1632
ObjectIdGetDatum (opcForm -> opcamid ),
1619
1633
0 , 0 , 0 );
1620
1634
if (!HeapTupleIsValid (amTup ))
1621
- elog (ERROR , "syscache lookup for AM %u failed " ,
1635
+ elog (ERROR , "cache lookup failed for access method %u " ,
1622
1636
opcForm -> opcamid );
1623
1637
amForm = (Form_pg_am ) GETSTRUCT (amTup );
1624
1638
@@ -1650,7 +1664,7 @@ getObjectDescription(const ObjectAddress *object)
1650
1664
tup = systable_getnext (rcscan );
1651
1665
1652
1666
if (!HeapTupleIsValid (tup ))
1653
- elog (ERROR , "getObjectDescription: Rule %u does not exist " ,
1667
+ elog (ERROR , "could not find tuple for rule %u " ,
1654
1668
object -> objectId );
1655
1669
1656
1670
rule = (Form_pg_rewrite ) GETSTRUCT (tup );
@@ -1684,7 +1698,7 @@ getObjectDescription(const ObjectAddress *object)
1684
1698
tup = systable_getnext (tgscan );
1685
1699
1686
1700
if (!HeapTupleIsValid (tup ))
1687
- elog (ERROR , "getObjectDescription: Trigger %u does not exist " ,
1701
+ elog (ERROR , "could not find tuple for trigger %u " ,
1688
1702
object -> objectId );
1689
1703
1690
1704
trig = (Form_pg_trigger ) GETSTRUCT (tup );
@@ -1704,7 +1718,7 @@ getObjectDescription(const ObjectAddress *object)
1704
1718
1705
1719
nspname = get_namespace_name (object -> objectId );
1706
1720
if (!nspname )
1707
- elog (ERROR , "getObjectDescription: Schema %u does not exist " ,
1721
+ elog (ERROR , "cache lookup failed for namespace %u " ,
1708
1722
object -> objectId );
1709
1723
appendStringInfo (& buffer , "schema %s" , nspname );
1710
1724
break ;
@@ -1736,7 +1750,7 @@ getRelationDescription(StringInfo buffer, Oid relid)
1736
1750
ObjectIdGetDatum (relid ),
1737
1751
0 , 0 , 0 );
1738
1752
if (!HeapTupleIsValid (relTup ))
1739
- elog (ERROR , "cache lookup of relation %u failed " , relid );
1753
+ elog (ERROR , "cache lookup failed for relation %u" , relid );
1740
1754
relForm = (Form_pg_class ) GETSTRUCT (relTup );
1741
1755
1742
1756
/* Qualify the name if not visible in search path */
0 commit comments