From: Mark Dilger Date: Thu, 7 Nov 2019 12:20:46 -0800 Subject: [PATCH v1 4/5] Refactoring SPI execute related errors. Deprecating SPI_ERROR_PARAM in favor of throwing an error. This error code was only being returned when a caller of SPI_execute_plan, SPI_execute_snapshot, or SPI_execute_with_args passed in a plan which has nargs > 0 but then negligently passed in NULL for the Values and/or argtypes. This would be a C coding error, not a state of affairs that a user could trigger. --- doc/src/sgml/spi.sgml | 9 --------- src/backend/executor/spi.c | 8 +++----- src/include/executor/spi.h | 2 +- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/doc/src/sgml/spi.sgml b/doc/src/sgml/spi.sgml index abe1475256..cca91f6ef6 100644 --- a/doc/src/sgml/spi.sgml +++ b/doc/src/sgml/spi.sgml @@ -1439,15 +1439,6 @@ int SPI_execute_plan(SPIPlanPtr plan, Datum * - - SPI_ERROR_PARAM - - - if values is NULL and - plan was prepared with some parameters - - - diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 7d227a11d2..579e80a6a7 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -538,7 +538,7 @@ SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const char *Nulls, return SPI_ERROR_ARGUMENT; if (plan->nargs > 0 && Values == NULL) - return SPI_ERROR_PARAM; + elog(ERROR, "SPI_execute_plan passed invalid parameters"); res = _SPI_begin_call(true); if (res < 0) @@ -608,7 +608,7 @@ SPI_execute_snapshot(SPIPlanPtr plan, return SPI_ERROR_ARGUMENT; if (plan->nargs > 0 && Values == NULL) - return SPI_ERROR_PARAM; + elog(ERROR, "SPI_execute_snapshot passed invalid parameters"); res = _SPI_begin_call(true); if (res < 0) @@ -644,7 +644,7 @@ SPI_execute_with_args(const char *src, return SPI_ERROR_ARGUMENT; if (nargs > 0 && (argtypes == NULL || Values == NULL)) - return SPI_ERROR_PARAM; + elog(ERROR, "SPI_execute_with_args passed invalid parameters"); res = _SPI_begin_call(true); if (res < 0) @@ -1717,8 +1717,6 @@ SPI_result_code_string(int code) return "SPI_ERROR_UNCONNECTED"; case SPI_ERROR_ARGUMENT: return "SPI_ERROR_ARGUMENT"; - case SPI_ERROR_PARAM: - return "SPI_ERROR_PARAM"; case SPI_ERROR_TRANSACTION: return "SPI_ERROR_TRANSACTION"; case SPI_ERROR_NOATTRIBUTE: diff --git a/src/include/executor/spi.h b/src/include/executor/spi.h index 7a43b9d21e..575978737f 100644 --- a/src/include/executor/spi.h +++ b/src/include/executor/spi.h @@ -42,7 +42,7 @@ typedef struct _SPI_plan *SPIPlanPtr; #define SPI_ERROR_UNCONNECTED (-4) #define SPI_ERROR_CURSOR (-5) /* not used anymore */ #define SPI_ERROR_ARGUMENT (-6) -#define SPI_ERROR_PARAM (-7) +#define SPI_ERROR_PARAM (-7) /* not used anymore */ #define SPI_ERROR_TRANSACTION (-8) #define SPI_ERROR_NOATTRIBUTE (-9) #define SPI_ERROR_NOOUTFUNC (-10) /* not used anymore */ -- 2.20.1 --------------EE32DA189D040DF51B4A06B1 Content-Type: text/x-patch; name="v1-0005-Refactoring-SPI-related-errors.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="v1-0005-Refactoring-SPI-related-errors.patch"