Skip to content

Commit 9ee4891

Browse files
committed
Some quick fixes for ALTER DOMAIN patch. It still needs a lot of work,
but at least it doesn't generate gcc warnings.
1 parent 4ed6be5 commit 9ee4891

File tree

1 file changed

+76
-96
lines changed

1 file changed

+76
-96
lines changed

src/backend/commands/typecmds.c

Lines changed: 76 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.20 2002/12/06 05:00:11 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.21 2002/12/09 20:31:05 tgl Exp $
1212
*
1313
* DESCRIPTION
1414
* The "DefineFoo" routines take the parse tree and pick out the
@@ -63,7 +63,6 @@
6363
static Oid findTypeIOFunction(List *procname, Oid typeOid, bool isOutput);
6464
static List *get_rels_with_domain(Oid domainOid);
6565
static void domainPermissionCheck(HeapTuple tup, TypeName *typename);
66-
static void domainCheckForUnsupportedConstraints(Node *newConstraint);
6766
static char *domainAddConstraint(Oid domainOid, Oid domainNamespace,
6867
Oid baseTypeOid,
6968
int typMod, Constraint *constr,
@@ -519,24 +518,23 @@ DefineDomain(CreateDomainStmt *stmt)
519518
Constraint *colDef;
520519
ParseState *pstate;
521520

522-
/*
523-
* Check for constraint types which are not supported by
524-
* domains. Throws an error if it finds one.
525-
*/
526-
domainCheckForUnsupportedConstraints(newConstraint);
521+
/* Check for unsupported constraint types */
522+
if (IsA(newConstraint, FkConstraint))
523+
elog(ERROR, "CREATE DOMAIN / FOREIGN KEY constraints not supported");
524+
525+
/* this case should not happen */
526+
if (!IsA(newConstraint, Constraint))
527+
elog(ERROR, "DefineDomain: unexpected constraint node type");
527528

528-
/* Assume its a CHECK, DEFAULT, NULL or NOT NULL constraint */
529529
colDef = (Constraint *) newConstraint;
530+
530531
switch (colDef->contype)
531532
{
533+
case CONSTR_DEFAULT:
532534
/*
533535
* The inherited default value may be overridden by the
534536
* user with the DEFAULT <expr> statement.
535-
*
536-
* We have to search the entire constraint tree returned as
537-
* we don't want to cook or fiddle too much.
538537
*/
539-
case CONSTR_DEFAULT:
540538
if (defaultExpr)
541539
elog(ERROR, "CREATE DOMAIN has multiple DEFAULT expressions");
542540
/* Create a dummy ParseState for transformExpr */
@@ -563,9 +561,6 @@ DefineDomain(CreateDomainStmt *stmt)
563561
defaultValueBin = nodeToString(defaultExpr);
564562
break;
565563

566-
/*
567-
* Find the NULL constraint.
568-
*/
569564
case CONSTR_NOTNULL:
570565
if (nullDefined)
571566
elog(ERROR, "CREATE DOMAIN has conflicting NULL / NOT NULL constraint");
@@ -580,19 +575,34 @@ DefineDomain(CreateDomainStmt *stmt)
580575
nullDefined = true;
581576
break;
582577

583-
/*
584-
* Check constraints are handled after domain creation, as they require
585-
* the Oid of the domain
586-
*/
587578
case CONSTR_CHECK:
579+
/*
580+
* Check constraints are handled after domain creation, as they
581+
* require the Oid of the domain
582+
*/
583+
break;
584+
585+
/*
586+
* All else are error cases
587+
*/
588+
case CONSTR_UNIQUE:
589+
elog(ERROR, "CREATE DOMAIN / UNIQUE not supported");
590+
break;
591+
592+
case CONSTR_PRIMARY:
593+
elog(ERROR, "CREATE DOMAIN / PRIMARY KEY not supported");
594+
break;
595+
596+
case CONSTR_ATTR_DEFERRABLE:
597+
case CONSTR_ATTR_NOT_DEFERRABLE:
598+
case CONSTR_ATTR_DEFERRED:
599+
case CONSTR_ATTR_IMMEDIATE:
600+
elog(ERROR, "CREATE DOMAIN: DEFERRABLE, NON DEFERRABLE, DEFERRED"
601+
" and IMMEDIATE not supported");
588602
break;
589603

590-
/*
591-
* If we reach this, then domainCheckForUnsupportedConstraints()
592-
* doesn't have a complete list of unsupported domain constraints
593-
*/
594604
default:
595-
elog(ERROR, "DefineDomain: unrecognized constraint node type");
605+
elog(ERROR, "DefineDomain: unrecognized constraint subtype");
596606
break;
597607
}
598608
}
@@ -629,6 +639,8 @@ DefineDomain(CreateDomainStmt *stmt)
629639
{
630640
Constraint *constr = lfirst(listptr);
631641

642+
/* it must be a Constraint, per check above */
643+
632644
switch (constr->contype)
633645
{
634646
case CONSTR_CHECK:
@@ -642,7 +654,8 @@ DefineDomain(CreateDomainStmt *stmt)
642654
}
643655
break;
644656

645-
/* Errors for other constraints are taken care of prior to domain creation */
657+
/* Other constraint types were fully processed above */
658+
646659
default:
647660
break;
648661
}
@@ -1262,21 +1275,21 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
12621275
elog(ERROR, "AlterDomain: type \"%s\" does not exist",
12631276
TypeNameToString(typename));
12641277

1278+
typTup = (Form_pg_type) GETSTRUCT(tup);
12651279

12661280
/* Doesn't return if user isn't allowed to alter the domain */
12671281
domainPermissionCheck(tup, typename);
12681282

1269-
typTup = (Form_pg_type) GETSTRUCT(tup);
1270-
1283+
/* Check for unsupported constraint types */
1284+
if (IsA(newConstraint, FkConstraint))
1285+
elog(ERROR, "ALTER DOMAIN / FOREIGN KEY constraints not supported");
12711286

1272-
/*
1273-
* Check for constraint types which are not supported by
1274-
* domains. Throws an error if it finds one.
1275-
*/
1276-
domainCheckForUnsupportedConstraints(newConstraint);
1287+
/* this case should not happen */
1288+
if (!IsA(newConstraint, Constraint))
1289+
elog(ERROR, "AlterDomainAddConstraint: unexpected constraint node type");
12771290

1278-
/* Assume its a CHECK, DEFAULT, NULL or NOT NULL constraint */
12791291
constr = (Constraint *) newConstraint;
1292+
12801293
switch (constr->contype)
12811294
{
12821295
case CONSTR_DEFAULT:
@@ -1288,32 +1301,42 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
12881301
elog(ERROR, "Use ALTER DOMAIN .. [ SET | DROP ] NOT NULL instead");
12891302
break;
12901303

1291-
/*
1292-
* Check constraints are handled after domain creation, as they require
1293-
* the Oid of the domain
1294-
*/
12951304
case CONSTR_CHECK:
1296-
{
1297-
/* Returns the cooked constraint which is not needed during creation */
1298-
ccbin = domainAddConstraint(HeapTupleGetOid(tup), typTup->typnamespace,
1299-
typTup->typbasetype, typTup->typtypmod,
1300-
constr, &counter, NameStr(typTup->typname));
1301-
}
1305+
/* processed below */
13021306
break;
13031307

1304-
/*
1305-
* If we reach this, then domainCheckForUnsupportedConstraints()
1306-
* doesn't have a complete list of unsupported domain constraints
1307-
*/
1308+
case CONSTR_UNIQUE:
1309+
elog(ERROR, "ALTER DOMAIN / UNIQUE indexes not supported");
1310+
break;
1311+
1312+
case CONSTR_PRIMARY:
1313+
elog(ERROR, "ALTER DOMAIN / PRIMARY KEY indexes not supported");
1314+
break;
1315+
1316+
case CONSTR_ATTR_DEFERRABLE:
1317+
case CONSTR_ATTR_NOT_DEFERRABLE:
1318+
case CONSTR_ATTR_DEFERRED:
1319+
case CONSTR_ATTR_IMMEDIATE:
1320+
elog(ERROR, "ALTER DOMAIN: DEFERRABLE, NON DEFERRABLE, DEFERRED"
1321+
" and IMMEDIATE not supported");
1322+
break;
1323+
13081324
default:
1309-
elog(ERROR, "DefineDomain: unrecognized constraint node type");
1325+
elog(ERROR, "AlterDomainAddConstraint: unrecognized constraint node type");
13101326
break;
13111327
}
13121328

13131329
/*
13141330
* Since all other constraint types throw errors, this must be
1315-
* a check constraint, and ccbin must be set.
1316-
*
1331+
* a check constraint.
1332+
*/
1333+
1334+
/* Returns the cooked constraint which is not needed during creation */
1335+
ccbin = domainAddConstraint(HeapTupleGetOid(tup), typTup->typnamespace,
1336+
typTup->typbasetype, typTup->typtypmod,
1337+
constr, &counter, NameStr(typTup->typname));
1338+
1339+
/*
13171340
* Test all values stored in the attributes based on the domain
13181341
* the constraint is being added to.
13191342
*/
@@ -1424,7 +1447,7 @@ get_rels_with_domain(Oid domainOid)
14241447
/* Scan through pg_class for tables */
14251448
while ((classTup = heap_getnext(classScan, ForwardScanDirection)) != NULL)
14261449
{
1427-
bool addToList = true;
1450+
relToCheck *rtc = NULL;
14281451
int nkeys = 0;
14291452
HeapTuple attTup;
14301453
HeapScanDesc attScan;
@@ -1447,13 +1470,9 @@ get_rels_with_domain(Oid domainOid)
14471470
/* Scan through pg_attribute for attributes based on the domain */
14481471
while ((attTup = heap_getnext(attScan, ForwardScanDirection)) != NULL)
14491472
{
1450-
relToCheck *rtc;
1451-
1452-
/* Make the list entries for the relation */
1453-
if (addToList)
1473+
if (rtc == NULL)
14541474
{
1455-
addToList = false;
1456-
1475+
/* First one found for this rel */
14571476
rtc = (relToCheck *)palloc(sizeof(relToCheck));
14581477
rtc->atts = (int *)palloc(sizeof(int) * pg_class->relnatts);
14591478
rtc->relOid = HeapTupleGetOid(classTup);
@@ -1625,42 +1644,3 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
16251644
*/
16261645
return ccbin;
16271646
}
1628-
1629-
/*
1630-
* domainCheckForUnsupportedConstraints
1631-
*
1632-
* Throws an error on constraints that are unsupported by the
1633-
* domains.
1634-
*/
1635-
void
1636-
domainCheckForUnsupportedConstraints(Node *newConstraint)
1637-
{
1638-
Constraint *colDef;
1639-
1640-
if (nodeTag(newConstraint) == T_FkConstraint)
1641-
elog(ERROR, "CREATE DOMAIN / FOREIGN KEY constraints not supported");
1642-
1643-
colDef = (Constraint *) newConstraint;
1644-
1645-
switch (colDef->contype)
1646-
{
1647-
case CONSTR_UNIQUE:
1648-
elog(ERROR, "CREATE DOMAIN / UNIQUE indexes not supported");
1649-
break;
1650-
1651-
case CONSTR_PRIMARY:
1652-
elog(ERROR, "CREATE DOMAIN / PRIMARY KEY indexes not supported");
1653-
break;
1654-
1655-
case CONSTR_ATTR_DEFERRABLE:
1656-
case CONSTR_ATTR_NOT_DEFERRABLE:
1657-
case CONSTR_ATTR_DEFERRED:
1658-
case CONSTR_ATTR_IMMEDIATE:
1659-
elog(ERROR, "DefineDomain: DEFERRABLE, NON DEFERRABLE, DEFERRED"
1660-
" and IMMEDIATE not supported");
1661-
break;
1662-
1663-
default:
1664-
break;
1665-
}
1666-
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy