]> granicus.if.org Git - postgresql/blobdiff - src/backend/tcop/utility.c
From: t-ishii@sra.co.jp
[postgresql] / src / backend / tcop / utility.c
index 9ffcf151d52bd41457e7b8d9f9395a4d5b6a503a..94f44a73857076f37e053e089bb0a073693a4b39 100644 (file)
@@ -9,12 +9,11 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.28 1997/11/07 06:38:51 thomas Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.44 1998/07/26 04:30:48 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include "postgres.h"
-#include "parser/dbcommands.h"
 #include "access/xact.h"
 #include "access/heapam.h"
 #include "catalog/catalog.h"
@@ -25,9 +24,9 @@
 #include "commands/command.h"
 #include "commands/copy.h"
 #include "commands/creatinh.h"
+#include "commands/dbcommands.h"
 #include "commands/sequence.h"
 #include "commands/defrem.h"
-#include "commands/purge.h"
 #include "commands/rename.h"
 #include "commands/view.h"
 #include "commands/version.h"
@@ -36,6 +35,7 @@
 #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"
@@ -46,7 +46,6 @@
 #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;
@@ -100,18 +109,18 @@ ProcessUtility(Node * parsetree,
                                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;
                                }
@@ -126,7 +135,7 @@ ProcessUtility(Node * parsetree,
                        {
                                ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
 
-                               commandTag = "CLOSE";
+                               *ps_status = commandTag = "CLOSE";
                                CHECK_IF_ABORTED();
 
                                PerformPortalClose(stmt->portalname, dest);
@@ -140,7 +149,7 @@ ProcessUtility(Node * parsetree,
                                bool            forward;
                                int                     count;
 
-                               commandTag = (stmt->ismove) ? "MOVE" : "FETCH";
+                               *ps_status = commandTag = (stmt->ismove) ? "MOVE" : "FETCH";
                                CHECK_IF_ABORTED();
 
                                forward = (bool) (stmt->direction == FORWARD);
@@ -161,7 +170,7 @@ ProcessUtility(Node * parsetree,
                         *
                         */
                case T_CreateStmt:
-                       commandTag = "CREATE";
+                       *ps_status = commandTag = "CREATE";
                        CHECK_IF_ABORTED();
 
                        DefineRelation((CreateStmt *) parsetree);
@@ -174,31 +183,31 @@ ProcessUtility(Node * 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
                                }
@@ -210,24 +219,11 @@ ProcessUtility(Node * parsetree,
                        }
                        break;
 
-               case T_PurgeStmt:
-                       {
-                               PurgeStmt  *stmt = (PurgeStmt *) parsetree;
-
-                               commandTag = "PURGE";
-                               CHECK_IF_ABORTED();
-
-                               RelationPurge(stmt->relname,
-                                                         stmt->beforeDate, /* absolute time string */
-                                                         stmt->afterDate); /* relative time string */
-                       }
-                       break;
-
                case T_CopyStmt:
                        {
                                CopyStmt   *stmt = (CopyStmt *) parsetree;
 
-                               commandTag = "COPY";
+                               *ps_status = commandTag = "COPY";
                                CHECK_IF_ABORTED();
 
                                DoCopy(stmt->relname,
@@ -249,7 +245,7 @@ ProcessUtility(Node * parsetree,
                        {
                                AddAttrStmt *stmt = (AddAttrStmt *) parsetree;
 
-                               commandTag = "ADD";
+                               *ps_status = commandTag = "ADD";
                                CHECK_IF_ABORTED();
 
                                /*
@@ -259,7 +255,7 @@ ProcessUtility(Node * parsetree,
                                PerformAddAttribute(stmt->relname,
                                                                        userName,
                                                                        stmt->inh,
-                                                                       stmt->colDef);
+                                                                       (ColumnDef *) stmt->colDef);
                        }
                        break;
 
@@ -270,16 +266,16 @@ ProcessUtility(Node * parsetree,
                        {
                                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
 
@@ -328,7 +324,7 @@ ProcessUtility(Node * parsetree,
                                AclItem    *aip;
                                unsigned        modechg;
 
-                               commandTag = "CHANGE";
+                               *ps_status = commandTag = "CHANGE";
                                CHECK_IF_ABORTED();
 
                                aip = stmt->aclitem;
@@ -339,7 +335,7 @@ ProcessUtility(Node * parsetree,
                                {
                                        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
@@ -361,7 +357,7 @@ ProcessUtility(Node * parsetree,
                        {
                                DefineStmt *stmt = (DefineStmt *) parsetree;
 
-                               commandTag = "CREATE";
+                               *ps_status = commandTag = "CREATE";
                                CHECK_IF_ABORTED();
 
                                switch (stmt->defType)
@@ -371,9 +367,7 @@ ProcessUtility(Node * parsetree,
                                                                           stmt->definition);           /* rest */
                                                break;
                                        case TYPE_P:
-                                               {
                                                        DefineType(stmt->defname, stmt->definition);
-                                               }
                                                break;
                                        case AGGREGATE:
                                                DefineAggregate(stmt->defname,  /* aggregate name */
@@ -387,14 +381,14 @@ ProcessUtility(Node * parsetree,
                        {
                                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;
@@ -403,9 +397,8 @@ ProcessUtility(Node * parsetree,
                        {
                                IndexStmt  *stmt = (IndexStmt *) parsetree;
 
-                               commandTag = "CREATE";
+                               *ps_status = commandTag = "CREATE";
                                CHECK_IF_ABORTED();
-                               /* XXX no support for ARCHIVE indices, yet */
                                DefineIndex(stmt->relname,              /* relation name */
                                                        stmt->idxname,          /* index name */
                                                        stmt->accessMethod, /* am name */
@@ -426,16 +419,16 @@ ProcessUtility(Node * parsetree,
                                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);
@@ -445,7 +438,7 @@ ProcessUtility(Node * parsetree,
                        {
                                ExtendStmt *stmt = (ExtendStmt *) parsetree;
 
-                               commandTag = "EXTEND";
+                               *ps_status = commandTag = "EXTEND";
                                CHECK_IF_ABORTED();
 
                                ExtendIndex(stmt->idxname,              /* index name */
@@ -458,7 +451,7 @@ ProcessUtility(Node * parsetree,
                        {
                                RemoveStmt *stmt = (RemoveStmt *) parsetree;
 
-                               commandTag = "DROP";
+                               *ps_status = commandTag = "DROP";
                                CHECK_IF_ABORTED();
 
                                switch (stmt->removeType)
@@ -466,11 +459,11 @@ ProcessUtility(Node * parsetree,
                                        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;
@@ -484,9 +477,7 @@ ProcessUtility(Node * parsetree,
                                                        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);
                                                }
@@ -507,7 +498,7 @@ ProcessUtility(Node * parsetree,
                                                        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);
@@ -522,7 +513,7 @@ ProcessUtility(Node * parsetree,
                        {
                                RemoveAggrStmt *stmt = (RemoveAggrStmt *) parsetree;
 
-                               commandTag = "DROP";
+                               *ps_status = commandTag = "DROP";
                                CHECK_IF_ABORTED();
                                RemoveAggregate(stmt->aggname, stmt->aggtype);
                        }
@@ -532,7 +523,7 @@ ProcessUtility(Node * parsetree,
                        {
                                RemoveFuncStmt *stmt = (RemoveFuncStmt *) parsetree;
 
-                               commandTag = "DROP";
+                               *ps_status = commandTag = "DROP";
                                CHECK_IF_ABORTED();
                                RemoveFunction(stmt->funcname,
                                                           length(stmt->args),
@@ -546,7 +537,7 @@ ProcessUtility(Node * parsetree,
                                char       *type1 = (char *) NULL;
                                char       *type2 = (char *) NULL;
 
-                               commandTag = "DROP";
+                               *ps_status = commandTag = "DROP";
                                CHECK_IF_ABORTED();
 
                                if (lfirst(stmt->args) != NULL)
@@ -558,18 +549,20 @@ ProcessUtility(Node * parsetree,
                        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;
 
@@ -577,7 +570,7 @@ ProcessUtility(Node * parsetree,
                        {
                                DestroydbStmt *stmt = (DestroydbStmt *) parsetree;
 
-                               commandTag = "DESTROYDB";
+                               *ps_status = commandTag = "DESTROYDB";
                                CHECK_IF_ABORTED();
                                destroydb(stmt->dbname);
                        }
@@ -588,7 +581,7 @@ ProcessUtility(Node * parsetree,
                        {
                                NotifyStmt *stmt = (NotifyStmt *) parsetree;
 
-                               commandTag = "NOTIFY";
+                               *ps_status = commandTag = "NOTIFY";
                                CHECK_IF_ABORTED();
 
                                Async_Notify(stmt->relname);
@@ -599,10 +592,10 @@ ProcessUtility(Node * parsetree,
                        {
                                ListenStmt *stmt = (ListenStmt *) parsetree;
 
-                               commandTag = "LISTEN";
+                               *ps_status = commandTag = "LISTEN";
                                CHECK_IF_ABORTED();
 
-                               Async_Listen(stmt->relname, MasterPid);
+                               Async_Listen(stmt->relname, MyProcPid);
                        }
                        break;
 
@@ -616,13 +609,13 @@ ProcessUtility(Node * parsetree,
                                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);
                        }
@@ -632,7 +625,7 @@ ProcessUtility(Node * parsetree,
                        {
                                ClusterStmt *stmt = (ClusterStmt *) parsetree;
 
-                               commandTag = "CLUSTER";
+                               *ps_status = commandTag = "CLUSTER";
                                CHECK_IF_ABORTED();
 
                                cluster(stmt->relname, stmt->indexname);
@@ -640,7 +633,7 @@ ProcessUtility(Node * parsetree,
                        break;
 
                case T_VacuumStmt:
-                       commandTag = "VACUUM";
+                       *ps_status = commandTag = "VACUUM";
                        CHECK_IF_ABORTED();
                        vacuum(((VacuumStmt *) parsetree)->vacrel,
                                   ((VacuumStmt *) parsetree)->verbose,
@@ -652,7 +645,7 @@ ProcessUtility(Node * parsetree,
                        {
                                ExplainStmt *stmt = (ExplainStmt *) parsetree;
 
-                               commandTag = "EXPLAIN";
+                               *ps_status = commandTag = "EXPLAIN";
                                CHECK_IF_ABORTED();
 
                                ExplainQuery(stmt->query, stmt->verbose, dest);
@@ -666,7 +659,7 @@ ProcessUtility(Node * parsetree,
                        {
                                RecipeStmt *stmt = (RecipeStmt *) parsetree;
 
-                               commandTag = "EXECUTE RECIPE";
+                               *ps_status = commandTag = "EXECUTE RECIPE";
                                CHECK_IF_ABORTED();
                                beginRecipe(stmt);
                        }
@@ -680,7 +673,7 @@ ProcessUtility(Node * parsetree,
                                VariableSetStmt *n = (VariableSetStmt *) parsetree;
 
                                SetPGVariable(n->name, n->value);
-                               commandTag = "SET VARIABLE";
+                               *ps_status = commandTag = "SET VARIABLE";
                        }
                        break;
 
@@ -689,7 +682,7 @@ ProcessUtility(Node * parsetree,
                                VariableShowStmt *n = (VariableShowStmt *) parsetree;
 
                                GetPGVariable(n->name);
-                               commandTag = "SHOW VARIABLE";
+                               *ps_status = commandTag = "SHOW VARIABLE";
                        }
                        break;
 
@@ -698,7 +691,7 @@ ProcessUtility(Node * parsetree,
                                VariableResetStmt *n = (VariableResetStmt *) parsetree;
 
                                ResetPGVariable(n->name);
-                               commandTag = "RESET VARIABLE";
+                               *ps_status = commandTag = "RESET VARIABLE";
                        }
                        break;
 
@@ -706,14 +699,14 @@ ProcessUtility(Node * parsetree,
                         * ******************************** 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);
@@ -723,25 +716,51 @@ ProcessUtility(Node * 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;
        }