*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.31 1997/11/24 05:32:40 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.44 1998/07/26 04:30:48 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include "commands/explain.h"
#include "commands/trigger.h"
#include "commands/proclang.h"
+#include "commands/variable.h"
#include "nodes/parsenodes.h"
#include "../backend/parser/parse.h"
#include "rewrite/rewriteDefine.h"
#include "tcop/tcopdebug.h"
#include "tcop/dest.h"
-#include "tcop/variable.h"
#include "tcop/utility.h"
#include "fmgr.h" /* For load_file() */
#include "storage/fd.h"
#include "utils/syscache.h"
#endif
+void DefineUser(CreateUserStmt *stmt);
+void AlterUser(AlterUserStmt *stmt);
+void RemoveUser(char *username);
+
+extern const char **ps_status; /* from postgres.c */
/* ----------------
* CHECK_IF_ABORTED() is used to avoid doing unnecessary
* processing within an aborted transaction block.
* ----------------
*/
+ /* we have to use IF because of the 'break' */
#define CHECK_IF_ABORTED() \
- if (IsAbortedTransactionBlockState()) { \
+if (1) \
+{ \
+ if (IsAbortedTransactionBlockState()) \
+ { \
elog(NOTICE, "(transaction aborted): %s", \
- "queries ignored until END"); \
+ "all queries ignored until end of transaction block"); \
commandTag = "*ABORT STATE*"; \
break; \
} \
+} else
/* ----------------
* general utility function invoker
* ----------------
*/
void
-ProcessUtility(Node * parsetree,
+ProcessUtility(Node *parsetree,
CommandDest dest)
{
char *commandTag = NULL;
switch (stmt->command)
{
case BEGIN_TRANS:
- commandTag = "BEGIN";
+ *ps_status = commandTag = "BEGIN";
CHECK_IF_ABORTED();
BeginTransactionBlock();
break;
case END_TRANS:
- commandTag = "END";
+ *ps_status = commandTag = "END";
EndTransactionBlock();
break;
case ABORT_TRANS:
- commandTag = "ABORT";
+ *ps_status = commandTag = "ABORT";
UserAbortTransactionBlock();
break;
}
{
ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
- commandTag = "CLOSE";
+ *ps_status = commandTag = "CLOSE";
CHECK_IF_ABORTED();
PerformPortalClose(stmt->portalname, dest);
bool forward;
int count;
- commandTag = (stmt->ismove) ? "MOVE" : "FETCH";
+ *ps_status = commandTag = (stmt->ismove) ? "MOVE" : "FETCH";
CHECK_IF_ABORTED();
forward = (bool) (stmt->direction == FORWARD);
*
*/
case T_CreateStmt:
- commandTag = "CREATE";
+ *ps_status = commandTag = "CREATE";
CHECK_IF_ABORTED();
DefineRelation((CreateStmt *) parsetree);
List *args = stmt->relNames;
Relation rel;
- commandTag = "DROP";
+ *ps_status = commandTag = "DROP";
CHECK_IF_ABORTED();
foreach(arg, args)
{
relname = strVal(lfirst(arg));
if (IsSystemRelationName(relname))
- elog(WARN, "class \"%s\" is a system catalog",
+ elog(ERROR, "class \"%s\" is a system catalog",
relname);
rel = heap_openr(relname);
if (RelationIsValid(rel))
{
if (stmt->sequence &&
rel->rd_rel->relkind != RELKIND_SEQUENCE)
- elog(WARN, "Use DROP TABLE to drop table '%s'",
+ elog(ERROR, "Use DROP TABLE to drop table '%s'",
relname);
if (!(stmt->sequence) &&
rel->rd_rel->relkind == RELKIND_SEQUENCE)
- elog(WARN, "Use DROP SEQUENCE to drop sequence '%s'",
+ elog(ERROR, "Use DROP SEQUENCE to drop sequence '%s'",
relname);
heap_close(rel);
}
#ifndef NO_SECURITY
if (!pg_ownercheck(userName, relname, RELNAME))
- elog(WARN, "you do not own class \"%s\"",
+ elog(ERROR, "you do not own class \"%s\"",
relname);
#endif
}
{
CopyStmt *stmt = (CopyStmt *) parsetree;
- commandTag = "COPY";
+ *ps_status = commandTag = "COPY";
CHECK_IF_ABORTED();
DoCopy(stmt->relname,
{
AddAttrStmt *stmt = (AddAttrStmt *) parsetree;
- commandTag = "ADD";
+ *ps_status = commandTag = "ADD";
CHECK_IF_ABORTED();
/*
PerformAddAttribute(stmt->relname,
userName,
stmt->inh,
- stmt->colDef);
+ (ColumnDef *) stmt->colDef);
}
break;
{
RenameStmt *stmt = (RenameStmt *) parsetree;
- commandTag = "RENAME";
+ *ps_status = commandTag = "RENAME";
CHECK_IF_ABORTED();
relname = stmt->relname;
if (IsSystemRelationName(relname))
- elog(WARN, "class \"%s\" is a system catalog",
+ elog(ERROR, "class \"%s\" is a system catalog",
relname);
#ifndef NO_SECURITY
if (!pg_ownercheck(userName, relname, RELNAME))
- elog(WARN, "you do not own class \"%s\"",
+ elog(ERROR, "you do not own class \"%s\"",
relname);
#endif
AclItem *aip;
unsigned modechg;
- commandTag = "CHANGE";
+ *ps_status = commandTag = "CHANGE";
CHECK_IF_ABORTED();
aip = stmt->aclitem;
{
relname = strVal(lfirst(i));
if (!pg_ownercheck(userName, relname, RELNAME))
- elog(WARN, "you do not own class \"%s\"",
+ elog(ERROR, "you do not own class \"%s\"",
relname);
}
#endif
{
DefineStmt *stmt = (DefineStmt *) parsetree;
- commandTag = "CREATE";
+ *ps_status = commandTag = "CREATE";
CHECK_IF_ABORTED();
switch (stmt->defType)
stmt->definition); /* rest */
break;
case TYPE_P:
- {
DefineType(stmt->defname, stmt->definition);
- }
break;
case AGGREGATE:
DefineAggregate(stmt->defname, /* aggregate name */
{
ViewStmt *stmt = (ViewStmt *) parsetree;
- commandTag = "CREATE";
+ *ps_status = commandTag = "CREATE";
CHECK_IF_ABORTED();
DefineView(stmt->viewname, stmt->query); /* retrieve parsetree */
}
break;
case T_ProcedureStmt: /* CREATE FUNCTION */
- commandTag = "CREATE";
+ *ps_status = commandTag = "CREATE";
CHECK_IF_ABORTED();
CreateFunction((ProcedureStmt *) parsetree, dest); /* everything */
break;
{
IndexStmt *stmt = (IndexStmt *) parsetree;
- commandTag = "CREATE";
+ *ps_status = commandTag = "CREATE";
CHECK_IF_ABORTED();
DefineIndex(stmt->relname, /* relation name */
stmt->idxname, /* index name */
relname = stmt->object->relname;
aclcheck_result = pg_aclcheck(relname, userName, ACL_RU);
if (aclcheck_result != ACLCHECK_OK)
- elog(WARN, "%s: %s", relname, aclcheck_error_strings[aclcheck_result]);
+ elog(ERROR, "%s: %s", relname, aclcheck_error_strings[aclcheck_result]);
#endif
- commandTag = "CREATE";
+ *ps_status = commandTag = "CREATE";
CHECK_IF_ABORTED();
DefineQueryRewrite(stmt);
}
break;
case T_CreateSeqStmt:
- commandTag = "CREATE";
+ *ps_status = commandTag = "CREATE";
CHECK_IF_ABORTED();
DefineSequence((CreateSeqStmt *) parsetree);
{
ExtendStmt *stmt = (ExtendStmt *) parsetree;
- commandTag = "EXTEND";
+ *ps_status = commandTag = "EXTEND";
CHECK_IF_ABORTED();
ExtendIndex(stmt->idxname, /* index name */
{
RemoveStmt *stmt = (RemoveStmt *) parsetree;
- commandTag = "DROP";
+ *ps_status = commandTag = "DROP";
CHECK_IF_ABORTED();
switch (stmt->removeType)
case INDEX:
relname = stmt->name;
if (IsSystemRelationName(relname))
- elog(WARN, "class \"%s\" is a system catalog index",
+ elog(ERROR, "class \"%s\" is a system catalog index",
relname);
#ifndef NO_SECURITY
if (!pg_ownercheck(userName, relname, RELNAME))
- elog(WARN, "%s: %s", relname, aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
+ elog(ERROR, "%s: %s", relname, aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
#endif
RemoveIndex(relname);
break;
relationName = RewriteGetRuleEventRel(rulename);
aclcheck_result = pg_aclcheck(relationName, userName, ACL_RU);
if (aclcheck_result != ACLCHECK_OK)
- {
- elog(WARN, "%s: %s", relationName, aclcheck_error_strings[aclcheck_result]);
- }
+ elog(ERROR, "%s: %s", relationName, aclcheck_error_strings[aclcheck_result]);
#endif
RemoveRewriteRule(rulename);
}
ruleName = MakeRetrieveViewRuleName(viewName);
relationName = RewriteGetRuleEventRel(ruleName);
if (!pg_ownercheck(userName, relationName, RELNAME))
- elog(WARN, "%s: %s", relationName, aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
+ elog(ERROR, "%s: %s", relationName, aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
pfree(ruleName);
#endif
RemoveView(viewName);
{
RemoveAggrStmt *stmt = (RemoveAggrStmt *) parsetree;
- commandTag = "DROP";
+ *ps_status = commandTag = "DROP";
CHECK_IF_ABORTED();
RemoveAggregate(stmt->aggname, stmt->aggtype);
}
{
RemoveFuncStmt *stmt = (RemoveFuncStmt *) parsetree;
- commandTag = "DROP";
+ *ps_status = commandTag = "DROP";
CHECK_IF_ABORTED();
RemoveFunction(stmt->funcname,
length(stmt->args),
char *type1 = (char *) NULL;
char *type2 = (char *) NULL;
- commandTag = "DROP";
+ *ps_status = commandTag = "DROP";
CHECK_IF_ABORTED();
if (lfirst(stmt->args) != NULL)
break;
case T_VersionStmt:
- {
- elog(WARN, "CREATE VERSION is not currently implemented");
- }
+ elog(ERROR, "CREATE VERSION is not currently implemented");
break;
case T_CreatedbStmt:
{
CreatedbStmt *stmt = (CreatedbStmt *) parsetree;
- commandTag = "CREATEDB";
+ *ps_status = commandTag = "CREATEDB";
CHECK_IF_ABORTED();
+#ifdef MULTIBYTE
+ createdb(stmt->dbname, stmt->dbpath, stmt->encoding);
+#else
createdb(stmt->dbname, stmt->dbpath);
+#endif
}
break;
{
DestroydbStmt *stmt = (DestroydbStmt *) parsetree;
- commandTag = "DESTROYDB";
+ *ps_status = commandTag = "DESTROYDB";
CHECK_IF_ABORTED();
destroydb(stmt->dbname);
}
{
NotifyStmt *stmt = (NotifyStmt *) parsetree;
- commandTag = "NOTIFY";
+ *ps_status = commandTag = "NOTIFY";
CHECK_IF_ABORTED();
Async_Notify(stmt->relname);
{
ListenStmt *stmt = (ListenStmt *) parsetree;
- commandTag = "LISTEN";
+ *ps_status = commandTag = "LISTEN";
CHECK_IF_ABORTED();
- Async_Listen(stmt->relname, MasterPid);
+ Async_Listen(stmt->relname, MyProcPid);
}
break;
FILE *fp;
char *filename;
- commandTag = "LOAD";
+ *ps_status = commandTag = "LOAD";
CHECK_IF_ABORTED();
filename = stmt->filename;
closeAllVfds();
if ((fp = AllocateFile(filename, "r")) == NULL)
- elog(WARN, "LOAD: could not open file %s", filename);
+ elog(ERROR, "LOAD: could not open file %s", filename);
FreeFile(fp);
load_file(filename);
}
{
ClusterStmt *stmt = (ClusterStmt *) parsetree;
- commandTag = "CLUSTER";
+ *ps_status = commandTag = "CLUSTER";
CHECK_IF_ABORTED();
cluster(stmt->relname, stmt->indexname);
break;
case T_VacuumStmt:
- commandTag = "VACUUM";
+ *ps_status = commandTag = "VACUUM";
CHECK_IF_ABORTED();
vacuum(((VacuumStmt *) parsetree)->vacrel,
((VacuumStmt *) parsetree)->verbose,
{
ExplainStmt *stmt = (ExplainStmt *) parsetree;
- commandTag = "EXPLAIN";
+ *ps_status = commandTag = "EXPLAIN";
CHECK_IF_ABORTED();
ExplainQuery(stmt->query, stmt->verbose, dest);
{
RecipeStmt *stmt = (RecipeStmt *) parsetree;
- commandTag = "EXECUTE RECIPE";
+ *ps_status = commandTag = "EXECUTE RECIPE";
CHECK_IF_ABORTED();
beginRecipe(stmt);
}
VariableSetStmt *n = (VariableSetStmt *) parsetree;
SetPGVariable(n->name, n->value);
- commandTag = "SET VARIABLE";
+ *ps_status = commandTag = "SET VARIABLE";
}
break;
VariableShowStmt *n = (VariableShowStmt *) parsetree;
GetPGVariable(n->name);
- commandTag = "SHOW VARIABLE";
+ *ps_status = commandTag = "SHOW VARIABLE";
}
break;
VariableResetStmt *n = (VariableResetStmt *) parsetree;
ResetPGVariable(n->name);
- commandTag = "RESET VARIABLE";
+ *ps_status = commandTag = "RESET VARIABLE";
}
break;
* ******************************** TRIGGER statements *******************************
*/
case T_CreateTrigStmt:
- commandTag = "CREATE";
+ *ps_status = commandTag = "CREATE";
CHECK_IF_ABORTED();
CreateTrigger((CreateTrigStmt *) parsetree);
break;
case T_DropTrigStmt:
- commandTag = "DROP";
+ *ps_status = commandTag = "DROP";
CHECK_IF_ABORTED();
DropTrigger((DropTrigStmt *) parsetree);
* ************* PROCEDURAL LANGUAGE statements *****************
*/
case T_CreatePLangStmt:
- commandTag = "CREATE";
+ *ps_status = commandTag = "CREATE";
CHECK_IF_ABORTED();
CreateProceduralLanguage((CreatePLangStmt *) parsetree);
break;
case T_DropPLangStmt:
- commandTag = "DROP";
+ *ps_status = commandTag = "DROP";
CHECK_IF_ABORTED();
DropProceduralLanguage((DropPLangStmt *) parsetree);
break;
+ /*
+ * ******************************** USER statements ****
+ *
+ */
+ case T_CreateUserStmt:
+ *ps_status = commandTag = "CREATE USER";
+ CHECK_IF_ABORTED();
+
+ DefineUser((CreateUserStmt *) parsetree);
+ break;
+
+ case T_AlterUserStmt:
+ *ps_status = commandTag = "ALTER USER";
+ CHECK_IF_ABORTED();
+
+ AlterUser((AlterUserStmt *) parsetree);
+ break;
+
+ case T_DropUserStmt:
+ *ps_status = commandTag = "DROP USER";
+ CHECK_IF_ABORTED();
+
+ RemoveUser(((DropUserStmt *) parsetree)->user);
+ break;
+
+
/*
* ******************************** default ********************************
*
*/
default:
- elog(WARN, "ProcessUtility: command #%d unsupported",
+ elog(ERROR, "ProcessUtility: command #%d unsupported",
nodeTag(parsetree));
break;
}