mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Modify all callers of datatype input and receive functions so that if these
functions are not strict, they will be called (passing a NULL first parameter) during any attempt to input a NULL value of their datatype. Currently, all our input functions are strict and so this commit does not change any behavior. However, this will make it possible to build domain input functions that centralize checking of domain constraints, thereby closing numerous holes in our domain support, as per previous discussion. While at it, I took the opportunity to introduce convenience functions InputFunctionCall, OutputFunctionCall, etc to use in code that calls I/O functions. This eliminates a lot of grotty-looking casts, but the main motivation is to make it easier to grep for these places if we ever need to touch them again.
This commit is contained in:
@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.92 2006/03/05 15:58:26 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.93 2006/04/04 19:35:34 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -928,6 +928,7 @@ TupleDescGetAttInMetadata(TupleDesc tupdesc)
|
||||
/*
|
||||
* BuildTupleFromCStrings - build a HeapTuple given user data in C string form.
|
||||
* values is an array of C strings, one for each attribute of the return tuple.
|
||||
* A NULL string pointer indicates we want to create a NULL field.
|
||||
*/
|
||||
HeapTuple
|
||||
BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
|
||||
@ -937,35 +938,25 @@ BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
|
||||
Datum *dvalues;
|
||||
char *nulls;
|
||||
int i;
|
||||
Oid attioparam;
|
||||
int32 atttypmod;
|
||||
HeapTuple tuple;
|
||||
|
||||
dvalues = (Datum *) palloc(natts * sizeof(Datum));
|
||||
nulls = (char *) palloc(natts * sizeof(char));
|
||||
|
||||
/* Call the "in" function for each non-null, non-dropped attribute */
|
||||
/* Call the "in" function for each non-dropped attribute */
|
||||
for (i = 0; i < natts; i++)
|
||||
{
|
||||
if (!tupdesc->attrs[i]->attisdropped)
|
||||
{
|
||||
/* Non-dropped attributes */
|
||||
dvalues[i] = InputFunctionCall(&attinmeta->attinfuncs[i],
|
||||
values[i],
|
||||
attinmeta->attioparams[i],
|
||||
attinmeta->atttypmods[i]);
|
||||
if (values[i] != NULL)
|
||||
{
|
||||
attioparam = attinmeta->attioparams[i];
|
||||
atttypmod = attinmeta->atttypmods[i];
|
||||
|
||||
dvalues[i] = FunctionCall3(&attinmeta->attinfuncs[i],
|
||||
CStringGetDatum(values[i]),
|
||||
ObjectIdGetDatum(attioparam),
|
||||
Int32GetDatum(atttypmod));
|
||||
nulls[i] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
dvalues[i] = (Datum) 0;
|
||||
nulls[i] = 'n';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -61,7 +61,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.138 2006/03/05 15:58:26 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.139 2006/04/04 19:35:34 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1407,10 +1407,8 @@ GetAggInitVal(Datum textInitVal, Oid transtype)
|
||||
|
||||
getTypeInputInfo(transtype, &typinput, &typioparam);
|
||||
strInitVal = DatumGetCString(DirectFunctionCall1(textout, textInitVal));
|
||||
initVal = OidFunctionCall3(typinput,
|
||||
CStringGetDatum(strInitVal),
|
||||
ObjectIdGetDatum(typioparam),
|
||||
Int32GetDatum(-1));
|
||||
initVal = OidInputFunctionCall(typinput, strInitVal,
|
||||
typioparam, -1);
|
||||
pfree(strInitVal);
|
||||
return initVal;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.149 2006/03/14 22:48:19 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.150 2006/04/04 19:35:34 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -629,9 +629,9 @@ SPI_fname(TupleDesc tupdesc, int fnumber)
|
||||
char *
|
||||
SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
|
||||
{
|
||||
char *result;
|
||||
Datum origval,
|
||||
val,
|
||||
result;
|
||||
val;
|
||||
bool isnull;
|
||||
Oid typoid,
|
||||
foutoid;
|
||||
@ -666,14 +666,13 @@ SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
|
||||
else
|
||||
val = origval;
|
||||
|
||||
result = OidFunctionCall1(foutoid,
|
||||
val);
|
||||
result = OidOutputFunctionCall(foutoid, val);
|
||||
|
||||
/* Clean up detoasted copy, if any */
|
||||
if (val != origval)
|
||||
pfree(DatumGetPointer(val));
|
||||
|
||||
return DatumGetCString(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
Datum
|
||||
|
Reference in New Issue
Block a user