mirror of
https://github.com/postgres/postgres.git
synced 2025-08-30 06:01:21 +03:00
Use castNode() in a bunch of statement-list-related code.
When I wrote commit ab1f0c822
, I really missed the castNode() macro that
Peter E. had proposed shortly before. This back-fills the uses I would
have put it to. It's probably not all that significant, but there are
more assertions here than there were before, and conceivably they will
help catch any bugs associated with those representation changes.
I left behind a number of usages like "(Query *) copyObject(query_var)".
Those could have been converted as well, but Peter has proposed another
notational improvement that would handle copyObject cases automatically,
so I let that be for now.
This commit is contained in:
@@ -962,7 +962,7 @@ exec_simple_query(const char *query_string)
|
||||
*/
|
||||
foreach(parsetree_item, parsetree_list)
|
||||
{
|
||||
RawStmt *parsetree = (RawStmt *) lfirst(parsetree_item);
|
||||
RawStmt *parsetree = castNode(RawStmt, lfirst(parsetree_item));
|
||||
bool snapshot_set = false;
|
||||
const char *commandTag;
|
||||
char completionTag[COMPLETION_TAG_BUFSIZE];
|
||||
@@ -1286,7 +1286,7 @@ exec_parse_message(const char *query_string, /* string to execute */
|
||||
bool snapshot_set = false;
|
||||
int i;
|
||||
|
||||
raw_parse_tree = (RawStmt *) linitial(parsetree_list);
|
||||
raw_parse_tree = castNode(RawStmt, linitial(parsetree_list));
|
||||
|
||||
/*
|
||||
* Get the command name for possible use in status display.
|
||||
@@ -2148,7 +2148,7 @@ errdetail_execute(List *raw_parsetree_list)
|
||||
|
||||
foreach(parsetree_item, raw_parsetree_list)
|
||||
{
|
||||
RawStmt *parsetree = (RawStmt *) lfirst(parsetree_item);
|
||||
RawStmt *parsetree = castNode(RawStmt, lfirst(parsetree_item));
|
||||
|
||||
if (IsA(parsetree->stmt, ExecuteStmt))
|
||||
{
|
||||
@@ -2502,9 +2502,8 @@ IsTransactionExitStmtList(List *pstmts)
|
||||
{
|
||||
if (list_length(pstmts) == 1)
|
||||
{
|
||||
PlannedStmt *pstmt = (PlannedStmt *) linitial(pstmts);
|
||||
PlannedStmt *pstmt = castNode(PlannedStmt, linitial(pstmts));
|
||||
|
||||
Assert(IsA(pstmt, PlannedStmt));
|
||||
if (pstmt->commandType == CMD_UTILITY &&
|
||||
IsTransactionExitStmt(pstmt->utilityStmt))
|
||||
return true;
|
||||
@@ -2518,9 +2517,8 @@ IsTransactionStmtList(List *pstmts)
|
||||
{
|
||||
if (list_length(pstmts) == 1)
|
||||
{
|
||||
PlannedStmt *pstmt = (PlannedStmt *) linitial(pstmts);
|
||||
PlannedStmt *pstmt = castNode(PlannedStmt, linitial(pstmts));
|
||||
|
||||
Assert(IsA(pstmt, PlannedStmt));
|
||||
if (pstmt->commandType == CMD_UTILITY &&
|
||||
IsA(pstmt->utilityStmt, TransactionStmt))
|
||||
return true;
|
||||
|
@@ -487,7 +487,7 @@ PortalStart(Portal portal, ParamListInfo params,
|
||||
* Create QueryDesc in portal's context; for the moment, set
|
||||
* the destination to DestNone.
|
||||
*/
|
||||
queryDesc = CreateQueryDesc((PlannedStmt *) linitial(portal->stmts),
|
||||
queryDesc = CreateQueryDesc(castNode(PlannedStmt, linitial(portal->stmts)),
|
||||
portal->sourceText,
|
||||
GetActiveSnapshot(),
|
||||
InvalidSnapshot,
|
||||
@@ -1020,7 +1020,7 @@ FillPortalStore(Portal portal, bool isTopLevel)
|
||||
break;
|
||||
|
||||
case PORTAL_UTIL_SELECT:
|
||||
PortalRunUtility(portal, (PlannedStmt *) linitial(portal->stmts),
|
||||
PortalRunUtility(portal, castNode(PlannedStmt, linitial(portal->stmts)),
|
||||
isTopLevel, true, treceiver, completionTag);
|
||||
break;
|
||||
|
||||
@@ -1215,7 +1215,7 @@ PortalRunMulti(Portal portal,
|
||||
*/
|
||||
foreach(stmtlist_item, portal->stmts)
|
||||
{
|
||||
PlannedStmt *pstmt = (PlannedStmt *) lfirst(stmtlist_item);
|
||||
PlannedStmt *pstmt = castNode(PlannedStmt, lfirst(stmtlist_item));
|
||||
|
||||
/*
|
||||
* If we got a cancel signal in prior command, quit
|
||||
|
@@ -1829,22 +1829,19 @@ UtilityContainsQuery(Node *parsetree)
|
||||
switch (nodeTag(parsetree))
|
||||
{
|
||||
case T_DeclareCursorStmt:
|
||||
qry = (Query *) ((DeclareCursorStmt *) parsetree)->query;
|
||||
Assert(IsA(qry, Query));
|
||||
qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
|
||||
if (qry->commandType == CMD_UTILITY)
|
||||
return UtilityContainsQuery(qry->utilityStmt);
|
||||
return qry;
|
||||
|
||||
case T_ExplainStmt:
|
||||
qry = (Query *) ((ExplainStmt *) parsetree)->query;
|
||||
Assert(IsA(qry, Query));
|
||||
qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
|
||||
if (qry->commandType == CMD_UTILITY)
|
||||
return UtilityContainsQuery(qry->utilityStmt);
|
||||
return qry;
|
||||
|
||||
case T_CreateTableAsStmt:
|
||||
qry = (Query *) ((CreateTableAsStmt *) parsetree)->query;
|
||||
Assert(IsA(qry, Query));
|
||||
qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
|
||||
if (qry->commandType == CMD_UTILITY)
|
||||
return UtilityContainsQuery(qry->utilityStmt);
|
||||
return qry;
|
||||
|
Reference in New Issue
Block a user