Commit 4951a882 authored by Tom Lane's avatar Tom Lane

copyObject() and equal() now know about all parse-time node types,

including utility statements.  Still can't copy or compare executor
state, but at present that doesn't seem to be necessary.  This makes
it possible to execute most (all?) utility statements in plpgsql.
Had to change parsetree representation of CreateTrigStmt so that it
contained only legal Nodes, and not bare string constants.
parent 66fd8f85
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.75 2000/08/03 19:19:18 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.76 2000/08/11 23:45:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -212,7 +212,7 @@ CreateTrigger(CreateTrigStmt *stmt)
foreach(le, stmt->args)
{
char *ar = (char *) lfirst(le);
char *ar = ((Value*) lfirst(le))->val.str;
len += strlen(ar) + 4;
for (; *ar; ar++)
......@@ -222,10 +222,10 @@ CreateTrigger(CreateTrigStmt *stmt)
}
}
args = (char *) palloc(len + 1);
args[0] = 0;
args[0] = '\0';
foreach(le, stmt->args)
{
char *s = (char *) lfirst(le);
char *s = ((Value*) lfirst(le))->val.str;
char *d = args + strlen(args);
while (*s)
......@@ -234,8 +234,7 @@ CreateTrigger(CreateTrigStmt *stmt)
*d++ = '\\';
*d++ = *s++;
}
*d = 0;
strcat(args, "\\000");
strcpy(d, "\\000");
}
values[Anum_pg_trigger_tgnargs - 1] = Int16GetDatum(nargs);
values[Anum_pg_trigger_tgargs - 1] = DirectFunctionCall1(byteain,
......
This diff is collapsed.
This diff is collapsed.
......@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: analyze.c,v 1.153 2000/08/08 15:42:04 tgl Exp $
* $Id: analyze.c,v 1.154 2000/08/11 23:45:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1112,13 +1112,13 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
fk_trigger->args = NIL;
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->constr_name);
makeString(fkconstraint->constr_name));
fk_trigger->args = lappend(fk_trigger->args,
stmt->relname);
makeString(stmt->relname));
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->pktable_name);
makeString(fkconstraint->pktable_name));
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->match_type);
makeString(fkconstraint->match_type));
fk_attr = fkconstraint->fk_attrs;
pk_attr = fkconstraint->pk_attrs;
if (length(fk_attr) != length(pk_attr))
......@@ -1130,10 +1130,12 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
while (fk_attr != NIL)
{
id = (Ident *) lfirst(fk_attr);
fk_trigger->args = lappend(fk_trigger->args, id->name);
fk_trigger->args = lappend(fk_trigger->args,
makeString(id->name));
id = (Ident *) lfirst(pk_attr);
fk_trigger->args = lappend(fk_trigger->args, id->name);
fk_trigger->args = lappend(fk_trigger->args,
makeString(id->name));
fk_attr = lnext(fk_attr);
pk_attr = lnext(pk_attr);
......@@ -1189,22 +1191,24 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
fk_trigger->args = NIL;
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->constr_name);
makeString(fkconstraint->constr_name));
fk_trigger->args = lappend(fk_trigger->args,
stmt->relname);
makeString(stmt->relname));
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->pktable_name);
makeString(fkconstraint->pktable_name));
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->match_type);
makeString(fkconstraint->match_type));
fk_attr = fkconstraint->fk_attrs;
pk_attr = fkconstraint->pk_attrs;
while (fk_attr != NIL)
{
id = (Ident *) lfirst(fk_attr);
fk_trigger->args = lappend(fk_trigger->args, id->name);
fk_trigger->args = lappend(fk_trigger->args,
makeString(id->name));
id = (Ident *) lfirst(pk_attr);
fk_trigger->args = lappend(fk_trigger->args, id->name);
fk_trigger->args = lappend(fk_trigger->args,
makeString(id->name));
fk_attr = lnext(fk_attr);
pk_attr = lnext(pk_attr);
......@@ -1260,22 +1264,24 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
fk_trigger->args = NIL;
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->constr_name);
makeString(fkconstraint->constr_name));
fk_trigger->args = lappend(fk_trigger->args,
stmt->relname);
makeString(stmt->relname));
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->pktable_name);
makeString(fkconstraint->pktable_name));
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->match_type);
makeString(fkconstraint->match_type));
fk_attr = fkconstraint->fk_attrs;
pk_attr = fkconstraint->pk_attrs;
while (fk_attr != NIL)
{
id = (Ident *) lfirst(fk_attr);
fk_trigger->args = lappend(fk_trigger->args, id->name);
fk_trigger->args = lappend(fk_trigger->args,
makeString(id->name));
id = (Ident *) lfirst(pk_attr);
fk_trigger->args = lappend(fk_trigger->args, id->name);
fk_trigger->args = lappend(fk_trigger->args,
makeString(id->name));
fk_attr = lnext(fk_attr);
pk_attr = lnext(pk_attr);
......@@ -1662,13 +1668,13 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt)
fk_trigger->args = NIL;
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->constr_name);
makeString(fkconstraint->constr_name));
fk_trigger->args = lappend(fk_trigger->args,
stmt->relname);
makeString(stmt->relname));
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->pktable_name);
makeString(fkconstraint->pktable_name));
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->match_type);
makeString(fkconstraint->match_type));
fk_attr = fkconstraint->fk_attrs;
pk_attr = fkconstraint->pk_attrs;
if (length(fk_attr) != length(pk_attr))
......@@ -1680,10 +1686,12 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt)
while (fk_attr != NIL)
{
id = (Ident *) lfirst(fk_attr);
fk_trigger->args = lappend(fk_trigger->args, id->name);
fk_trigger->args = lappend(fk_trigger->args,
makeString(id->name));
id = (Ident *) lfirst(pk_attr);
fk_trigger->args = lappend(fk_trigger->args, id->name);
fk_trigger->args = lappend(fk_trigger->args,
makeString(id->name));
fk_attr = lnext(fk_attr);
pk_attr = lnext(pk_attr);
......@@ -1737,22 +1745,24 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt)
fk_trigger->args = NIL;
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->constr_name);
makeString(fkconstraint->constr_name));
fk_trigger->args = lappend(fk_trigger->args,
stmt->relname);
makeString(stmt->relname));
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->pktable_name);
makeString(fkconstraint->pktable_name));
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->match_type);
makeString(fkconstraint->match_type));
fk_attr = fkconstraint->fk_attrs;
pk_attr = fkconstraint->pk_attrs;
while (fk_attr != NIL)
{
id = (Ident *) lfirst(fk_attr);
fk_trigger->args = lappend(fk_trigger->args, id->name);
fk_trigger->args = lappend(fk_trigger->args,
makeString(id->name));
id = (Ident *) lfirst(pk_attr);
fk_trigger->args = lappend(fk_trigger->args, id->name);
fk_trigger->args = lappend(fk_trigger->args,
makeString(id->name));
fk_attr = lnext(fk_attr);
pk_attr = lnext(pk_attr);
......@@ -1806,22 +1816,24 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt)
fk_trigger->args = NIL;
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->constr_name);
makeString(fkconstraint->constr_name));
fk_trigger->args = lappend(fk_trigger->args,
stmt->relname);
makeString(stmt->relname));
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->pktable_name);
makeString(fkconstraint->pktable_name));
fk_trigger->args = lappend(fk_trigger->args,
fkconstraint->match_type);
makeString(fkconstraint->match_type));
fk_attr = fkconstraint->fk_attrs;
pk_attr = fkconstraint->pk_attrs;
while (fk_attr != NIL)
{
id = (Ident *) lfirst(fk_attr);
fk_trigger->args = lappend(fk_trigger->args, id->name);
fk_trigger->args = lappend(fk_trigger->args,
makeString(id->name));
id = (Ident *) lfirst(pk_attr);
fk_trigger->args = lappend(fk_trigger->args, id->name);
fk_trigger->args = lappend(fk_trigger->args,
makeString(id->name));
fk_attr = lnext(fk_attr);
pk_attr = lnext(pk_attr);
......
......@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.184 2000/08/07 20:16:13 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.185 2000/08/11 23:45:27 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
......@@ -158,7 +158,8 @@ static void doNegateFloat(Value *v);
%type <str> OptConstrFromTable
%type <str> TriggerEvents, TriggerFuncArg
%type <str> TriggerEvents
%type <value> TriggerFuncArg
%type <str> relation_name, copy_file_name, copy_delimiter, copy_null, def_name,
database_name, access_method_clause, access_method, attr_name,
......@@ -1792,11 +1793,20 @@ TriggerFuncArg: ICONST
{
char buf[64];
sprintf (buf, "%d", $1);
$$ = pstrdup(buf);
$$ = makeString(pstrdup(buf));
}
| FCONST
{
$$ = makeString($1);
}
| Sconst
{
$$ = makeString($1);
}
| ColId
{
$$ = makeString($1);
}
| FCONST { $$ = $1; }
| Sconst { $$ = $1; }
| ColId { $$ = $1; }
;
OptConstrFromTable: /* Empty */
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.170 2000/07/17 03:05:14 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.171 2000/08/11 23:45:35 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
......@@ -417,21 +417,13 @@ pg_parse_and_rewrite(char *query_string, /* string to execute */
* trees. The present (bizarre) implementation of UNION/INTERSECT/EXCEPT
* doesn't run analysis of the second and later subqueries until rewrite,
* so we'd get false failures on these queries if we did it beforehand.
*
* Currently, copyObject doesn't know about most of the utility query
* types, so suppress the check until that can be fixed... it should
* be fixed, though.
*/
if (querytree_list &&
((Query *) lfirst(querytree_list))->commandType != CMD_UTILITY)
{
new_list = (List *) copyObject(querytree_list);
/* This checks both copyObject() and the equal() routines... */
if (! equal(new_list, querytree_list))
elog(NOTICE, "pg_parse_and_rewrite: copyObject failed on parse tree");
else
querytree_list = new_list;
}
new_list = (List *) copyObject(querytree_list);
/* This checks both copyObject() and the equal() routines... */
if (! equal(new_list, querytree_list))
elog(NOTICE, "pg_parse_and_rewrite: copyObject failed on parse tree");
else
querytree_list = new_list;
#endif
if (Debug_print_rewritten)
......@@ -1412,7 +1404,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.170 $ $Date: 2000/07/17 03:05:14 $\n");
puts("$Revision: 1.171 $ $Date: 2000/08/11 23:45:35 $\n");
}
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment