@@ -238,7 +238,6 @@ RI_FKey_check(TriggerData *trigdata)
238238 TupleTableSlot * newslot ;
239239 RI_QueryKey qkey ;
240240 SPIPlanPtr qplan ;
241- int i ;
242241
243242 riinfo = ri_FetchConstraintInfo (trigdata -> tg_trigger ,
244243 trigdata -> tg_relation , false);
@@ -379,7 +378,7 @@ RI_FKey_check(TriggerData *trigdata)
379378 quoteRelationName (pkrelname , pk_rel );
380379 appendStringInfo (& querybuf , "SELECT 1 FROM ONLY %s x" , pkrelname );
381380 querysep = "WHERE" ;
382- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
381+ for (int i = 0 ; i < riinfo -> nkeys ; i ++ )
383382 {
384383 Oid pk_type = RIAttType (pk_rel , riinfo -> pk_attnums [i ]);
385384 Oid fk_type = RIAttType (fk_rel , riinfo -> fk_attnums [i ]);
@@ -468,7 +467,6 @@ ri_Check_Pk_Match(Relation pk_rel, Relation fk_rel,
468467{
469468 SPIPlanPtr qplan ;
470469 RI_QueryKey qkey ;
471- int i ;
472470 bool result ;
473471
474472 /* Only called for non-null rows */
@@ -504,7 +502,7 @@ ri_Check_Pk_Match(Relation pk_rel, Relation fk_rel,
504502 quoteRelationName (pkrelname , pk_rel );
505503 appendStringInfo (& querybuf , "SELECT 1 FROM ONLY %s x" , pkrelname );
506504 querysep = "WHERE" ;
507- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
505+ for (int i = 0 ; i < riinfo -> nkeys ; i ++ )
508506 {
509507 Oid pk_type = RIAttType (pk_rel , riinfo -> pk_attnums [i ]);
510508
@@ -675,7 +673,6 @@ ri_restrict(TriggerData *trigdata, bool is_no_action)
675673 const char * querysep ;
676674 Oid queryoids [RI_MAX_NUMKEYS ];
677675 const char * fk_only ;
678- int i ;
679676
680677 /* ----------
681678 * The query string built is
@@ -692,7 +689,7 @@ ri_restrict(TriggerData *trigdata, bool is_no_action)
692689 appendStringInfo (& querybuf , "SELECT 1 FROM %s%s x" ,
693690 fk_only , fkrelname );
694691 querysep = "WHERE" ;
695- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
692+ for (int i = 0 ; i < riinfo -> nkeys ; i ++ )
696693 {
697694 Oid pk_type = RIAttType (pk_rel , riinfo -> pk_attnums [i ]);
698695 Oid fk_type = RIAttType (fk_rel , riinfo -> fk_attnums [i ]);
@@ -747,7 +744,6 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
747744 TupleTableSlot * old_slot ;
748745 RI_QueryKey qkey ;
749746 SPIPlanPtr qplan ;
750- int i ;
751747
752748 /* Check that this is a valid trigger call on the right time and event. */
753749 ri_CheckTrigger (fcinfo , "RI_FKey_cascade_del" , RI_TRIGTYPE_DELETE );
@@ -795,7 +791,7 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
795791 appendStringInfo (& querybuf , "DELETE FROM %s%s" ,
796792 fk_only , fkrelname );
797793 querysep = "WHERE" ;
798- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
794+ for (int i = 0 ; i < riinfo -> nkeys ; i ++ )
799795 {
800796 Oid pk_type = RIAttType (pk_rel , riinfo -> pk_attnums [i ]);
801797 Oid fk_type = RIAttType (fk_rel , riinfo -> fk_attnums [i ]);
@@ -851,8 +847,6 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
851847 TupleTableSlot * old_slot ;
852848 RI_QueryKey qkey ;
853849 SPIPlanPtr qplan ;
854- int i ;
855- int j ;
856850
857851 /* Check that this is a valid trigger call on the right time and event. */
858852 ri_CheckTrigger (fcinfo , "RI_FKey_cascade_upd" , RI_TRIGTYPE_UPDATE );
@@ -909,7 +903,7 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
909903 fk_only , fkrelname );
910904 querysep = "" ;
911905 qualsep = "WHERE" ;
912- for (i = 0 , j = riinfo -> nkeys ; i < riinfo -> nkeys ; i ++ , j ++ )
906+ for (int i = 0 , j = riinfo -> nkeys ; i < riinfo -> nkeys ; i ++ , j ++ )
913907 {
914908 Oid pk_type = RIAttType (pk_rel , riinfo -> pk_attnums [i ]);
915909 Oid fk_type = RIAttType (fk_rel , riinfo -> fk_attnums [i ]);
@@ -998,7 +992,6 @@ ri_setnull(TriggerData *trigdata)
998992 TupleTableSlot * old_slot ;
999993 RI_QueryKey qkey ;
1000994 SPIPlanPtr qplan ;
1001- int i ;
1002995
1003996 riinfo = ri_FetchConstraintInfo (trigdata -> tg_trigger ,
1004997 trigdata -> tg_relation , true);
@@ -1051,7 +1044,7 @@ ri_setnull(TriggerData *trigdata)
10511044 fk_only , fkrelname );
10521045 querysep = "" ;
10531046 qualsep = "WHERE" ;
1054- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
1047+ for (int i = 0 ; i < riinfo -> nkeys ; i ++ )
10551048 {
10561049 Oid pk_type = RIAttType (pk_rel , riinfo -> pk_attnums [i ]);
10571050 Oid fk_type = RIAttType (fk_rel , riinfo -> fk_attnums [i ]);
@@ -1173,7 +1166,6 @@ ri_setdefault(TriggerData *trigdata)
11731166 const char * qualsep ;
11741167 Oid queryoids [RI_MAX_NUMKEYS ];
11751168 const char * fk_only ;
1176- int i ;
11771169
11781170 /* ----------
11791171 * The query string built is
@@ -1192,7 +1184,7 @@ ri_setdefault(TriggerData *trigdata)
11921184 fk_only , fkrelname );
11931185 querysep = "" ;
11941186 qualsep = "WHERE" ;
1195- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
1187+ for (int i = 0 ; i < riinfo -> nkeys ; i ++ )
11961188 {
11971189 Oid pk_type = RIAttType (pk_rel , riinfo -> pk_attnums [i ]);
11981190 Oid fk_type = RIAttType (fk_rel , riinfo -> fk_attnums [i ]);
@@ -1402,7 +1394,6 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
14021394 RangeTblEntry * fkrte ;
14031395 const char * sep ;
14041396 const char * fk_only ;
1405- int i ;
14061397 int save_nestlevel ;
14071398 char workmembuf [32 ];
14081399 int spi_result ;
@@ -1431,7 +1422,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
14311422 fkrte -> rellockmode = AccessShareLock ;
14321423 fkrte -> requiredPerms = ACL_SELECT ;
14331424
1434- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
1425+ for (int i = 0 ; i < riinfo -> nkeys ; i ++ )
14351426 {
14361427 int attno ;
14371428
@@ -1475,7 +1466,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
14751466 initStringInfo (& querybuf );
14761467 appendStringInfoString (& querybuf , "SELECT " );
14771468 sep = "" ;
1478- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
1469+ for (int i = 0 ; i < riinfo -> nkeys ; i ++ )
14791470 {
14801471 quoteOneName (fkattname ,
14811472 RIAttName (fk_rel , riinfo -> fk_attnums [i ]));
@@ -1494,7 +1485,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
14941485 strcpy (pkattname , "pk." );
14951486 strcpy (fkattname , "fk." );
14961487 sep = "(" ;
1497- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
1488+ for (int i = 0 ; i < riinfo -> nkeys ; i ++ )
14981489 {
14991490 Oid pk_type = RIAttType (pk_rel , riinfo -> pk_attnums [i ]);
15001491 Oid fk_type = RIAttType (fk_rel , riinfo -> fk_attnums [i ]);
@@ -1522,7 +1513,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
15221513 appendStringInfo (& querybuf , ") WHERE pk.%s IS NULL AND (" , pkattname );
15231514
15241515 sep = "" ;
1525- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
1516+ for (int i = 0 ; i < riinfo -> nkeys ; i ++ )
15261517 {
15271518 quoteOneName (fkattname , RIAttName (fk_rel , riinfo -> fk_attnums [i ]));
15281519 appendStringInfo (& querybuf ,
@@ -1613,7 +1604,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
16131604 * or fk_rel's tupdesc.
16141605 */
16151606 memcpy (& fake_riinfo , riinfo , sizeof (RI_ConstraintInfo ));
1616- for (i = 0 ; i < fake_riinfo .nkeys ; i ++ )
1607+ for (int i = 0 ; i < fake_riinfo .nkeys ; i ++ )
16171608 fake_riinfo .fk_attnums [i ] = i + 1 ;
16181609
16191610 /*
@@ -2195,15 +2186,14 @@ ri_ExtractValues(Relation rel, TupleTableSlot *slot,
21952186 Datum * vals , char * nulls )
21962187{
21972188 const int16 * attnums ;
2198- int i ;
21992189 bool isnull ;
22002190
22012191 if (rel_is_pk )
22022192 attnums = riinfo -> pk_attnums ;
22032193 else
22042194 attnums = riinfo -> fk_attnums ;
22052195
2206- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
2196+ for (int i = 0 ; i < riinfo -> nkeys ; i ++ )
22072197 {
22082198 vals [i ] = slot_getattr (slot , attnums [i ], & isnull );
22092199 nulls [i ] = isnull ? 'n' : ' ' ;
@@ -2229,7 +2219,6 @@ ri_ReportViolation(const RI_ConstraintInfo *riinfo,
22292219 StringInfoData key_values ;
22302220 bool onfk ;
22312221 const int16 * attnums ;
2232- int idx ;
22332222 Oid rel_oid ;
22342223 AclResult aclresult ;
22352224 bool has_perm = true;
@@ -2271,7 +2260,7 @@ ri_ReportViolation(const RI_ConstraintInfo *riinfo,
22712260 if (aclresult != ACLCHECK_OK )
22722261 {
22732262 /* Try for column-level permissions */
2274- for (idx = 0 ; idx < riinfo -> nkeys ; idx ++ )
2263+ for (int idx = 0 ; idx < riinfo -> nkeys ; idx ++ )
22752264 {
22762265 aclresult = pg_attribute_aclcheck (rel_oid , attnums [idx ],
22772266 GetUserId (),
@@ -2294,7 +2283,7 @@ ri_ReportViolation(const RI_ConstraintInfo *riinfo,
22942283 /* Get printable versions of the keys involved */
22952284 initStringInfo (& key_names );
22962285 initStringInfo (& key_values );
2297- for (idx = 0 ; idx < riinfo -> nkeys ; idx ++ )
2286+ for (int idx = 0 ; idx < riinfo -> nkeys ; idx ++ )
22982287 {
22992288 int fnum = attnums [idx ];
23002289 Form_pg_attribute att = TupleDescAttr (tupdesc , fnum - 1 );
@@ -2370,7 +2359,6 @@ ri_NullCheck(TupleDesc tupDesc,
23702359 const RI_ConstraintInfo * riinfo , bool rel_is_pk )
23712360{
23722361 const int16 * attnums ;
2373- int i ;
23742362 bool allnull = true;
23752363 bool nonenull = true;
23762364
@@ -2379,7 +2367,7 @@ ri_NullCheck(TupleDesc tupDesc,
23792367 else
23802368 attnums = riinfo -> fk_attnums ;
23812369
2382- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
2370+ for (int i = 0 ; i < riinfo -> nkeys ; i ++ )
23832371 {
23842372 if (slot_attisnull (slot , attnums [i ]))
23852373 nonenull = false;
@@ -2533,7 +2521,6 @@ ri_KeysEqual(Relation rel, TupleTableSlot *oldslot, TupleTableSlot *newslot,
25332521{
25342522 const int16 * attnums ;
25352523 const Oid * eq_oprs ;
2536- int i ;
25372524
25382525 if (rel_is_pk )
25392526 {
@@ -2547,7 +2534,7 @@ ri_KeysEqual(Relation rel, TupleTableSlot *oldslot, TupleTableSlot *newslot,
25472534 }
25482535
25492536 /* XXX: could be worthwhile to fetch all necessary attrs at once */
2550- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
2537+ for (int i = 0 ; i < riinfo -> nkeys ; i ++ )
25512538 {
25522539 Datum oldvalue ;
25532540 Datum newvalue ;
0 commit comments