foreach(l, fkoidlist)
{
- int i;
- ArrayType *arr;
+ Oid fkoid = lfirst_oid(l);
+ HeapTuple htup;
+ Form_pg_constraint constraint;
+ ForeignKeyOptInfo *info;
Datum adatum;
bool isnull;
+ ArrayType *arr;
int numkeys;
- Oid fkoid = lfirst_oid(l);
-
- HeapTuple htup = SearchSysCache1(CONSTROID, ObjectIdGetDatum(fkoid));
- Form_pg_constraint constraint = (Form_pg_constraint) GETSTRUCT(htup);
+ int i;
- ForeignKeyOptInfo *info;
+ htup = SearchSysCache1(CONSTROID, ObjectIdGetDatum(fkoid));
+ if (!HeapTupleIsValid(htup)) /* should not happen */
+ elog(ERROR, "cache lookup failed for constraint %u", fkoid);
+ constraint = (Form_pg_constraint) GETSTRUCT(htup);
Assert(constraint->contype == CONSTRAINT_FOREIGN);
arr = DatumGetArrayTypeP(adatum);
numkeys = ARR_DIMS(arr)[0];
- info->conkeys = (int*)palloc0(numkeys * sizeof(int));
-
+ info->conkeys = (int*)palloc(numkeys * sizeof(int));
for (i = 0; i < numkeys; i++)
info->conkeys[i] = ((int16 *) ARR_DATA_PTR(arr))[i];
Assert(!isnull);
arr = DatumGetArrayTypeP(adatum);
- numkeys = ARR_DIMS(arr)[0];
- info->confkeys = (int*)palloc0(numkeys * sizeof(int));
-
+ Assert(numkeys == ARR_DIMS(arr)[0]);
+ info->confkeys = (int*)palloc(numkeys * sizeof(int));
for (i = 0; i < numkeys; i++)
info->confkeys[i] = ((int16 *) ARR_DATA_PTR(arr))[i];
Assert(!isnull);
arr = DatumGetArrayTypeP(adatum);
- numkeys = ARR_DIMS(arr)[0];
- info->conpfeqop = (Oid*)palloc0(numkeys * sizeof(Oid));
-
+ Assert(numkeys == ARR_DIMS(arr)[0]);
+ info->conpfeqop = (Oid*)palloc(numkeys * sizeof(Oid));
for (i = 0; i < numkeys; i++)
info->conpfeqop[i] = ((Oid *) ARR_DATA_PTR(arr))[i];
ReleaseSysCache(htup);
- fkinfos = lcons(info, fkinfos);
+ fkinfos = lappend(fkinfos, info);
}
list_free(fkoidlist);