Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit82b1b21

Browse files
committed
Adjust more backend functions to return OID rather than void.
This is again intended to support extensions to the event triggerfunctionality. This may go a bit further than we need for thatpurpose, but there's some value in being consistent, and the OIDmay be useful for other purposes also.Dimitri Fontaine
1 parent5ab3af4 commit82b1b21

29 files changed

+231
-131
lines changed

‎src/backend/commands/comment.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* This routine is used to add the associated comment into
3737
* pg_description for the object specified by the given SQL command.
3838
*/
39-
void
39+
Oid
4040
CommentObject(CommentStmt*stmt)
4141
{
4242
ObjectAddressaddress;
@@ -60,7 +60,7 @@ CommentObject(CommentStmt *stmt)
6060
ereport(WARNING,
6161
(errcode(ERRCODE_UNDEFINED_DATABASE),
6262
errmsg("database \"%s\" does not exist",database)));
63-
return;
63+
returnInvalidOid;
6464
}
6565
}
6666

@@ -123,6 +123,8 @@ CommentObject(CommentStmt *stmt)
123123
*/
124124
if (relation!=NULL)
125125
relation_close(relation,NoLock);
126+
127+
returnaddress.objectId;
126128
}
127129

128130
/*

‎src/backend/commands/copy.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -743,14 +743,14 @@ CopyLoadRawBuf(CopyState cstate)
743743
* Do not allow the copy if user doesn't have proper permission to access
744744
* the table or the specifically requested columns.
745745
*/
746-
uint64
747-
DoCopy(constCopyStmt*stmt,constchar*queryString)
746+
Oid
747+
DoCopy(constCopyStmt*stmt,constchar*queryString,uint64*processed)
748748
{
749749
CopyStatecstate;
750750
boolis_from=stmt->is_from;
751751
boolpipe= (stmt->filename==NULL);
752752
Relationrel;
753-
uint64processed;
753+
Oidrelid;
754754

755755
/* Disallow file COPY except to superusers. */
756756
if (!pipe&& !superuser())
@@ -774,6 +774,8 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
774774
rel=heap_openrv(stmt->relation,
775775
(is_from ?RowExclusiveLock :AccessShareLock));
776776

777+
relid=RelationGetRelid(rel);
778+
777779
rte=makeNode(RangeTblEntry);
778780
rte->rtekind=RTE_RELATION;
779781
rte->relid=RelationGetRelid(rel);
@@ -811,14 +813,14 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
811813

812814
cstate=BeginCopyFrom(rel,stmt->filename,
813815
stmt->attlist,stmt->options);
814-
processed=CopyFrom(cstate);/* copy from file to database */
816+
*processed=CopyFrom(cstate);/* copy from file to database */
815817
EndCopyFrom(cstate);
816818
}
817819
else
818820
{
819821
cstate=BeginCopyTo(rel,stmt->query,queryString,stmt->filename,
820822
stmt->attlist,stmt->options);
821-
processed=DoCopyTo(cstate);/* copy from database to file */
823+
*processed=DoCopyTo(cstate);/* copy from database to file */
822824
EndCopyTo(cstate);
823825
}
824826

@@ -830,7 +832,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
830832
if (rel!=NULL)
831833
heap_close(rel, (is_from ?NoLock :AccessShareLock));
832834

833-
returnprocessed;
835+
returnrelid;
834836
}
835837

836838
/*

‎src/backend/commands/dbcommands.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static interrdetail_busy_db(int notherbackends, int npreparedxacts);
9090
/*
9191
* CREATE DATABASE
9292
*/
93-
void
93+
Oid
9494
createdb(constCreatedbStmt*stmt)
9595
{
9696
HeapScanDescscan;
@@ -655,6 +655,8 @@ createdb(const CreatedbStmt *stmt)
655655
}
656656
PG_END_ENSURE_ERROR_CLEANUP(createdb_failure_callback,
657657
PointerGetDatum(&fparms));
658+
659+
returndboid;
658660
}
659661

660662
/*
@@ -1301,10 +1303,11 @@ movedb_failure_callback(int code, Datum arg)
13011303
/*
13021304
* ALTER DATABASE name ...
13031305
*/
1304-
void
1306+
Oid
13051307
AlterDatabase(AlterDatabaseStmt*stmt,boolisTopLevel)
13061308
{
13071309
Relationrel;
1310+
Oiddboid;
13081311
HeapTupletuple,
13091312
newtuple;
13101313
ScanKeyDatascankey;
@@ -1350,7 +1353,7 @@ AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
13501353
/* this case isn't allowed within a transaction block */
13511354
PreventTransactionChain(isTopLevel,"ALTER DATABASE SET TABLESPACE");
13521355
movedb(stmt->dbname,strVal(dtablespace->arg));
1353-
return;
1356+
returnInvalidOid;
13541357
}
13551358

13561359
if (dconnlimit)
@@ -1380,6 +1383,8 @@ AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
13801383
(errcode(ERRCODE_UNDEFINED_DATABASE),
13811384
errmsg("database \"%s\" does not exist",stmt->dbname)));
13821385

1386+
dboid=HeapTupleGetOid(tuple);
1387+
13831388
if (!pg_database_ownercheck(HeapTupleGetOid(tuple),GetUserId()))
13841389
aclcheck_error(ACLCHECK_NOT_OWNER,ACL_KIND_DATABASE,
13851390
stmt->dbname);
@@ -1408,13 +1413,15 @@ AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
14081413

14091414
/* Close pg_database, but keep lock till commit */
14101415
heap_close(rel,NoLock);
1416+
1417+
returndboid;
14111418
}
14121419

14131420

14141421
/*
14151422
* ALTER DATABASE name SET ...
14161423
*/
1417-
void
1424+
Oid
14181425
AlterDatabaseSet(AlterDatabaseSetStmt*stmt)
14191426
{
14201427
Oiddatid=get_database_oid(stmt->dbname, false);
@@ -1432,6 +1439,8 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
14321439
AlterSetting(datid,InvalidOid,stmt->setstmt);
14331440

14341441
UnlockSharedObject(DatabaseRelationId,datid,0,AccessShareLock);
1442+
1443+
returndatid;
14351444
}
14361445

14371446

‎src/backend/commands/event_trigger.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ static void AlterEventTriggerOwner_internal(Relation rel,
9494
staticevent_trigger_command_tag_check_resultcheck_ddl_tag(constchar*tag);
9595
staticvoiderror_duplicate_filter_variable(constchar*defname);
9696
staticDatumfilter_list_to_array(List*filterlist);
97-
staticvoidinsert_event_trigger_tuple(char*trigname,char*eventname,
98-
OidevtOwner,Oidfuncoid,List*tags);
97+
staticOidinsert_event_trigger_tuple(char*trigname,char*eventname,
98+
OidevtOwner,Oidfuncoid,List*tags);
9999
staticvoidvalidate_ddl_tags(constchar*filtervar,List*taglist);
100100
staticvoidEventTriggerInvoke(List*fn_oid_list,EventTriggerData*trigdata);
101101

102102
/*
103103
* Create an event trigger.
104104
*/
105-
void
105+
Oid
106106
CreateEventTrigger(CreateEventTrigStmt*stmt)
107107
{
108108
HeapTupletuple;
@@ -173,8 +173,8 @@ CreateEventTrigger(CreateEventTrigStmt *stmt)
173173
NameListToString(stmt->funcname))));
174174

175175
/* Insert catalog entries. */
176-
insert_event_trigger_tuple(stmt->trigname,stmt->eventname,
177-
evtowner,funcoid,tags);
176+
returninsert_event_trigger_tuple(stmt->trigname,stmt->eventname,
177+
evtowner,funcoid,tags);
178178
}
179179

180180
/*
@@ -260,7 +260,7 @@ error_duplicate_filter_variable(const char *defname)
260260
/*
261261
* Insert the new pg_event_trigger row and record dependencies.
262262
*/
263-
staticvoid
263+
staticOid
264264
insert_event_trigger_tuple(char*trigname,char*eventname,OidevtOwner,
265265
Oidfuncoid,List*taglist)
266266
{
@@ -312,6 +312,8 @@ insert_event_trigger_tuple(char *trigname, char *eventname, Oid evtOwner,
312312

313313
/* Close pg_event_trigger. */
314314
heap_close(tgrel,RowExclusiveLock);
315+
316+
returntrigoid;
315317
}
316318

317319
/*
@@ -376,11 +378,12 @@ RemoveEventTriggerById(Oid trigOid)
376378
/*
377379
* ALTER EVENT TRIGGER foo ENABLE|DISABLE|ENABLE ALWAYS|REPLICA
378380
*/
379-
void
381+
Oid
380382
AlterEventTrigger(AlterEventTrigStmt*stmt)
381383
{
382384
Relationtgrel;
383385
HeapTupletup;
386+
Oidtrigoid;
384387
Form_pg_event_triggerevtForm;
385388
chartgenabled=stmt->tgenabled;
386389

@@ -393,7 +396,10 @@ AlterEventTrigger(AlterEventTrigStmt *stmt)
393396
(errcode(ERRCODE_UNDEFINED_OBJECT),
394397
errmsg("event trigger \"%s\" does not exist",
395398
stmt->trigname)));
396-
if (!pg_event_trigger_ownercheck(HeapTupleGetOid(tup),GetUserId()))
399+
400+
trigoid=HeapTupleGetOid(tup);
401+
402+
if (!pg_event_trigger_ownercheck(trigoid,GetUserId()))
397403
aclcheck_error(ACLCHECK_NOT_OWNER,ACL_KIND_EVENT_TRIGGER,
398404
stmt->trigname);
399405

@@ -407,6 +413,8 @@ AlterEventTrigger(AlterEventTrigStmt *stmt)
407413
/* clean up */
408414
heap_freetuple(tup);
409415
heap_close(tgrel,RowExclusiveLock);
416+
417+
returntrigoid;
410418
}
411419

412420

‎src/backend/commands/extension.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,7 @@ AlterExtensionNamespace(List *names, const char *newschema)
25802580
/*
25812581
* Execute ALTER EXTENSION UPDATE
25822582
*/
2583-
void
2583+
Oid
25842584
ExecAlterExtensionStmt(AlterExtensionStmt*stmt)
25852585
{
25862586
DefElem*d_new_version=NULL;
@@ -2697,7 +2697,7 @@ ExecAlterExtensionStmt(AlterExtensionStmt *stmt)
26972697
ereport(NOTICE,
26982698
(errmsg("version \"%s\" of extension \"%s\" is already installed",
26992699
versionName,stmt->extname)));
2700-
return;
2700+
returnInvalidOid;
27012701
}
27022702

27032703
/*
@@ -2713,6 +2713,8 @@ ExecAlterExtensionStmt(AlterExtensionStmt *stmt)
27132713
*/
27142714
ApplyExtensionUpdates(extensionOid,control,
27152715
oldVersionName,updateVersions);
2716+
2717+
returnextensionOid;
27162718
}
27172719

27182720
/*
@@ -2875,7 +2877,7 @@ ApplyExtensionUpdates(Oid extensionOid,
28752877
/*
28762878
* Execute ALTER EXTENSION ADD/DROP
28772879
*/
2878-
void
2880+
Oid
28792881
ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt*stmt)
28802882
{
28812883
ObjectAddressextension;
@@ -2976,4 +2978,6 @@ ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt)
29762978
*/
29772979
if (relation!=NULL)
29782980
relation_close(relation,NoLock);
2981+
2982+
returnextension.objectId;
29792983
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp