mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Don't bother checking the result of SPI_connect[_ext] anymore.
SPI_connect/SPI_connect_ext have not returned any value other than
SPI_OK_CONNECT since commit 1833f1a1c
in v10; any errors are thrown
via ereport. (The most likely failure is out-of-memory, which has
always been thrown that way, so callers had better be prepared for
such errors.) This makes it somewhat pointless to check these
functions' result, and some callers within our code haven't been
bothering; indeed, the only usage example within spi.sgml doesn't
bother. So it's likely that the omission has propagated into
extensions too.
Hence, let's standardize on not checking, and document the return
value as historical, while not actually changing these functions'
behavior. (The original proposal was to change their return type
to "void", but that would needlessly break extensions that are
conforming to the old practice.) This saves a small amount of
boilerplate code in a lot of places.
Stepan Neretin
Discussion: https://postgr.es/m/CAMaYL5Z9Uk8cD9qGz9QaZ2UBJFOu7jFx5Mwbznz-1tBbPDQZow@mail.gmail.com
This commit is contained in:
@ -385,9 +385,7 @@ crosstab(PG_FUNCTION_ARGS)
|
||||
per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
|
||||
|
||||
/* Connect to SPI manager */
|
||||
if ((ret = SPI_connect()) < 0)
|
||||
/* internal error */
|
||||
elog(ERROR, "crosstab: SPI_connect returned %d", ret);
|
||||
SPI_connect();
|
||||
|
||||
/* Retrieve the desired rows */
|
||||
ret = SPI_execute(sql, true, 0);
|
||||
@ -724,9 +722,7 @@ load_categories_hash(char *cats_sql, MemoryContext per_query_ctx)
|
||||
HASH_ELEM | HASH_STRINGS | HASH_CONTEXT);
|
||||
|
||||
/* Connect to SPI manager */
|
||||
if ((ret = SPI_connect()) < 0)
|
||||
/* internal error */
|
||||
elog(ERROR, "load_categories_hash: SPI_connect returned %d", ret);
|
||||
SPI_connect();
|
||||
|
||||
/* Retrieve the category name rows */
|
||||
ret = SPI_execute(cats_sql, true, 0);
|
||||
@ -806,9 +802,7 @@ get_crosstab_tuplestore(char *sql,
|
||||
tupstore = tuplestore_begin_heap(randomAccess, false, work_mem);
|
||||
|
||||
/* Connect to SPI manager */
|
||||
if ((ret = SPI_connect()) < 0)
|
||||
/* internal error */
|
||||
elog(ERROR, "get_crosstab_tuplestore: SPI_connect returned %d", ret);
|
||||
SPI_connect();
|
||||
|
||||
/* Now retrieve the crosstab source rows */
|
||||
ret = SPI_execute(sql, true, 0);
|
||||
@ -1151,15 +1145,11 @@ connectby(char *relname,
|
||||
AttInMetadata *attinmeta)
|
||||
{
|
||||
Tuplestorestate *tupstore = NULL;
|
||||
int ret;
|
||||
MemoryContext oldcontext;
|
||||
|
||||
int serial = 1;
|
||||
|
||||
/* Connect to SPI manager */
|
||||
if ((ret = SPI_connect()) < 0)
|
||||
/* internal error */
|
||||
elog(ERROR, "connectby: SPI_connect returned %d", ret);
|
||||
SPI_connect();
|
||||
|
||||
/* switch to longer term context to create the tuple store */
|
||||
oldcontext = MemoryContextSwitchTo(per_query_ctx);
|
||||
|
Reference in New Issue
Block a user