Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit dc070fd

Browse files
committed
Add copyObject logic for TruncateStmt and a few other utility-statement
parse node types. This allows these statements to be placed in a plpgsql function. Also, see to it that statement types not handled by the copy logic will draw an appropriate elog(ERROR), instead of leaving a null pointer that will cause coredump later on. More utility statements could be added if anyone felt like turning the crank.
1 parent 124875e commit dc070fd

File tree

1 file changed

+148
-17
lines changed

1 file changed

+148
-17
lines changed

src/backend/nodes/copyfuncs.c

Lines changed: 148 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.111 2000/04/04 01:21:48 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.112 2000/04/08 00:21:15 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1369,8 +1369,9 @@ _copyStream(Stream *from)
13691369
return newnode;
13701370
}
13711371

1372-
/*
1373-
* parsenodes.h routines have no copy functions
1372+
/* ****************************************************************
1373+
* parsenodes.h copy functions
1374+
* ****************************************************************
13741375
*/
13751376

13761377
static TargetEntry *
@@ -1467,14 +1468,7 @@ _copyQuery(Query *from)
14671468
Query *newnode = makeNode(Query);
14681469

14691470
newnode->commandType = from->commandType;
1470-
if (from->utilityStmt && nodeTag(from->utilityStmt) == T_NotifyStmt)
1471-
{
1472-
NotifyStmt *from_notify = (NotifyStmt *) from->utilityStmt;
1473-
NotifyStmt *n = makeNode(NotifyStmt);
1474-
1475-
n->relname = pstrdup(from_notify->relname);
1476-
newnode->utilityStmt = (Node *) n;
1477-
}
1471+
Node_Copy(from, newnode, utilityStmt);
14781472
newnode->resultRelation = from->resultRelation;
14791473
if (from->into)
14801474
newnode->into = pstrdup(from->into);
@@ -1510,10 +1504,117 @@ _copyQuery(Query *from)
15101504
return newnode;
15111505
}
15121506

1507+
static ClosePortalStmt *
1508+
_copyClosePortalStmt(ClosePortalStmt *from)
1509+
{
1510+
ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1511+
1512+
if (from->portalname)
1513+
newnode->portalname = pstrdup(from->portalname);
1514+
1515+
return newnode;
1516+
}
1517+
1518+
static TruncateStmt *
1519+
_copyTruncateStmt(TruncateStmt *from)
1520+
{
1521+
TruncateStmt *newnode = makeNode(TruncateStmt);
1522+
1523+
newnode->relName = pstrdup(from->relName);
1524+
1525+
return newnode;
1526+
}
1527+
1528+
static NotifyStmt *
1529+
_copyNotifyStmt(NotifyStmt *from)
1530+
{
1531+
NotifyStmt *newnode = makeNode(NotifyStmt);
1532+
1533+
if (from->relname)
1534+
newnode->relname = pstrdup(from->relname);
1535+
1536+
return newnode;
1537+
}
1538+
1539+
static ListenStmt *
1540+
_copyListenStmt(ListenStmt *from)
1541+
{
1542+
ListenStmt *newnode = makeNode(ListenStmt);
1543+
1544+
if (from->relname)
1545+
newnode->relname = pstrdup(from->relname);
1546+
1547+
return newnode;
1548+
}
1549+
1550+
static UnlistenStmt *
1551+
_copyUnlistenStmt(UnlistenStmt *from)
1552+
{
1553+
UnlistenStmt *newnode = makeNode(UnlistenStmt);
1554+
1555+
if (from->relname)
1556+
newnode->relname = pstrdup(from->relname);
1557+
1558+
return newnode;
1559+
}
1560+
1561+
static TransactionStmt *
1562+
_copyTransactionStmt(TransactionStmt *from)
1563+
{
1564+
TransactionStmt *newnode = makeNode(TransactionStmt);
1565+
1566+
newnode->command = from->command;
1567+
1568+
return newnode;
1569+
}
1570+
1571+
static LoadStmt *
1572+
_copyLoadStmt(LoadStmt *from)
1573+
{
1574+
LoadStmt *newnode = makeNode(LoadStmt);
1575+
1576+
if (from->filename)
1577+
newnode->filename = pstrdup(from->filename);
1578+
1579+
return newnode;
1580+
}
1581+
1582+
static VariableSetStmt *
1583+
_copyVariableSetStmt(VariableSetStmt *from)
1584+
{
1585+
VariableSetStmt *newnode = makeNode(VariableSetStmt);
1586+
1587+
if (from->name)
1588+
newnode->name = pstrdup(from->name);
1589+
if (from->value)
1590+
newnode->value = pstrdup(from->value);
1591+
1592+
return newnode;
1593+
}
1594+
1595+
static VariableResetStmt *
1596+
_copyVariableResetStmt(VariableResetStmt *from)
1597+
{
1598+
VariableResetStmt *newnode = makeNode(VariableResetStmt);
1599+
1600+
if (from->name)
1601+
newnode->name = pstrdup(from->name);
1602+
1603+
return newnode;
1604+
}
1605+
1606+
static LockStmt *
1607+
_copyLockStmt(LockStmt *from)
1608+
{
1609+
LockStmt *newnode = makeNode(LockStmt);
1610+
1611+
if (from->relname)
1612+
newnode->relname = pstrdup(from->relname);
1613+
newnode->mode = from->mode;
1614+
1615+
return newnode;
1616+
}
15131617

1514-
/*
1515-
* mnodes.h routines have no copy functions
1516-
*/
15171618

15181619
/* ****************************************************************
15191620
* pg_list.h copy functions
@@ -1718,9 +1819,6 @@ copyObject(void *from)
17181819
/*
17191820
* PARSE NODES
17201821
*/
1721-
case T_Query:
1722-
retval = _copyQuery(from);
1723-
break;
17241822
case T_TargetEntry:
17251823
retval = _copyTargetEntry(from);
17261824
break;
@@ -1742,6 +1840,39 @@ copyObject(void *from)
17421840
case T_TypeCast:
17431841
retval = _copyTypeCast(from);
17441842
break;
1843+
case T_Query:
1844+
retval = _copyQuery(from);
1845+
break;
1846+
case T_ClosePortalStmt:
1847+
retval = _copyClosePortalStmt(from);
1848+
break;
1849+
case T_TruncateStmt:
1850+
retval = _copyTruncateStmt(from);
1851+
break;
1852+
case T_NotifyStmt:
1853+
retval = _copyNotifyStmt(from);
1854+
break;
1855+
case T_ListenStmt:
1856+
retval = _copyListenStmt(from);
1857+
break;
1858+
case T_UnlistenStmt:
1859+
retval = _copyUnlistenStmt(from);
1860+
break;
1861+
case T_TransactionStmt:
1862+
retval = _copyTransactionStmt(from);
1863+
break;
1864+
case T_LoadStmt:
1865+
retval = _copyLoadStmt(from);
1866+
break;
1867+
case T_VariableSetStmt:
1868+
retval = _copyVariableSetStmt(from);
1869+
break;
1870+
case T_VariableResetStmt:
1871+
retval = _copyVariableResetStmt(from);
1872+
break;
1873+
case T_LockStmt:
1874+
retval = _copyLockStmt(from);
1875+
break;
17451876

17461877
/*
17471878
* VALUE NODES

0 commit comments

Comments
 (0)