mirror of
https://github.com/postgres/postgres.git
synced 2025-06-27 23:21:58 +03:00
The contents of command.c, creatinh.c, define.c, remove.c and rename.c
have been divided according to the type of object manipulated - so ALTER TABLE code is in tablecmds.c, aggregate commands in aggregatecmds.c and so on. A few common support routines remain in define.c (prototypes in src/include/commands/defrem.h). No code has been changed except for includes to reflect the new files. The prototypes for aggregatecmds.c, functioncmds.c, operatorcmds.c, and typecmds.c remain in src/include/commands/defrem.h. From John Gray <jgray@azuli.co.uk>
This commit is contained in:
116
src/backend/commands/schemacmds.c
Normal file
116
src/backend/commands/schemacmds.c
Normal file
@ -0,0 +1,116 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* schemacmds.c
|
||||
* schema creation command support code
|
||||
*
|
||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/schemacmds.c,v 1.1 2002/04/15 05:22:03 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include "catalog/catalog.h"
|
||||
#include "catalog/pg_namespace.h"
|
||||
#include "commands/schemacmds.h"
|
||||
#include "miscadmin.h"
|
||||
#include "parser/analyze.h"
|
||||
#include "tcop/utility.h"
|
||||
#include "utils/lsyscache.h"
|
||||
|
||||
|
||||
/*
|
||||
* CREATE SCHEMA
|
||||
*/
|
||||
void
|
||||
CreateSchemaCommand(CreateSchemaStmt *stmt)
|
||||
{
|
||||
const char *schemaName = stmt->schemaname;
|
||||
const char *authId = stmt->authid;
|
||||
List *parsetree_list;
|
||||
List *parsetree_item;
|
||||
const char *owner_name;
|
||||
Oid owner_userid;
|
||||
Oid saved_userid;
|
||||
|
||||
saved_userid = GetUserId();
|
||||
|
||||
if (!authId)
|
||||
{
|
||||
owner_userid = saved_userid;
|
||||
owner_name = GetUserName(owner_userid);
|
||||
}
|
||||
else if (superuser())
|
||||
{
|
||||
owner_name = authId;
|
||||
/* The following will error out if user does not exist */
|
||||
owner_userid = get_usesysid(owner_name);
|
||||
/*
|
||||
* Set the current user to the requested authorization so
|
||||
* that objects created in the statement have the requested
|
||||
* owner. (This will revert to session user on error or at
|
||||
* the end of this routine.)
|
||||
*/
|
||||
SetUserId(owner_userid);
|
||||
}
|
||||
else /* not superuser */
|
||||
{
|
||||
owner_userid = saved_userid;
|
||||
owner_name = GetUserName(owner_userid);
|
||||
if (strcmp(authId, owner_name) != 0)
|
||||
elog(ERROR, "CREATE SCHEMA: permission denied"
|
||||
"\n\t\"%s\" is not a superuser, so cannot create a schema for \"%s\"",
|
||||
owner_name, authId);
|
||||
}
|
||||
|
||||
if (!allowSystemTableMods && IsReservedName(schemaName))
|
||||
elog(ERROR, "CREATE SCHEMA: Illegal schema name: \"%s\" -- pg_ is reserved for system schemas",
|
||||
schemaName);
|
||||
|
||||
/* Create the schema's namespace */
|
||||
NamespaceCreate(schemaName, owner_userid);
|
||||
|
||||
/* Let commands in the schema-element-list know about the schema */
|
||||
CommandCounterIncrement();
|
||||
|
||||
/*
|
||||
* Examine the list of commands embedded in the CREATE SCHEMA command,
|
||||
* and reorganize them into a sequentially executable order with no
|
||||
* forward references. Note that the result is still a list of raw
|
||||
* parsetrees in need of parse analysis --- we cannot, in general,
|
||||
* run analyze.c on one statement until we have actually executed the
|
||||
* prior ones.
|
||||
*/
|
||||
parsetree_list = analyzeCreateSchemaStmt(stmt);
|
||||
|
||||
/*
|
||||
* Analyze and execute each command contained in the CREATE SCHEMA
|
||||
*/
|
||||
foreach(parsetree_item, parsetree_list)
|
||||
{
|
||||
Node *parsetree = (Node *) lfirst(parsetree_item);
|
||||
List *querytree_list,
|
||||
*querytree_item;
|
||||
|
||||
querytree_list = parse_analyze(parsetree, NULL);
|
||||
|
||||
foreach(querytree_item, querytree_list)
|
||||
{
|
||||
Query *querytree = (Query *) lfirst(querytree_item);
|
||||
|
||||
/* schemas should contain only utility stmts */
|
||||
Assert(querytree->commandType == CMD_UTILITY);
|
||||
/* do this step */
|
||||
ProcessUtility(querytree->utilityStmt, None, NULL);
|
||||
/* make sure later steps can see the object created here */
|
||||
CommandCounterIncrement();
|
||||
}
|
||||
}
|
||||
|
||||
/* Reset current user */
|
||||
SetUserId(saved_userid);
|
||||
}
|
Reference in New Issue
Block a user