mirror of
https://github.com/postgres/postgres.git
synced 2025-12-13 14:22:43 +03:00
Change tupledesc->attrs[n] to TupleDescAttr(tupledesc, n).
This is a mechanical change in preparation for a later commit that will change the layout of TupleDesc. Introducing a macro to abstract the details of where attributes are stored will allow us to change that in separate step and revise it in future. Author: Thomas Munro, editorialized by Andres Freund Reviewed-By: Andres Freund Discussion: https://postgr.es/m/CAEepm=0ZtQ-SpsgCyzzYpsXS6e=kZWqk3g5Ygn3MDV7A8dabUA@mail.gmail.com
This commit is contained in:
@@ -950,6 +950,7 @@ PLy_modify_tuple(PLyProcedure *proc, PyObject *pltd, TriggerData *tdata,
|
||||
char *plattstr;
|
||||
int attn;
|
||||
PLyObToDatum *att;
|
||||
Form_pg_attribute attr;
|
||||
|
||||
platt = PyList_GetItem(plkeys, i);
|
||||
if (PyString_Check(platt))
|
||||
@@ -982,11 +983,12 @@ PLy_modify_tuple(PLyProcedure *proc, PyObject *pltd, TriggerData *tdata,
|
||||
|
||||
Py_INCREF(plval);
|
||||
|
||||
attr = TupleDescAttr(tupdesc, attn - 1);
|
||||
if (plval != Py_None)
|
||||
{
|
||||
modvalues[attn - 1] =
|
||||
(att->func) (att,
|
||||
tupdesc->attrs[attn - 1]->atttypmod,
|
||||
attr->atttypmod,
|
||||
plval,
|
||||
false);
|
||||
modnulls[attn - 1] = false;
|
||||
@@ -997,7 +999,7 @@ PLy_modify_tuple(PLyProcedure *proc, PyObject *pltd, TriggerData *tdata,
|
||||
InputFunctionCall(&att->typfunc,
|
||||
NULL,
|
||||
att->typioparam,
|
||||
tupdesc->attrs[attn - 1]->atttypmod);
|
||||
attr->atttypmod);
|
||||
modnulls[attn - 1] = true;
|
||||
}
|
||||
modrepls[attn - 1] = true;
|
||||
|
||||
@@ -148,7 +148,11 @@ PLy_result_colnames(PyObject *self, PyObject *unused)
|
||||
|
||||
list = PyList_New(ob->tupdesc->natts);
|
||||
for (i = 0; i < ob->tupdesc->natts; i++)
|
||||
PyList_SET_ITEM(list, i, PyString_FromString(NameStr(ob->tupdesc->attrs[i]->attname)));
|
||||
{
|
||||
Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
|
||||
|
||||
PyList_SET_ITEM(list, i, PyString_FromString(NameStr(attr->attname)));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -168,7 +172,11 @@ PLy_result_coltypes(PyObject *self, PyObject *unused)
|
||||
|
||||
list = PyList_New(ob->tupdesc->natts);
|
||||
for (i = 0; i < ob->tupdesc->natts; i++)
|
||||
PyList_SET_ITEM(list, i, PyInt_FromLong(ob->tupdesc->attrs[i]->atttypid));
|
||||
{
|
||||
Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
|
||||
|
||||
PyList_SET_ITEM(list, i, PyInt_FromLong(attr->atttypid));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -188,7 +196,11 @@ PLy_result_coltypmods(PyObject *self, PyObject *unused)
|
||||
|
||||
list = PyList_New(ob->tupdesc->natts);
|
||||
for (i = 0; i < ob->tupdesc->natts; i++)
|
||||
PyList_SET_ITEM(list, i, PyInt_FromLong(ob->tupdesc->attrs[i]->atttypmod));
|
||||
{
|
||||
Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
|
||||
|
||||
PyList_SET_ITEM(list, i, PyInt_FromLong(attr->atttypmod));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -152,21 +152,21 @@ PLy_input_tuple_funcs(PLyTypeInfo *arg, TupleDesc desc)
|
||||
for (i = 0; i < desc->natts; i++)
|
||||
{
|
||||
HeapTuple typeTup;
|
||||
Form_pg_attribute attr = TupleDescAttr(desc, i);
|
||||
|
||||
if (desc->attrs[i]->attisdropped)
|
||||
if (attr->attisdropped)
|
||||
continue;
|
||||
|
||||
if (arg->in.r.atts[i].typoid == desc->attrs[i]->atttypid)
|
||||
if (arg->in.r.atts[i].typoid == attr->atttypid)
|
||||
continue; /* already set up this entry */
|
||||
|
||||
typeTup = SearchSysCache1(TYPEOID,
|
||||
ObjectIdGetDatum(desc->attrs[i]->atttypid));
|
||||
typeTup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(attr->atttypid));
|
||||
if (!HeapTupleIsValid(typeTup))
|
||||
elog(ERROR, "cache lookup failed for type %u",
|
||||
desc->attrs[i]->atttypid);
|
||||
attr->atttypid);
|
||||
|
||||
PLy_input_datum_func2(&(arg->in.r.atts[i]), arg->mcxt,
|
||||
desc->attrs[i]->atttypid,
|
||||
attr->atttypid,
|
||||
typeTup,
|
||||
exec_ctx->curr_proc->langid,
|
||||
exec_ctx->curr_proc->trftypes);
|
||||
@@ -224,18 +224,18 @@ PLy_output_tuple_funcs(PLyTypeInfo *arg, TupleDesc desc)
|
||||
for (i = 0; i < desc->natts; i++)
|
||||
{
|
||||
HeapTuple typeTup;
|
||||
Form_pg_attribute attr = TupleDescAttr(desc, i);
|
||||
|
||||
if (desc->attrs[i]->attisdropped)
|
||||
if (attr->attisdropped)
|
||||
continue;
|
||||
|
||||
if (arg->out.r.atts[i].typoid == desc->attrs[i]->atttypid)
|
||||
if (arg->out.r.atts[i].typoid == attr->atttypid)
|
||||
continue; /* already set up this entry */
|
||||
|
||||
typeTup = SearchSysCache1(TYPEOID,
|
||||
ObjectIdGetDatum(desc->attrs[i]->atttypid));
|
||||
typeTup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(attr->atttypid));
|
||||
if (!HeapTupleIsValid(typeTup))
|
||||
elog(ERROR, "cache lookup failed for type %u",
|
||||
desc->attrs[i]->atttypid);
|
||||
attr->atttypid);
|
||||
|
||||
PLy_output_datum_func2(&(arg->out.r.atts[i]), arg->mcxt, typeTup,
|
||||
exec_ctx->curr_proc->langid,
|
||||
@@ -306,11 +306,12 @@ PLyDict_FromTuple(PLyTypeInfo *info, HeapTuple tuple, TupleDesc desc)
|
||||
Datum vattr;
|
||||
bool is_null;
|
||||
PyObject *value;
|
||||
Form_pg_attribute attr = TupleDescAttr(desc, i);
|
||||
|
||||
if (desc->attrs[i]->attisdropped)
|
||||
if (attr->attisdropped)
|
||||
continue;
|
||||
|
||||
key = NameStr(desc->attrs[i]->attname);
|
||||
key = NameStr(attr->attname);
|
||||
vattr = heap_getattr(tuple, (i + 1), desc, &is_null);
|
||||
|
||||
if (is_null || info->in.r.atts[i].func == NULL)
|
||||
@@ -1183,15 +1184,16 @@ PLyMapping_ToComposite(PLyTypeInfo *info, TupleDesc desc, PyObject *mapping)
|
||||
char *key;
|
||||
PyObject *volatile value;
|
||||
PLyObToDatum *att;
|
||||
Form_pg_attribute attr = TupleDescAttr(desc, i);
|
||||
|
||||
if (desc->attrs[i]->attisdropped)
|
||||
if (attr->attisdropped)
|
||||
{
|
||||
values[i] = (Datum) 0;
|
||||
nulls[i] = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
key = NameStr(desc->attrs[i]->attname);
|
||||
key = NameStr(attr->attname);
|
||||
value = NULL;
|
||||
att = &info->out.r.atts[i];
|
||||
PG_TRY();
|
||||
@@ -1256,7 +1258,7 @@ PLySequence_ToComposite(PLyTypeInfo *info, TupleDesc desc, PyObject *sequence)
|
||||
idx = 0;
|
||||
for (i = 0; i < desc->natts; i++)
|
||||
{
|
||||
if (!desc->attrs[i]->attisdropped)
|
||||
if (!TupleDescAttr(desc, i)->attisdropped)
|
||||
idx++;
|
||||
}
|
||||
if (PySequence_Length(sequence) != idx)
|
||||
@@ -1277,7 +1279,7 @@ PLySequence_ToComposite(PLyTypeInfo *info, TupleDesc desc, PyObject *sequence)
|
||||
PyObject *volatile value;
|
||||
PLyObToDatum *att;
|
||||
|
||||
if (desc->attrs[i]->attisdropped)
|
||||
if (TupleDescAttr(desc, i)->attisdropped)
|
||||
{
|
||||
values[i] = (Datum) 0;
|
||||
nulls[i] = true;
|
||||
@@ -1346,15 +1348,16 @@ PLyGenericObject_ToComposite(PLyTypeInfo *info, TupleDesc desc, PyObject *object
|
||||
char *key;
|
||||
PyObject *volatile value;
|
||||
PLyObToDatum *att;
|
||||
Form_pg_attribute attr = TupleDescAttr(desc, i);
|
||||
|
||||
if (desc->attrs[i]->attisdropped)
|
||||
if (attr->attisdropped)
|
||||
{
|
||||
values[i] = (Datum) 0;
|
||||
nulls[i] = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
key = NameStr(desc->attrs[i]->attname);
|
||||
key = NameStr(attr->attname);
|
||||
value = NULL;
|
||||
att = &info->out.r.atts[i];
|
||||
PG_TRY();
|
||||
|
||||
Reference in New Issue
Block a user