Re: Some new SPI functions
От
Bruce Momjian
Тема
Re: Some new SPI functions
Дата
Msg-id
200403050047.i250l3R05618@candle.pha.pa.us
Ответ на
Re: Some new SPI functions (Thomas Hallgren)
Список
Дерево обсуждения
Some new SPI functions "Thomas Hallgren" <thhal@mailblocks.com>
Re: Some new SPI functions Bruce Momjian <pgman@candle.pha.pa.us>
Re: Some new SPI functions Tom Lane <tgl@sss.pgh.pa.us>
Re: Some new SPI functions Bruce Momjian <pgman@candle.pha.pa.us>
Patch applied. Thanks.
---------------------------------------------------------------------------
Thomas Hallgren wrote:
> > Who did you think would do it?
> >
> > regards, tom lane
> >
> you :-)
>
> Seriously, I didn't give it much though. This is undoubtedly the best way
> although some projects handle it differently. A tech-writer perhaps, with
> better writing skills then programmers in general. But people like that are
> probabaly not too common in the open source field. If you don't do like
> JBoss and charge for the docs (I'm *not* in favor of that).
>
> Anyway, here's the patch again. This time with documentation.
>
> Index: doc/src/sgml/spi.sgml
> ===================================================================
> retrieving revision 1.30
> diff -u -r1.30 spi.sgml
> --- doc/src/sgml/spi.sgml 1 Dec 2003 22:07:57 -0000 1.30
> +++ doc/src/sgml/spi.sgml 15 Feb 2004 13:47:13 -0000
> @@ -573,6 +573,190 @@
>
>
>
> +
> +
> + SPI_getargcount
> +
> +
> +
> + SPI_getargcount
> + returns the number of arguments needed when executing a plan
> + prepared by SPI_prepare
> +
> +
> + SPI_getargcount
> +
> +
> +
> +int SPI_getargcount(void * plan)
> +
> +
> +
> +
> + Description
> +
> +
> + SPI_getargcount returns the number of arguments
> needed
> + when executing a plan prepared by SPI_prepare.
> +
> +
> +
> +
> + Arguments
> +
> +
> +
> + void * plan
> +
> +
> + execution plan (returned by SPI_prepare)
> +
> +
> +
> +
> +
> +
> +
> + Return Value
> +
> + The expected argument count for the plan or
> + SPI_ERROR_ARGUMENT if the plan
> + is NULL
> +
> +
> +
> +
> +
> +
> +
> +
> + SPI_getargtypeid
> +
> +
> +
> + SPI_getargtypeid
> + returns the expected typeid for the specified argument when
> + executing a plan prepared by
> SPI_prepare
> +
> +
> + SPI_getargtypeid
> +
> +
> +
> +Oid SPI_getargtypeid(void * plan, int
> argIndex)
> +
> +
> +
> +
> + Description
> +
> +
> + SPI_getargtypeid returns the Oid representing the
> type
> + id for argument at argIndex in a plan prepared by
> + SPI_prepare. First argument is at index zero.
> +
> +
> +
> +
> + Arguments
> +
> +
> +
> + void * plan
> +
> +
> + execution plan (returned by SPI_prepare)
> +
> +
> +
> +
> +
> + int argIndex
> +
> +
> + zero based index of the argument
> +
> +
> +
> +
> +
> +
> +
> + Return Value
> +
> + The type id of the argument at the given index or
> + SPI_ERROR_ARGUMENT if the plan is
> + NULL or argIndex is less than 0
> or
> + not less than the number of arguments declared for the plan
> +
> +
> +
> +
> +
> +
> +
> +
> +
> + SPI_is_cursor_plan
> +
> +
> +
> + SPI_is_cursor_plan
> + returns true if a plan
> + prepared by SPI_prepare can be passed
> + as an argument to SPI_cursor_open
> +
> +
> + SPI_is_cursor_plan
> +
> +
> +
> +bool SPI_is_cursor_plan(void * plan)
> +
> +
> +
> +
> + Description
> +
> +
> + SPI_is_cursor_plan returns true
> + if a plan prepared by SPI_prepare can be passed
> + as an argument to SPI_cursor_open and
> + false if that is not the case. The criteria is that the
> + plan represents one single command and that this
> + command is a SELECT without an
> INTO
> + clause.
> +
> +
> +
> +
> + Arguments
> +
> +
> +
> + void * plan
> +
> +
> + execution plan (returned by SPI_prepare)
> +
> +
> +
> +
> +
> +
> +
> + Return Value
> +
> + true or false to indicate if the
> + plan can produce a cursor or not, or
> + SPI_ERROR_ARGUMENT if the plan
> + is NULL
> +
> +
> +
> +
> +
> +
>
>
> SPI_execp
> Index: src/backend/executor/spi.c
> ===================================================================
> retrieving revision 1.109
> diff -u -r1.109 spi.c
> --- src/backend/executor/spi.c 2 Dec 2003 19:26:47 -0000 1.109
> +++ src/backend/executor/spi.c 15 Feb 2004 13:47:18 -0000
> @@ -918,6 +918,65 @@
> PortalDrop(portal, false);
> }
>
> +/*
> + * Returns the Oid representing the type id for argument at argIndex. First
> + * parameter is at index zero.
> + */
> +Oid
> +SPI_getargtypeid(void *plan, int argIndex)
> +{
> + if (plan == NULL || argIndex < 0 || argIndex >= ((_SPI_plan*)plan)->nargs)
> + {
> + SPI_result = SPI_ERROR_ARGUMENT;
> + return InvalidOid;
> + }
> + return ((_SPI_plan *) plan)->argtypes[argIndex];
> +}
> +
> +/*
> + * Returns the number of arguments for the prepared plan.
> + */
> +int
> +SPI_getargcount(void *plan)
> +{
> + if (plan == NULL)
> + {
> + SPI_result = SPI_ERROR_ARGUMENT;
> + return -1;
> + }
> + return ((_SPI_plan *) plan)->nargs;
> +}
> +
> +/*
> + * Returns true if the plan contains exactly one command
> + * and that command originates from normal SELECT (i.e.
> + * *not* a SELECT ... INTO). In essence, the result indicates
> + * if the command can be used with SPI_cursor_open
> + *
> + * Parameters
> + * plan A plan previously prepared using SPI_prepare
> + */
> +bool
> +SPI_is_cursor_plan(void *plan)
> +{
> + List *qtlist;
> + _SPI_plan *spiplan = (_SPI_plan *) plan;
> + if (spiplan == NULL)
> + {
> + SPI_result = SPI_ERROR_ARGUMENT;
> + return false;
> + }
> +
> + qtlist = spiplan->qtlist;
> + if(length(spiplan->ptlist) == 1 && length(qtlist) == 1)
> + {
> + Query *queryTree = (Query *) lfirst((List *) lfirst(qtlist));
> + if(queryTree->commandType == CMD_SELECT && queryTree->into == NULL)
> + return true;
> + }
> + return false;
> +}
> +
> /* =================== private functions =================== */
>
> /*
> Index: src/include/executor/spi.h
> ===================================================================
> retrieving revision 1.41
> diff -u -r1.41 spi.h
> --- src/include/executor/spi.h 2 Dec 2003 19:26:47 -0000 1.41
> +++ src/include/executor/spi.h 15 Feb 2004 13:47:32 -0000
> @@ -90,6 +90,10 @@
> extern void *SPI_saveplan(void *plan);
> extern int SPI_freeplan(void *plan);
>
> +extern Oid SPI_getargtypeid(void *plan, int argIndex);
> +extern int SPI_getargcount(void *plan);
> +extern bool SPI_is_cursor_plan(void *plan);
> +
> extern HeapTuple SPI_copytuple(HeapTuple tuple);
> extern TupleDesc SPI_copytupledesc(TupleDesc tupdesc);
> extern TupleTableSlot *SPI_copytupleintoslot(HeapTuple tuple,
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
В списке pgsql-patches по дате отправления