mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Add DOMAIN check constraints.
Rod Taylor
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.217 2002/11/11 22:19:22 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.218 2002/11/15 02:50:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1056,11 +1056,35 @@ _copyConstraintTest(ConstraintTest *from)
|
||||
newnode->testtype = from->testtype;
|
||||
if (from->name)
|
||||
newnode->name = pstrdup(from->name);
|
||||
if (from->domname)
|
||||
newnode->domname = pstrdup(from->domname);
|
||||
Node_Copy(from, newnode, check_expr);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static ConstraintTestValue *
|
||||
_copyConstraintTestValue(ConstraintTestValue *from)
|
||||
{
|
||||
ConstraintTestValue *newnode = makeNode(ConstraintTestValue);
|
||||
|
||||
/*
|
||||
* copy remainder of node
|
||||
*/
|
||||
newnode->typeId = from->typeId;
|
||||
newnode->typeMod = from->typeMod;
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static DomainConstraintValue *
|
||||
_copyDomainConstraintValue(DomainConstraintValue *from)
|
||||
{
|
||||
DomainConstraintValue *newnode = makeNode(DomainConstraintValue);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static ArrayRef *
|
||||
_copyArrayRef(ArrayRef *from)
|
||||
{
|
||||
@@ -3252,6 +3276,9 @@ copyObject(void *from)
|
||||
case T_ConstraintTest:
|
||||
retval = _copyConstraintTest(from);
|
||||
break;
|
||||
case T_ConstraintTestValue:
|
||||
retval = _copyConstraintTestValue(from);
|
||||
break;
|
||||
case T_FkConstraint:
|
||||
retval = _copyFkConstraint(from);
|
||||
break;
|
||||
@@ -3264,6 +3291,9 @@ copyObject(void *from)
|
||||
case T_InsertDefault:
|
||||
retval = _copyInsertDefault(from);
|
||||
break;
|
||||
case T_DomainConstraintValue:
|
||||
retval = _copyDomainConstraintValue(from);
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(ERROR, "copyObject: don't know how to copy node type %d",
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.163 2002/11/11 22:19:22 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.164 2002/11/15 02:50:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1971,15 +1971,32 @@ _equalConstraintTest(ConstraintTest *a, ConstraintTest *b)
|
||||
return false;
|
||||
if (!equalstr(a->name, b->name))
|
||||
return false;
|
||||
if (!equalstr(a->domname, b->domname))
|
||||
return false;
|
||||
if (!equal(a->check_expr, b->check_expr))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalConstraintTestValue(ConstraintTestValue *a, ConstraintTestValue *b)
|
||||
{
|
||||
if (a->typeId != b->typeId)
|
||||
return false;
|
||||
if (a->typeMod != b->typeMod)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalDomainConstraintValue(DomainConstraintValue *a, DomainConstraintValue *b)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Stuff from pg_list.h
|
||||
*/
|
||||
|
||||
static bool
|
||||
_equalValue(Value *a, Value *b)
|
||||
{
|
||||
@@ -2438,6 +2455,9 @@ equal(void *a, void *b)
|
||||
case T_ConstraintTest:
|
||||
retval = _equalConstraintTest(a, b);
|
||||
break;
|
||||
case T_ConstraintTestValue:
|
||||
retval = _equalConstraintTestValue(a, b);
|
||||
break;
|
||||
case T_FkConstraint:
|
||||
retval = _equalFkConstraint(a, b);
|
||||
break;
|
||||
@@ -2450,6 +2470,9 @@ equal(void *a, void *b)
|
||||
case T_InsertDefault:
|
||||
retval = _equalInsertDefault(a, b);
|
||||
break;
|
||||
case T_DomainConstraintValue:
|
||||
retval = _equalDomainConstraintValue(a, b);
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(WARNING, "equal: don't know whether nodes of type %d are equal",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.179 2002/11/11 22:19:22 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.180 2002/11/15 02:50:07 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Every (plan) node in POSTGRES has an associated "out" routine which
|
||||
@@ -1525,10 +1525,32 @@ _outConstraintTest(StringInfo str, ConstraintTest *node)
|
||||
appendStringInfo(str, " :testtype %d :name ",
|
||||
(int) node->testtype);
|
||||
_outToken(str, node->name);
|
||||
appendStringInfo(str, " :domain ");
|
||||
_outToken(str, node->domname);
|
||||
appendStringInfo(str, " :check_expr ");
|
||||
_outNode(str, node->check_expr);
|
||||
}
|
||||
|
||||
/*
|
||||
* ConstraintTestValue
|
||||
*/
|
||||
static void
|
||||
_outConstraintTestValue(StringInfo str, ConstraintTestValue *node)
|
||||
{
|
||||
appendStringInfo(str, " CONSTRAINTTESTVALUE :typeid %u :typemod %d ",
|
||||
node->typeId,
|
||||
node->typeMod);
|
||||
}
|
||||
|
||||
/*
|
||||
* DomainConstraintValue
|
||||
*/
|
||||
static void
|
||||
_outDomainConstraintValue(StringInfo str, DomainConstraintValue *node)
|
||||
{
|
||||
appendStringInfo(str, " DOMAINCONSTRAINTVALUE ");
|
||||
}
|
||||
|
||||
/*
|
||||
* _outNode -
|
||||
* converts a Node into ascii string and append it to 'str'
|
||||
@@ -1796,9 +1818,15 @@ _outNode(StringInfo str, void *obj)
|
||||
case T_ConstraintTest:
|
||||
_outConstraintTest(str, obj);
|
||||
break;
|
||||
case T_ConstraintTestValue:
|
||||
_outConstraintTestValue(str, obj);
|
||||
break;
|
||||
case T_FuncCall:
|
||||
_outFuncCall(str, obj);
|
||||
break;
|
||||
case T_DomainConstraintValue:
|
||||
_outDomainConstraintValue(str, obj);
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(WARNING, "_outNode: don't know how to print type %d ",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.136 2002/11/06 00:00:44 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.137 2002/11/15 02:50:07 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Most of the read functions for plan nodes are tested. (In fact, they
|
||||
@@ -949,12 +949,56 @@ _readConstraintTest(void)
|
||||
token = pg_strtok(&length); /* now read it */
|
||||
local_node->name = nullable_string(token, length);
|
||||
|
||||
token = pg_strtok(&length); /* get :domname */
|
||||
token = pg_strtok(&length); /* get domname */
|
||||
local_node->domname = nullable_string(token, length);
|
||||
|
||||
token = pg_strtok(&length); /* eat :check_expr */
|
||||
local_node->check_expr = nodeRead(true); /* now read it */
|
||||
|
||||
return local_node;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* _readConstraintTestValue
|
||||
*
|
||||
* ConstraintTestValue is a subclass of Node
|
||||
* ----------------
|
||||
*/
|
||||
static ConstraintTestValue *
|
||||
_readConstraintTestValue(void)
|
||||
{
|
||||
ConstraintTestValue *local_node;
|
||||
char *token;
|
||||
int length;
|
||||
|
||||
local_node = makeNode(ConstraintTestValue);
|
||||
token = pg_strtok(&length); /* eat :typeid */
|
||||
token = pg_strtok(&length); /* get typeid */
|
||||
local_node->typeId = atooid(token);
|
||||
token = pg_strtok(&length); /* eat :typemod */
|
||||
token = pg_strtok(&length); /* get typemod */
|
||||
local_node->typeMod = atoi(token);
|
||||
|
||||
return local_node;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* _readDomainConstraintValue
|
||||
*
|
||||
* DomainConstraintValue is a subclass of Node
|
||||
* ----------------
|
||||
*/
|
||||
static DomainConstraintValue *
|
||||
_readDomainConstraintValue(void)
|
||||
{
|
||||
DomainConstraintValue *local_node;
|
||||
|
||||
local_node = makeNode(DomainConstraintValue);
|
||||
|
||||
return local_node;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* _readVar
|
||||
*
|
||||
@@ -2300,6 +2344,10 @@ parsePlanString(void)
|
||||
return_value = _readBooleanTest();
|
||||
else if (length == 14 && strncmp(token, "CONSTRAINTTEST", length) == 0)
|
||||
return_value = _readConstraintTest();
|
||||
else if (length == 21 && strncmp(token, "DOMAINCONSTRAINTVALUE", length) == 0)
|
||||
return_value = _readDomainConstraintValue();
|
||||
else if (length == 19 && strncmp(token, "CONSTRAINTTESTVALUE", length) == 0)
|
||||
return_value = _readConstraintTestValue();
|
||||
else
|
||||
elog(ERROR, "badly formatted planstring \"%.10s\"...", token);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user