mirror of
https://github.com/postgres/postgres.git
synced 2025-08-14 02:22:38 +03:00
Adjust more backend functions to return OID rather than void.
This is again intended to support extensions to the event trigger functionality. This may go a bit further than we need for that purpose, but there's some value in being consistent, and the OID may be useful for other purposes also. Dimitri Fontaine
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
* This routine is used to add the associated comment into
|
||||
* pg_description for the object specified by the given SQL command.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
CommentObject(CommentStmt *stmt)
|
||||
{
|
||||
ObjectAddress address;
|
||||
@@ -60,7 +60,7 @@ CommentObject(CommentStmt *stmt)
|
||||
ereport(WARNING,
|
||||
(errcode(ERRCODE_UNDEFINED_DATABASE),
|
||||
errmsg("database \"%s\" does not exist", database)));
|
||||
return;
|
||||
return InvalidOid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,8 @@ CommentObject(CommentStmt *stmt)
|
||||
*/
|
||||
if (relation != NULL)
|
||||
relation_close(relation, NoLock);
|
||||
|
||||
return address.objectId;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -743,14 +743,14 @@ CopyLoadRawBuf(CopyState cstate)
|
||||
* Do not allow the copy if user doesn't have proper permission to access
|
||||
* the table or the specifically requested columns.
|
||||
*/
|
||||
uint64
|
||||
DoCopy(const CopyStmt *stmt, const char *queryString)
|
||||
Oid
|
||||
DoCopy(const CopyStmt *stmt, const char *queryString, uint64 *processed)
|
||||
{
|
||||
CopyState cstate;
|
||||
bool is_from = stmt->is_from;
|
||||
bool pipe = (stmt->filename == NULL);
|
||||
Relation rel;
|
||||
uint64 processed;
|
||||
Oid relid;
|
||||
|
||||
/* Disallow file COPY except to superusers. */
|
||||
if (!pipe && !superuser())
|
||||
@@ -774,6 +774,8 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
|
||||
rel = heap_openrv(stmt->relation,
|
||||
(is_from ? RowExclusiveLock : AccessShareLock));
|
||||
|
||||
relid = RelationGetRelid(rel);
|
||||
|
||||
rte = makeNode(RangeTblEntry);
|
||||
rte->rtekind = RTE_RELATION;
|
||||
rte->relid = RelationGetRelid(rel);
|
||||
@@ -811,14 +813,14 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
|
||||
|
||||
cstate = BeginCopyFrom(rel, stmt->filename,
|
||||
stmt->attlist, stmt->options);
|
||||
processed = CopyFrom(cstate); /* copy from file to database */
|
||||
*processed = CopyFrom(cstate); /* copy from file to database */
|
||||
EndCopyFrom(cstate);
|
||||
}
|
||||
else
|
||||
{
|
||||
cstate = BeginCopyTo(rel, stmt->query, queryString, stmt->filename,
|
||||
stmt->attlist, stmt->options);
|
||||
processed = DoCopyTo(cstate); /* copy from database to file */
|
||||
*processed = DoCopyTo(cstate); /* copy from database to file */
|
||||
EndCopyTo(cstate);
|
||||
}
|
||||
|
||||
@@ -830,7 +832,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
|
||||
if (rel != NULL)
|
||||
heap_close(rel, (is_from ? NoLock : AccessShareLock));
|
||||
|
||||
return processed;
|
||||
return relid;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -90,7 +90,7 @@ static int errdetail_busy_db(int notherbackends, int npreparedxacts);
|
||||
/*
|
||||
* CREATE DATABASE
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
createdb(const CreatedbStmt *stmt)
|
||||
{
|
||||
HeapScanDesc scan;
|
||||
@@ -655,6 +655,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
}
|
||||
PG_END_ENSURE_ERROR_CLEANUP(createdb_failure_callback,
|
||||
PointerGetDatum(&fparms));
|
||||
|
||||
return dboid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1301,10 +1303,11 @@ movedb_failure_callback(int code, Datum arg)
|
||||
/*
|
||||
* ALTER DATABASE name ...
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
|
||||
{
|
||||
Relation rel;
|
||||
Oid dboid;
|
||||
HeapTuple tuple,
|
||||
newtuple;
|
||||
ScanKeyData scankey;
|
||||
@@ -1350,7 +1353,7 @@ AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
|
||||
/* this case isn't allowed within a transaction block */
|
||||
PreventTransactionChain(isTopLevel, "ALTER DATABASE SET TABLESPACE");
|
||||
movedb(stmt->dbname, strVal(dtablespace->arg));
|
||||
return;
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
if (dconnlimit)
|
||||
@@ -1380,6 +1383,8 @@ AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
|
||||
(errcode(ERRCODE_UNDEFINED_DATABASE),
|
||||
errmsg("database \"%s\" does not exist", stmt->dbname)));
|
||||
|
||||
dboid = HeapTupleGetOid(tuple);
|
||||
|
||||
if (!pg_database_ownercheck(HeapTupleGetOid(tuple), GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
|
||||
stmt->dbname);
|
||||
@@ -1408,13 +1413,15 @@ AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
|
||||
|
||||
/* Close pg_database, but keep lock till commit */
|
||||
heap_close(rel, NoLock);
|
||||
|
||||
return dboid;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ALTER DATABASE name SET ...
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
|
||||
{
|
||||
Oid datid = get_database_oid(stmt->dbname, false);
|
||||
@@ -1432,6 +1439,8 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
|
||||
AlterSetting(datid, InvalidOid, stmt->setstmt);
|
||||
|
||||
UnlockSharedObject(DatabaseRelationId, datid, 0, AccessShareLock);
|
||||
|
||||
return datid;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -94,15 +94,15 @@ static void AlterEventTriggerOwner_internal(Relation rel,
|
||||
static event_trigger_command_tag_check_result check_ddl_tag(const char *tag);
|
||||
static void error_duplicate_filter_variable(const char *defname);
|
||||
static Datum filter_list_to_array(List *filterlist);
|
||||
static void insert_event_trigger_tuple(char *trigname, char *eventname,
|
||||
Oid evtOwner, Oid funcoid, List *tags);
|
||||
static Oid insert_event_trigger_tuple(char *trigname, char *eventname,
|
||||
Oid evtOwner, Oid funcoid, List *tags);
|
||||
static void validate_ddl_tags(const char *filtervar, List *taglist);
|
||||
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata);
|
||||
|
||||
/*
|
||||
* Create an event trigger.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
CreateEventTrigger(CreateEventTrigStmt *stmt)
|
||||
{
|
||||
HeapTuple tuple;
|
||||
@@ -173,8 +173,8 @@ CreateEventTrigger(CreateEventTrigStmt *stmt)
|
||||
NameListToString(stmt->funcname))));
|
||||
|
||||
/* Insert catalog entries. */
|
||||
insert_event_trigger_tuple(stmt->trigname, stmt->eventname,
|
||||
evtowner, funcoid, tags);
|
||||
return insert_event_trigger_tuple(stmt->trigname, stmt->eventname,
|
||||
evtowner, funcoid, tags);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -260,7 +260,7 @@ error_duplicate_filter_variable(const char *defname)
|
||||
/*
|
||||
* Insert the new pg_event_trigger row and record dependencies.
|
||||
*/
|
||||
static void
|
||||
static Oid
|
||||
insert_event_trigger_tuple(char *trigname, char *eventname, Oid evtOwner,
|
||||
Oid funcoid, List *taglist)
|
||||
{
|
||||
@@ -312,6 +312,8 @@ insert_event_trigger_tuple(char *trigname, char *eventname, Oid evtOwner,
|
||||
|
||||
/* Close pg_event_trigger. */
|
||||
heap_close(tgrel, RowExclusiveLock);
|
||||
|
||||
return trigoid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -376,11 +378,12 @@ RemoveEventTriggerById(Oid trigOid)
|
||||
/*
|
||||
* ALTER EVENT TRIGGER foo ENABLE|DISABLE|ENABLE ALWAYS|REPLICA
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterEventTrigger(AlterEventTrigStmt *stmt)
|
||||
{
|
||||
Relation tgrel;
|
||||
HeapTuple tup;
|
||||
Oid trigoid;
|
||||
Form_pg_event_trigger evtForm;
|
||||
char tgenabled = stmt->tgenabled;
|
||||
|
||||
@@ -393,7 +396,10 @@ AlterEventTrigger(AlterEventTrigStmt *stmt)
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("event trigger \"%s\" does not exist",
|
||||
stmt->trigname)));
|
||||
if (!pg_event_trigger_ownercheck(HeapTupleGetOid(tup), GetUserId()))
|
||||
|
||||
trigoid = HeapTupleGetOid(tup);
|
||||
|
||||
if (!pg_event_trigger_ownercheck(trigoid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_EVENT_TRIGGER,
|
||||
stmt->trigname);
|
||||
|
||||
@@ -407,6 +413,8 @@ AlterEventTrigger(AlterEventTrigStmt *stmt)
|
||||
/* clean up */
|
||||
heap_freetuple(tup);
|
||||
heap_close(tgrel, RowExclusiveLock);
|
||||
|
||||
return trigoid;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -2580,7 +2580,7 @@ AlterExtensionNamespace(List *names, const char *newschema)
|
||||
/*
|
||||
* Execute ALTER EXTENSION UPDATE
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
ExecAlterExtensionStmt(AlterExtensionStmt *stmt)
|
||||
{
|
||||
DefElem *d_new_version = NULL;
|
||||
@@ -2697,7 +2697,7 @@ ExecAlterExtensionStmt(AlterExtensionStmt *stmt)
|
||||
ereport(NOTICE,
|
||||
(errmsg("version \"%s\" of extension \"%s\" is already installed",
|
||||
versionName, stmt->extname)));
|
||||
return;
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2713,6 +2713,8 @@ ExecAlterExtensionStmt(AlterExtensionStmt *stmt)
|
||||
*/
|
||||
ApplyExtensionUpdates(extensionOid, control,
|
||||
oldVersionName, updateVersions);
|
||||
|
||||
return extensionOid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2875,7 +2877,7 @@ ApplyExtensionUpdates(Oid extensionOid,
|
||||
/*
|
||||
* Execute ALTER EXTENSION ADD/DROP
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt)
|
||||
{
|
||||
ObjectAddress extension;
|
||||
@@ -2976,4 +2978,6 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt)
|
||||
*/
|
||||
if (relation != NULL)
|
||||
relation_close(relation, NoLock);
|
||||
|
||||
return extension.objectId;
|
||||
}
|
||||
|
@@ -583,7 +583,7 @@ parse_func_options(List *func_options,
|
||||
/*
|
||||
* Create a foreign-data wrapper
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
CreateForeignDataWrapper(CreateFdwStmt *stmt)
|
||||
{
|
||||
Relation rel;
|
||||
@@ -690,13 +690,15 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
|
||||
ForeignDataWrapperRelationId, fdwId, 0, NULL);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
|
||||
return fdwId;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Alter foreign-data wrapper
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterForeignDataWrapper(AlterFdwStmt *stmt)
|
||||
{
|
||||
Relation rel;
|
||||
@@ -851,6 +853,8 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
|
||||
}
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
|
||||
return fdwId;
|
||||
}
|
||||
|
||||
|
||||
@@ -881,7 +885,7 @@ RemoveForeignDataWrapperById(Oid fdwId)
|
||||
/*
|
||||
* Create a foreign server
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
CreateForeignServer(CreateForeignServerStmt *stmt)
|
||||
{
|
||||
Relation rel;
|
||||
@@ -987,13 +991,15 @@ CreateForeignServer(CreateForeignServerStmt *stmt)
|
||||
ForeignServerRelationId, srvId, 0, NULL);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
|
||||
return srvId;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Alter foreign server
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterForeignServer(AlterForeignServerStmt *stmt)
|
||||
{
|
||||
Relation rel;
|
||||
@@ -1080,6 +1086,8 @@ AlterForeignServer(AlterForeignServerStmt *stmt)
|
||||
heap_freetuple(tp);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
|
||||
return srvId;
|
||||
}
|
||||
|
||||
|
||||
@@ -1137,7 +1145,7 @@ user_mapping_ddl_aclcheck(Oid umuserid, Oid serverid, const char *servername)
|
||||
/*
|
||||
* Create user mapping
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
CreateUserMapping(CreateUserMappingStmt *stmt)
|
||||
{
|
||||
Relation rel;
|
||||
@@ -1228,13 +1236,15 @@ CreateUserMapping(CreateUserMappingStmt *stmt)
|
||||
UserMappingRelationId, umId, 0, NULL);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
|
||||
return umId;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Alter user mapping
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterUserMapping(AlterUserMappingStmt *stmt)
|
||||
{
|
||||
Relation rel;
|
||||
@@ -1314,13 +1324,15 @@ AlterUserMapping(AlterUserMappingStmt *stmt)
|
||||
heap_freetuple(tp);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
|
||||
return umId;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Drop user mapping
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
RemoveUserMapping(DropUserMappingStmt *stmt)
|
||||
{
|
||||
ObjectAddress object;
|
||||
@@ -1338,7 +1350,7 @@ RemoveUserMapping(DropUserMappingStmt *stmt)
|
||||
* leave.
|
||||
*/
|
||||
elog(NOTICE, "role \"%s\" does not exist, skipping", stmt->username);
|
||||
return;
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
if (!srv)
|
||||
@@ -1350,7 +1362,7 @@ RemoveUserMapping(DropUserMappingStmt *stmt)
|
||||
stmt->servername)));
|
||||
/* IF EXISTS, just note it */
|
||||
ereport(NOTICE, (errmsg("server does not exist, skipping")));
|
||||
return;
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
umId = GetSysCacheOid2(USERMAPPINGUSERSERVER,
|
||||
@@ -1369,7 +1381,7 @@ RemoveUserMapping(DropUserMappingStmt *stmt)
|
||||
ereport(NOTICE,
|
||||
(errmsg("user mapping \"%s\" does not exist for the server, skipping",
|
||||
MappingUserName(useId))));
|
||||
return;
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
user_mapping_ddl_aclcheck(useId, srv->serverid, srv->servername);
|
||||
@@ -1382,6 +1394,8 @@ RemoveUserMapping(DropUserMappingStmt *stmt)
|
||||
object.objectSubId = 0;
|
||||
|
||||
performDeletion(&object, DROP_CASCADE, 0);
|
||||
|
||||
return umId;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1111,7 +1111,7 @@ RenameFunction(List *name, List *argtypes, const char *newname)
|
||||
* RENAME and OWNER clauses, which are handled as part of the generic
|
||||
* ALTER framework).
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterFunction(AlterFunctionStmt *stmt)
|
||||
{
|
||||
HeapTuple tup;
|
||||
@@ -1241,6 +1241,8 @@ AlterFunction(AlterFunctionStmt *stmt)
|
||||
|
||||
heap_close(rel, NoLock);
|
||||
heap_freetuple(tup);
|
||||
|
||||
return funcOid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1318,7 +1320,7 @@ SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType)
|
||||
/*
|
||||
* CREATE CAST
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
CreateCast(CreateCastStmt *stmt)
|
||||
{
|
||||
Oid sourcetypeid;
|
||||
@@ -1632,6 +1634,8 @@ CreateCast(CreateCastStmt *stmt)
|
||||
heap_freetuple(tuple);
|
||||
|
||||
heap_close(relation, RowExclusiveLock);
|
||||
|
||||
return castid;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -1671,7 +1671,7 @@ ChooseIndexColumnNames(List *indexElems)
|
||||
* ReindexIndex
|
||||
* Recreate a specific index.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
ReindexIndex(RangeVar *indexRelation)
|
||||
{
|
||||
Oid indOid;
|
||||
@@ -1684,6 +1684,8 @@ ReindexIndex(RangeVar *indexRelation)
|
||||
(void *) &heapOid);
|
||||
|
||||
reindex_index(indOid, false);
|
||||
|
||||
return indOid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1749,7 +1751,7 @@ RangeVarCallbackForReindexIndex(const RangeVar *relation,
|
||||
* ReindexTable
|
||||
* Recreate all indexes of a table (and of its toast table, if any)
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
ReindexTable(RangeVar *relation)
|
||||
{
|
||||
Oid heapOid;
|
||||
@@ -1762,6 +1764,8 @@ ReindexTable(RangeVar *relation)
|
||||
ereport(NOTICE,
|
||||
(errmsg("table \"%s\" has no indexes",
|
||||
relation->relname)));
|
||||
|
||||
return heapOid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1772,7 +1776,7 @@ ReindexTable(RangeVar *relation)
|
||||
* separate transaction, so we can release the lock on it right away.
|
||||
* That means this must not be called within a user transaction block!
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
ReindexDatabase(const char *databaseName, bool do_system, bool do_user)
|
||||
{
|
||||
Relation relationRelation;
|
||||
@@ -1882,4 +1886,6 @@ ReindexDatabase(const char *databaseName, bool do_system, bool do_user)
|
||||
StartTransactionCommand();
|
||||
|
||||
MemoryContextDelete(private_context);
|
||||
|
||||
return MyDatabaseId;
|
||||
}
|
||||
|
@@ -321,7 +321,7 @@ CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid)
|
||||
* DefineOpClass
|
||||
* Define a new index operator class.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
DefineOpClass(CreateOpClassStmt *stmt)
|
||||
{
|
||||
char *opcname; /* name of opclass we're creating */
|
||||
@@ -714,6 +714,8 @@ DefineOpClass(CreateOpClassStmt *stmt)
|
||||
OperatorClassRelationId, opclassoid, 0, NULL);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
|
||||
return opclassoid;
|
||||
}
|
||||
|
||||
|
||||
@@ -721,7 +723,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
|
||||
* DefineOpFamily
|
||||
* Define a new index operator family.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
DefineOpFamily(CreateOpFamilyStmt *stmt)
|
||||
{
|
||||
char *opfname; /* name of opfamily we're creating */
|
||||
@@ -754,7 +756,7 @@ DefineOpFamily(CreateOpFamilyStmt *stmt)
|
||||
errmsg("must be superuser to create an operator family")));
|
||||
|
||||
/* Insert pg_opfamily catalog entry */
|
||||
(void) CreateOpFamily(stmt->amname, opfname, namespaceoid, amoid);
|
||||
return CreateOpFamily(stmt->amname, opfname, namespaceoid, amoid);
|
||||
}
|
||||
|
||||
|
||||
@@ -766,7 +768,7 @@ DefineOpFamily(CreateOpFamilyStmt *stmt)
|
||||
* other commands called ALTER OPERATOR FAMILY exist, but go through
|
||||
* different code paths.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterOpFamily(AlterOpFamilyStmt *stmt)
|
||||
{
|
||||
Oid amoid, /* our AM's oid */
|
||||
@@ -820,6 +822,8 @@ AlterOpFamily(AlterOpFamilyStmt *stmt)
|
||||
AlterOpFamilyAdd(stmt->opfamilyname, amoid, opfamilyoid,
|
||||
maxOpNumber, maxProcNumber,
|
||||
stmt->items);
|
||||
|
||||
return opfamilyoid;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -51,16 +51,16 @@ typedef struct
|
||||
char *tmpllibrary; /* path of shared library */
|
||||
} PLTemplate;
|
||||
|
||||
static void create_proc_lang(const char *languageName, bool replace,
|
||||
Oid languageOwner, Oid handlerOid, Oid inlineOid,
|
||||
Oid valOid, bool trusted);
|
||||
static Oid create_proc_lang(const char *languageName, bool replace,
|
||||
Oid languageOwner, Oid handlerOid, Oid inlineOid,
|
||||
Oid valOid, bool trusted);
|
||||
static PLTemplate *find_language_template(const char *languageName);
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* CREATE PROCEDURAL LANGUAGE
|
||||
* ---------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
{
|
||||
PLTemplate *pltemplate;
|
||||
@@ -225,9 +225,9 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
valOid = InvalidOid;
|
||||
|
||||
/* ok, create it */
|
||||
create_proc_lang(stmt->plname, stmt->replace, GetUserId(),
|
||||
handlerOid, inlineOid,
|
||||
valOid, pltemplate->tmpltrusted);
|
||||
return create_proc_lang(stmt->plname, stmt->replace, GetUserId(),
|
||||
handlerOid, inlineOid,
|
||||
valOid, pltemplate->tmpltrusted);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -300,16 +300,16 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
valOid = InvalidOid;
|
||||
|
||||
/* ok, create it */
|
||||
create_proc_lang(stmt->plname, stmt->replace, GetUserId(),
|
||||
handlerOid, inlineOid,
|
||||
valOid, stmt->pltrusted);
|
||||
return create_proc_lang(stmt->plname, stmt->replace, GetUserId(),
|
||||
handlerOid, inlineOid,
|
||||
valOid, stmt->pltrusted);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Guts of language creation.
|
||||
*/
|
||||
static void
|
||||
static Oid
|
||||
create_proc_lang(const char *languageName, bool replace,
|
||||
Oid languageOwner, Oid handlerOid, Oid inlineOid,
|
||||
Oid valOid, bool trusted)
|
||||
@@ -433,6 +433,8 @@ create_proc_lang(const char *languageName, bool replace,
|
||||
LanguageRelationId, myself.objectId, 0, NULL);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
|
||||
return myself.objectId;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -38,7 +38,7 @@ static List *label_provider_list = NIL;
|
||||
*
|
||||
* Apply a security label to a database object.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
ExecSecLabelStmt(SecLabelStmt *stmt)
|
||||
{
|
||||
LabelProvider *provider = NULL;
|
||||
@@ -131,6 +131,8 @@ ExecSecLabelStmt(SecLabelStmt *stmt)
|
||||
*/
|
||||
if (relation != NULL)
|
||||
relation_close(relation, NoLock);
|
||||
|
||||
return address.objectId;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -222,7 +222,7 @@ TablespaceCreateDbspace(Oid spcNode, Oid dbNode, bool isRedo)
|
||||
* since we're determining the system layout and, anyway, we probably have
|
||||
* root if we're doing this kind of activity
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
CreateTableSpace(CreateTableSpaceStmt *stmt)
|
||||
{
|
||||
#ifdef HAVE_SYMLINK
|
||||
@@ -371,6 +371,8 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("tablespaces are not supported on this platform")));
|
||||
#endif /* HAVE_SYMLINK */
|
||||
|
||||
return tablespaceoid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -890,13 +892,14 @@ RenameTableSpace(const char *oldname, const char *newname)
|
||||
/*
|
||||
* Alter table space options
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
|
||||
{
|
||||
Relation rel;
|
||||
ScanKeyData entry[1];
|
||||
HeapScanDesc scandesc;
|
||||
HeapTuple tup;
|
||||
Oid tablespaceoid;
|
||||
Datum datum;
|
||||
Datum newOptions;
|
||||
Datum repl_val[Natts_pg_tablespace];
|
||||
@@ -920,6 +923,8 @@ AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
|
||||
errmsg("tablespace \"%s\" does not exist",
|
||||
stmt->tablespacename)));
|
||||
|
||||
tablespaceoid = HeapTupleGetOid(tup);
|
||||
|
||||
/* Must be owner of the existing object */
|
||||
if (!pg_tablespace_ownercheck(HeapTupleGetOid(tup), GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TABLESPACE,
|
||||
@@ -952,6 +957,8 @@ AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
|
||||
/* Conclude heap scan. */
|
||||
heap_endscan(scandesc);
|
||||
heap_close(rel, NoLock);
|
||||
|
||||
return tablespaceoid;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -614,7 +614,7 @@ RemoveTSDictionaryById(Oid dictId)
|
||||
/*
|
||||
* ALTER TEXT SEARCH DICTIONARY
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterTSDictionary(AlterTSDictionaryStmt *stmt)
|
||||
{
|
||||
HeapTuple tup,
|
||||
@@ -722,6 +722,8 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
|
||||
ReleaseSysCache(tup);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
|
||||
return dictId;
|
||||
}
|
||||
|
||||
/* ---------------------- TS Template commands -----------------------*/
|
||||
@@ -1349,10 +1351,11 @@ RemoveTSConfigurationById(Oid cfgId)
|
||||
/*
|
||||
* ALTER TEXT SEARCH CONFIGURATION - main entry point
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
|
||||
{
|
||||
HeapTuple tup;
|
||||
Oid cfgId;
|
||||
Relation relMap;
|
||||
|
||||
/* Find the configuration */
|
||||
@@ -1363,6 +1366,8 @@ AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
|
||||
errmsg("text search configuration \"%s\" does not exist",
|
||||
NameListToString(stmt->cfgname))));
|
||||
|
||||
cfgId = HeapTupleGetOid(tup);
|
||||
|
||||
/* must be owner */
|
||||
if (!pg_ts_config_ownercheck(HeapTupleGetOid(tup), GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSCONFIGURATION,
|
||||
@@ -1382,6 +1387,8 @@ AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
|
||||
heap_close(relMap, RowExclusiveLock);
|
||||
|
||||
ReleaseSysCache(tup);
|
||||
|
||||
return cfgId;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -1053,7 +1053,7 @@ DefineDomain(CreateDomainStmt *stmt)
|
||||
* DefineEnum
|
||||
* Registers a new enum.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
DefineEnum(CreateEnumStmt *stmt)
|
||||
{
|
||||
char *enumName;
|
||||
@@ -1166,13 +1166,15 @@ DefineEnum(CreateEnumStmt *stmt)
|
||||
InvalidOid); /* type's collation */
|
||||
|
||||
pfree(enumArrayName);
|
||||
|
||||
return enumTypeOid;
|
||||
}
|
||||
|
||||
/*
|
||||
* AlterEnum
|
||||
* Adds a new label to an existing enum.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterEnum(AlterEnumStmt *stmt, bool isTopLevel)
|
||||
{
|
||||
Oid enum_type_oid;
|
||||
@@ -1215,6 +1217,8 @@ AlterEnum(AlterEnumStmt *stmt, bool isTopLevel)
|
||||
stmt->skipIfExists);
|
||||
|
||||
ReleaseSysCache(tup);
|
||||
|
||||
return enum_type_oid;
|
||||
}
|
||||
|
||||
|
||||
@@ -1246,7 +1250,7 @@ checkEnumOwner(HeapTuple tup)
|
||||
* DefineRange
|
||||
* Registers a new range type.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
DefineRange(CreateRangeStmt *stmt)
|
||||
{
|
||||
char *typeName;
|
||||
@@ -1498,6 +1502,8 @@ DefineRange(CreateRangeStmt *stmt)
|
||||
|
||||
/* And create the constructor functions for this range type */
|
||||
makeRangeConstructors(typeName, typeNamespace, typoid, rangeSubtype);
|
||||
|
||||
return typoid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2064,7 +2070,7 @@ DefineCompositeType(RangeVar *typevar, List *coldeflist)
|
||||
*
|
||||
* Routine implementing ALTER DOMAIN SET/DROP DEFAULT statements.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterDomainDefault(List *names, Node *defaultRaw)
|
||||
{
|
||||
TypeName *typename;
|
||||
@@ -2191,6 +2197,8 @@ AlterDomainDefault(List *names, Node *defaultRaw)
|
||||
/* Clean up */
|
||||
heap_close(rel, NoLock);
|
||||
heap_freetuple(newtuple);
|
||||
|
||||
return domainoid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2198,7 +2206,7 @@ AlterDomainDefault(List *names, Node *defaultRaw)
|
||||
*
|
||||
* Routine implementing ALTER DOMAIN SET/DROP NOT NULL statements.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterDomainNotNull(List *names, bool notNull)
|
||||
{
|
||||
TypeName *typename;
|
||||
@@ -2226,7 +2234,7 @@ AlterDomainNotNull(List *names, bool notNull)
|
||||
if (typTup->typnotnull == notNull)
|
||||
{
|
||||
heap_close(typrel, RowExclusiveLock);
|
||||
return;
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
/* Adding a NOT NULL constraint requires checking existing columns */
|
||||
@@ -2287,6 +2295,8 @@ AlterDomainNotNull(List *names, bool notNull)
|
||||
/* Clean up */
|
||||
heap_freetuple(tup);
|
||||
heap_close(typrel, RowExclusiveLock);
|
||||
|
||||
return domainoid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2294,7 +2304,7 @@ AlterDomainNotNull(List *names, bool notNull)
|
||||
*
|
||||
* Implements the ALTER DOMAIN DROP CONSTRAINT statement
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterDomainDropConstraint(List *names, const char *constrName,
|
||||
DropBehavior behavior, bool missing_ok)
|
||||
{
|
||||
@@ -2371,6 +2381,8 @@ AlterDomainDropConstraint(List *names, const char *constrName,
|
||||
(errmsg("constraint \"%s\" of domain \"%s\" does not exist, skipping",
|
||||
constrName, TypeNameToString(typename))));
|
||||
}
|
||||
|
||||
return domainoid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2378,7 +2390,7 @@ AlterDomainDropConstraint(List *names, const char *constrName,
|
||||
*
|
||||
* Implements the ALTER DOMAIN .. ADD CONSTRAINT statement.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterDomainAddConstraint(List *names, Node *newConstraint)
|
||||
{
|
||||
TypeName *typename;
|
||||
@@ -2474,6 +2486,8 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
|
||||
|
||||
/* Clean up */
|
||||
heap_close(typrel, RowExclusiveLock);
|
||||
|
||||
return domainoid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2481,7 +2495,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
|
||||
*
|
||||
* Implements the ALTER DOMAIN .. VALIDATE CONSTRAINT statement.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterDomainValidateConstraint(List *names, char *constrName)
|
||||
{
|
||||
TypeName *typename;
|
||||
@@ -2573,6 +2587,8 @@ AlterDomainValidateConstraint(List *names, char *constrName)
|
||||
heap_close(conrel, RowExclusiveLock);
|
||||
|
||||
ReleaseSysCache(tup);
|
||||
|
||||
return domainoid;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -67,7 +67,7 @@ have_createrole_privilege(void)
|
||||
/*
|
||||
* CREATE ROLE
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
CreateRole(CreateRoleStmt *stmt)
|
||||
{
|
||||
Relation pg_authid_rel;
|
||||
@@ -433,6 +433,8 @@ CreateRole(CreateRoleStmt *stmt)
|
||||
* Close pg_authid, but keep lock till commit.
|
||||
*/
|
||||
heap_close(pg_authid_rel, NoLock);
|
||||
|
||||
return roleid;
|
||||
}
|
||||
|
||||
|
||||
@@ -443,7 +445,7 @@ CreateRole(CreateRoleStmt *stmt)
|
||||
* backwards-compatible ALTER GROUP syntax. Although it will work to say
|
||||
* "ALTER ROLE role ROLE rolenames", we don't document it.
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterRole(AlterRoleStmt *stmt)
|
||||
{
|
||||
Datum new_record[Natts_pg_authid];
|
||||
@@ -799,17 +801,20 @@ AlterRole(AlterRoleStmt *stmt)
|
||||
* Close pg_authid, but keep lock till commit.
|
||||
*/
|
||||
heap_close(pg_authid_rel, NoLock);
|
||||
|
||||
return roleid;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ALTER ROLE ... SET
|
||||
*/
|
||||
void
|
||||
Oid
|
||||
AlterRoleSet(AlterRoleSetStmt *stmt)
|
||||
{
|
||||
HeapTuple roletuple;
|
||||
Oid databaseid = InvalidOid;
|
||||
Oid roleid;
|
||||
|
||||
roletuple = SearchSysCache1(AUTHNAME, PointerGetDatum(stmt->role));
|
||||
|
||||
@@ -818,6 +823,8 @@ AlterRoleSet(AlterRoleSetStmt *stmt)
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("role \"%s\" does not exist", stmt->role)));
|
||||
|
||||
roleid = HeapTupleGetOid(roletuple);
|
||||
|
||||
/*
|
||||
* Obtain a lock on the role and make sure it didn't go away in the
|
||||
* meantime.
|
||||
@@ -853,6 +860,8 @@ AlterRoleSet(AlterRoleSetStmt *stmt)
|
||||
|
||||
AlterSetting(databaseid, HeapTupleGetOid(roletuple), stmt->setstmt);
|
||||
ReleaseSysCache(roletuple);
|
||||
|
||||
return roleid;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user