1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-03 15:22:11 +03:00

Remove all uses of the deprecated functions heap_formtuple, heap_modifytuple,

and heap_deformtuple in favor of the newer functions heap_form_tuple et al
(which do the same things but use bool control flags instead of arbitrary
char values).  Eliminate the former duplicate coding of these functions,
reducing the deprecated functions to mere wrappers around the newer ones.
We can't get rid of them entirely because add-on modules probably still
contain many instances of the old coding style.

Kris Jurka
This commit is contained in:
Tom Lane
2008-11-02 01:45:28 +00:00
parent 492059daba
commit 902d1cb35f
46 changed files with 630 additions and 1013 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.222 2008/10/29 00:00:39 tgl Exp $
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.223 2008/11/02 01:45:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -3578,9 +3578,9 @@ exec_assign_value(PLpgSQL_execstate *estate,
int fno;
HeapTuple newtup;
int natts;
int i;
Datum *values;
char *nulls;
bool *nulls;
bool *replaces;
void *mustfree;
bool attisnull;
Oid atttype;
@@ -3602,10 +3602,11 @@ exec_assign_value(PLpgSQL_execstate *estate,
/*
* Get the number of the records field to change and the
* number of attributes in the tuple.
* number of attributes in the tuple. Note: disallow
* system column names because the code below won't cope.
*/
fno = SPI_fnumber(rec->tupdesc, recfield->fieldname);
if (fno == SPI_ERROR_NOATTRIBUTE)
if (fno <= 0)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("record \"%s\" has no field \"%s\"",
@@ -3614,24 +3615,16 @@ exec_assign_value(PLpgSQL_execstate *estate,
natts = rec->tupdesc->natts;
/*
* Set up values/datums arrays for heap_formtuple. For all
* Set up values/control arrays for heap_modify_tuple. For all
* the attributes except the one we want to replace, use the
* value that's in the old tuple.
*/
values = palloc(sizeof(Datum) * natts);
nulls = palloc(natts);
nulls = palloc(sizeof(bool) * natts);
replaces = palloc(sizeof(bool) * natts);
for (i = 0; i < natts; i++)
{
if (i == fno)
continue;
values[i] = SPI_getbinval(rec->tup, rec->tupdesc,
i + 1, &attisnull);
if (attisnull)
nulls[i] = 'n';
else
nulls[i] = ' ';
}
memset(replaces, false, sizeof(bool) * natts);
replaces[fno] = true;
/*
* Now insert the new value, being careful to cast it to the
@@ -3645,10 +3638,7 @@ exec_assign_value(PLpgSQL_execstate *estate,
atttype,
atttypmod,
attisnull);
if (attisnull)
nulls[fno] = 'n';
else
nulls[fno] = ' ';
nulls[fno] = attisnull;
/*
* Avoid leaking the result of exec_simple_cast_value, if it
@@ -3660,10 +3650,11 @@ exec_assign_value(PLpgSQL_execstate *estate,
mustfree = NULL;
/*
* Now call heap_formtuple() to create a new tuple that
* Now call heap_modify_tuple() to create a new tuple that
* replaces the old one in the record.
*/
newtup = heap_formtuple(rec->tupdesc, values, nulls);
newtup = heap_modify_tuple(rec->tup, rec->tupdesc,
values, nulls, replaces);
if (rec->freetup)
heap_freetuple(rec->tup);
@@ -3673,6 +3664,7 @@ exec_assign_value(PLpgSQL_execstate *estate,
pfree(values);
pfree(nulls);
pfree(replaces);
if (mustfree)
pfree(mustfree);
@@ -4519,12 +4511,12 @@ exec_move_row(PLpgSQL_execstate *estate,
else if (tupdesc)
{
/* If we have a tupdesc but no data, form an all-nulls tuple */
char *nulls;
bool *nulls;
nulls = (char *) palloc(tupdesc->natts * sizeof(char));
memset(nulls, 'n', tupdesc->natts * sizeof(char));
nulls = (bool *) palloc(tupdesc->natts * sizeof(bool));
memset(nulls, true, tupdesc->natts * sizeof(bool));
tup = heap_formtuple(tupdesc, NULL, nulls);
tup = heap_form_tuple(tupdesc, NULL, nulls);
pfree(nulls);
}

View File

@@ -1,7 +1,7 @@
/**********************************************************************
* plpython.c - python as a procedural language for PostgreSQL
*
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.114 2008/10/11 00:09:33 alvherre Exp $
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.115 2008/11/02 01:45:28 tgl Exp $
*
*********************************************************************
*/
@@ -1766,7 +1766,7 @@ PLyMapping_ToTuple(PLyTypeInfo * info, PyObject * mapping)
TupleDesc desc;
HeapTuple tuple;
Datum *values;
char *nulls;
bool *nulls;
volatile int i;
Assert(PyMapping_Check(mapping));
@@ -1778,7 +1778,7 @@ PLyMapping_ToTuple(PLyTypeInfo * info, PyObject * mapping)
/* Build tuple */
values = palloc(sizeof(Datum) * desc->natts);
nulls = palloc(sizeof(char) * desc->natts);
nulls = palloc(sizeof(bool) * desc->natts);
for (i = 0; i < desc->natts; ++i)
{
char *key;
@@ -1793,7 +1793,7 @@ PLyMapping_ToTuple(PLyTypeInfo * info, PyObject * mapping)
if (value == Py_None)
{
values[i] = (Datum) NULL;
nulls[i] = 'n';
nulls[i] = true;
}
else if (value)
{
@@ -1810,7 +1810,7 @@ PLyMapping_ToTuple(PLyTypeInfo * info, PyObject * mapping)
,-1);
Py_DECREF(so);
so = NULL;
nulls[i] = ' ';
nulls[i] = false;
}
else
ereport(ERROR,
@@ -1831,7 +1831,7 @@ PLyMapping_ToTuple(PLyTypeInfo * info, PyObject * mapping)
PG_END_TRY();
}
tuple = heap_formtuple(desc, values, nulls);
tuple = heap_form_tuple(desc, values, nulls);
ReleaseTupleDesc(desc);
pfree(values);
pfree(nulls);
@@ -1846,7 +1846,7 @@ PLySequence_ToTuple(PLyTypeInfo * info, PyObject * sequence)
TupleDesc desc;
HeapTuple tuple;
Datum *values;
char *nulls;
bool *nulls;
volatile int i;
Assert(PySequence_Check(sequence));
@@ -1868,7 +1868,7 @@ PLySequence_ToTuple(PLyTypeInfo * info, PyObject * sequence)
/* Build tuple */
values = palloc(sizeof(Datum) * desc->natts);
nulls = palloc(sizeof(char) * desc->natts);
nulls = palloc(sizeof(bool) * desc->natts);
for (i = 0; i < desc->natts; ++i)
{
PyObject *volatile value,
@@ -1882,7 +1882,7 @@ PLySequence_ToTuple(PLyTypeInfo * info, PyObject * sequence)
if (value == Py_None)
{
values[i] = (Datum) NULL;
nulls[i] = 'n';
nulls[i] = true;
}
else if (value)
{
@@ -1898,7 +1898,7 @@ PLySequence_ToTuple(PLyTypeInfo * info, PyObject * sequence)
,-1);
Py_DECREF(so);
so = NULL;
nulls[i] = ' ';
nulls[i] = false;
}
Py_XDECREF(value);
@@ -1913,7 +1913,7 @@ PLySequence_ToTuple(PLyTypeInfo * info, PyObject * sequence)
PG_END_TRY();
}
tuple = heap_formtuple(desc, values, nulls);
tuple = heap_form_tuple(desc, values, nulls);
ReleaseTupleDesc(desc);
pfree(values);
pfree(nulls);
@@ -1928,7 +1928,7 @@ PLyObject_ToTuple(PLyTypeInfo * info, PyObject * object)
TupleDesc desc;
HeapTuple tuple;
Datum *values;
char *nulls;
bool *nulls;
volatile int i;
desc = lookup_rowtype_tupdesc(info->out.d.typoid, -1);
@@ -1938,7 +1938,7 @@ PLyObject_ToTuple(PLyTypeInfo * info, PyObject * object)
/* Build tuple */
values = palloc(sizeof(Datum) * desc->natts);
nulls = palloc(sizeof(char) * desc->natts);
nulls = palloc(sizeof(bool) * desc->natts);
for (i = 0; i < desc->natts; ++i)
{
char *key;
@@ -1953,7 +1953,7 @@ PLyObject_ToTuple(PLyTypeInfo * info, PyObject * object)
if (value == Py_None)
{
values[i] = (Datum) NULL;
nulls[i] = 'n';
nulls[i] = true;
}
else if (value)
{
@@ -1969,7 +1969,7 @@ PLyObject_ToTuple(PLyTypeInfo * info, PyObject * object)
,-1);
Py_DECREF(so);
so = NULL;
nulls[i] = ' ';
nulls[i] = false;
}
else
ereport(ERROR,
@@ -1991,7 +1991,7 @@ PLyObject_ToTuple(PLyTypeInfo * info, PyObject * object)
PG_END_TRY();
}
tuple = heap_formtuple(desc, values, nulls);
tuple = heap_form_tuple(desc, values, nulls);
ReleaseTupleDesc(desc);
pfree(values);
pfree(nulls);