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