diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-04-04 19:35:37 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-04-04 19:35:37 +0000 |
commit | 147d4bf3e5e3da2ee0f0cc132718ab1c4912a877 (patch) | |
tree | e02e6a191197edb5224ab5f831146854fde7d460 /src/backend/executor | |
parent | eaef111396ef7e70c88979c7a82f6a8f918d9651 (diff) | |
download | postgresql-147d4bf3e5e3da2ee0f0cc132718ab1c4912a877.tar.gz postgresql-147d4bf3e5e3da2ee0f0cc132718ab1c4912a877.zip |
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.
Diffstat (limited to 'src/backend/executor')
-rw-r--r-- | src/backend/executor/execTuples.c | 23 | ||||
-rw-r--r-- | src/backend/executor/nodeAgg.c | 8 | ||||
-rw-r--r-- | src/backend/executor/spi.c | 11 |
3 files changed, 15 insertions, 27 deletions
diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c index bd50027f776..81f589fd44b 100644 --- a/src/backend/executor/execTuples.c +++ b/src/backend/executor/execTuples.c @@ -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 { diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index 5b48545aac9..a242d53968e 100644 --- a/src/backend/executor/nodeAgg.c +++ b/src/backend/executor/nodeAgg.c @@ -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; } diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 183bc89b020..3563ba23d3a 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -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 |