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

Commit290428d

Browse files
committed
Fix for regproc so proc name can be supplied if unique, if not, oid.
1 parent820f9f8 commit290428d

File tree

2 files changed

+78
-39
lines changed

2 files changed

+78
-39
lines changed

‎src/backend/catalog/indexing.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.32 1998/09/23 04:21:59 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.33 1998/10/02 05:10:10 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -62,9 +62,9 @@ char *Name_pg_trigger_indices[Num_pg_trigger_indices] = {TriggerRelidIndex};
6262

6363

6464
staticHeapTupleCatalogIndexFetchTuple(RelationheapRelation,
65-
Relationidesc,
66-
ScanKeyskey,
67-
int16num_keys);
65+
Relationidesc,
66+
ScanKeyskey,
67+
int16num_keys);
6868

6969

7070
/*
@@ -213,6 +213,7 @@ CatalogHasIndex(char *catName, Oid catId)
213213
returnpgRelP->relhasindex;
214214
}
215215

216+
216217
/*
217218
*CatalogIndexFetchTuple() -- Get a tuple that satisfies a scan key
218219
*from a catalog relation.
@@ -253,6 +254,7 @@ CatalogIndexFetchTuple(Relation heapRelation,
253254
returntuple;
254255
}
255256

257+
256258
/*
257259
* The remainder of the file is for individual index scan routines. Each
258260
* index should be scanned according to how it was defined during bootstrap
@@ -288,6 +290,7 @@ AttributeNameIndexScan(Relation heapRelation,
288290
returntuple;
289291
}
290292

293+
291294
HeapTuple
292295
AttributeNumIndexScan(RelationheapRelation,
293296
Oidrelid,
@@ -317,6 +320,7 @@ AttributeNumIndexScan(Relation heapRelation,
317320
returntuple;
318321
}
319322

323+
320324
HeapTuple
321325
ProcedureOidIndexScan(RelationheapRelation,OidprocId)
322326
{
@@ -339,7 +343,6 @@ ProcedureOidIndexScan(Relation heapRelation, Oid procId)
339343
}
340344

341345

342-
343346
HeapTuple
344347
ProcedureNameIndexScan(RelationheapRelation,
345348
char*procName,
@@ -377,7 +380,6 @@ ProcedureNameIndexScan(Relation heapRelation,
377380
}
378381

379382

380-
381383
HeapTuple
382384
ProcedureSrcIndexScan(RelationheapRelation,text*procSrc)
383385
{
@@ -399,6 +401,7 @@ ProcedureSrcIndexScan(Relation heapRelation, text *procSrc)
399401
returntuple;
400402
}
401403

404+
402405
HeapTuple
403406
TypeOidIndexScan(RelationheapRelation,OidtypeId)
404407
{
@@ -420,6 +423,7 @@ TypeOidIndexScan(Relation heapRelation, Oid typeId)
420423
returntuple;
421424
}
422425

426+
423427
HeapTuple
424428
TypeNameIndexScan(RelationheapRelation,char*typeName)
425429
{
@@ -441,6 +445,7 @@ TypeNameIndexScan(Relation heapRelation, char *typeName)
441445
returntuple;
442446
}
443447

448+
444449
HeapTuple
445450
ClassNameIndexScan(RelationheapRelation,char*relName)
446451
{
@@ -461,6 +466,7 @@ ClassNameIndexScan(Relation heapRelation, char *relName)
461466
returntuple;
462467
}
463468

469+
464470
HeapTuple
465471
ClassOidIndexScan(RelationheapRelation,OidrelId)
466472
{

‎src/backend/utils/adt/regproc.c

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.30 1998/09/25 03:36:33 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.31 1998/10/02 05:10:11 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414
#include<string.h>
1515
#include"postgres.h"
1616
#include"miscadmin.h"
1717
#include"access/heapam.h"
18+
#include"access/genam.h"
19+
#include"access/itup.h"
1820
#include"access/relscan.h"
21+
#include"storage/bufmgr.h"
1922
#include"fmgr.h"
2023
#include"utils/palloc.h"
2124
#include"utils/syscache.h"
2225

2326
#include"catalog/catname.h"
27+
#include"catalog/indexing.h"
2428
#include"catalog/pg_proc.h"
2529
#include"catalog/pg_type.h"
2630
#include"utils/builtins.h"/* where function declarations go */
@@ -30,45 +34,81 @@
3034
*****************************************************************************/
3135

3236
/*
33-
*regprocin- converts "proname" to proid
37+
*regprocin- converts "proname"or "proid"to proid
3438
*
3539
*proid of NULL signifies unknown
3640
*/
3741
int32
38-
regprocin(char*pro_name_and_oid)
42+
regprocin(char*pro_name_or_oid)
3943
{
40-
HeapTupleproctup=NULL;
41-
RegProcedureresult= (Oid)0;
42-
43-
if (pro_name_and_oid==NULL)
44-
return0;
44+
HeapTupleproctup=NULL;
45+
RegProcedureresult=InvalidOid;
4546

47+
if (pro_name_or_oid==NULL)
48+
returnInvalidOid;
4649

4750
if (!IsBootstrapProcessingMode())
4851
{
49-
5052
/*
5153
* we need to use the oid because there can be multiple entries
5254
* with the same name.We accept int4eq_1323 and 1323.
5355
*/
54-
if (strrchr(pro_name_and_oid,'_')!=NULL)
56+
if (pro_name_or_oid[0] >='0'&&
57+
pro_name_or_oid[0] <='9')
5558
{
5659
proctup=SearchSysCacheTuple(PROOID,
57-
ObjectIdGetDatum(atoi(strrchr(pro_name_and_oid,'_')+1)),
60+
ObjectIdGetDatum(oidin(pro_name_or_oid)),
5861
0,0,0);
59-
62+
if (HeapTupleIsValid(proctup))
63+
result= (RegProcedure)proctup->t_oid;
64+
else
65+
elog(ERROR,"No such procedure with oid %s",pro_name_or_oid);
6066
}
61-
elseif (atoi(pro_name_and_oid)!=InvalidOid)
67+
else
6268
{
63-
proctup=SearchSysCacheTuple(PROOID,
64-
/* atoi stops at the _ */
65-
ObjectIdGetDatum(atoi(pro_name_and_oid)),
66-
0,0,0);
69+
Relationhdesc;
70+
Relationidesc;
71+
IndexScanDescsd;
72+
ScanKeyDataskey[1];
73+
RetrieveIndexResultindexRes;
74+
Bufferbuffer;
75+
intmatches=0;
76+
77+
ScanKeyEntryInitialize(&skey[0],
78+
(bits16)0x0,
79+
(AttrNumber)1,
80+
(RegProcedure)F_NAMEEQ,
81+
PointerGetDatum(pro_name_or_oid));
82+
83+
hdesc=heap_openr(ProcedureRelationName);
84+
idesc=index_openr(ProcedureNameIndex);
85+
86+
sd=index_beginscan(idesc, false,1,skey);
87+
while ((indexRes=index_getnext(sd,ForwardScanDirection)))
88+
{
89+
proctup=heap_fetch(hdesc,SnapshotNow,
90+
&indexRes->heap_iptr,
91+
&buffer);
92+
pfree(indexRes);
93+
if (HeapTupleIsValid(proctup))
94+
{
95+
result= (RegProcedure)proctup->t_oid;
96+
ReleaseBuffer(buffer);
97+
98+
if (++matches>1)
99+
break;
100+
}
101+
}
102+
103+
index_endscan(sd);
104+
pfree(sd);
105+
index_close(idesc);
106+
107+
if (matches>1)
108+
elog(ERROR,"There is more than one %s procedure, supply oid in quotes.",pro_name_or_oid);
109+
elseif (matches==0)
110+
elog(ERROR,"No such procedure %s",pro_name_or_oid);
67111
}
68-
if (HeapTupleIsValid(proctup))
69-
result= (RegProcedure)proctup->t_oid;
70-
else
71-
elog(ERROR,"regprocin: no such procedure %s",pro_name_and_oid);
72112
}
73113
else
74114
{
@@ -88,7 +128,7 @@ regprocin(char *pro_name_and_oid)
88128
(bits16)0,
89129
(AttrNumber)1,
90130
(RegProcedure)F_NAMEEQ,
91-
(Datum)pro_name_and_oid);
131+
(Datum)pro_name_or_oid);
92132

93133
procscan=heap_beginscan(proc,0,SnapshotNow,1,&key);
94134
if (!HeapScanIsValid(procscan))
@@ -106,7 +146,7 @@ regprocin(char *pro_name_and_oid)
106146
RelationGetDescr(proc),
107147
&isnull);
108148
if (isnull)
109-
elog(FATAL,"regprocin: null procedure %s",pro_name_and_oid);
149+
elog(FATAL,"regprocin: null procedure %s",pro_name_or_oid);
110150
}
111151
else
112152
result= (RegProcedure)0;
@@ -115,14 +155,11 @@ regprocin(char *pro_name_and_oid)
115155
heap_close(proc);
116156
}
117157

118-
#ifdefEBUG
119-
elog(DEBUG,"regprocin: no such procedure %s",pro_name_and_oid);
120-
#endif/* defined(EBUG) */
121158
return (int32)result;
122159
}
123160

124161
/*
125-
*regprocout- converts proid to "pro_name_and_oid"
162+
*regprocout- converts proid to "pro_name"
126163
*/
127164
char*
128165
regprocout(RegProcedureproid)
@@ -143,7 +180,7 @@ regprocout(RegProcedure proid)
143180
char*s;
144181

145182
s= ((Form_pg_proc)GETSTRUCT(proctup))->proname.data;
146-
snprintf(result,NAMEDATALEN,"%s_%d",s,proid);
183+
StrNCpy(result,s,NAMEDATALEN);
147184
}
148185
else
149186
{
@@ -160,8 +197,7 @@ regprocout(RegProcedure proid)
160197
proc=heap_openr(ProcedureRelationName);
161198
if (!RelationIsValid(proc))
162199
{
163-
elog(ERROR,"regprocout: could not open %s",
164-
ProcedureRelationName);
200+
elog(ERROR,"regprocout: could not open %s",ProcedureRelationName);
165201
return0;
166202
}
167203
ScanKeyEntryInitialize(&key,
@@ -201,9 +237,6 @@ regprocout(RegProcedure proid)
201237
returnresult;
202238
}
203239

204-
#ifdefEBUG
205-
elog(DEBUG,"regprocout: no such procedure %d",proid);
206-
#endif/* defined(EBUG) */
207240
returnresult;
208241
}
209242

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp