Commit f478856c authored by Neil Conway's avatar Neil Conway

Change SPI functions to use a `long' when specifying the number of tuples

to produce when running the executor. This is consistent with the internal
executor APIs (such as ExecutorRun), which also use a long for this purpose.
It also allows FETCH_ALL to be passed -- since FETCH_ALL is defined as
LONG_MAX, this wouldn't have worked on platforms where int and long are of
different sizes. Per report from Tzahi Fadida.
parent 6c412f06
<!--
$PostgreSQL: pgsql/doc/src/sgml/spi.sgml,v 1.40 2005/03/29 02:53:53 neilc Exp $
$PostgreSQL: pgsql/doc/src/sgml/spi.sgml,v 1.41 2005/05/02 00:37:06 neilc Exp $
-->
<chapter id="spi">
......@@ -292,7 +292,7 @@ void SPI_pop(void)
<refsynopsisdiv>
<synopsis>
int SPI_execute(const char * <parameter>command</parameter>, bool <parameter>read_only</parameter>, int <parameter>count</parameter>)
int SPI_execute(const char * <parameter>command</parameter>, bool <parameter>read_only</parameter>, long <parameter>count</parameter>)
</synopsis>
</refsynopsisdiv>
......@@ -423,7 +423,7 @@ typedef struct
</varlistentry>
<varlistentry>
<term><literal>int <parameter>count</parameter></literal></term>
<term><literal>long <parameter>count</parameter></literal></term>
<listitem>
<para>
maximum number of rows to process or return
......@@ -598,7 +598,7 @@ typedef struct
<refsynopsisdiv>
<synopsis>
int SPI_exec(const char * <parameter>command</parameter>, int <parameter>count</parameter>)
int SPI_exec(const char * <parameter>command</parameter>, long <parameter>count</parameter>)
</synopsis>
</refsynopsisdiv>
......@@ -627,7 +627,7 @@ int SPI_exec(const char * <parameter>command</parameter>, int <parameter>count</
</varlistentry>
<varlistentry>
<term><literal>int <parameter>count</parameter></literal></term>
<term><literal>long <parameter>count</parameter></literal></term>
<listitem>
<para>
maximum number of rows to process or return
......@@ -963,7 +963,7 @@ bool SPI_is_cursor_plan(void * <parameter>plan</parameter>)
<refsynopsisdiv>
<synopsis>
int SPI_execute_plan(void * <parameter>plan</parameter>, Datum * <parameter>values</parameter>, const char * <parameter>nulls</parameter>,
bool <parameter>read_only</parameter>, int <parameter>count</parameter>)
bool <parameter>read_only</parameter>, long <parameter>count</parameter>)
</synopsis>
</refsynopsisdiv>
......@@ -1030,7 +1030,7 @@ int SPI_execute_plan(void * <parameter>plan</parameter>, Datum * <parameter>valu
</varlistentry>
<varlistentry>
<term><literal>int <parameter>count</parameter></literal></term>
<term><literal>long <parameter>count</parameter></literal></term>
<listitem>
<para>
maximum number of rows to process or return
......@@ -1104,7 +1104,7 @@ int SPI_execute_plan(void * <parameter>plan</parameter>, Datum * <parameter>valu
<refsynopsisdiv>
<synopsis>
int SPI_execp(void * <parameter>plan</parameter>, Datum * <parameter>values</parameter>, const char * <parameter>nulls</parameter>, int <parameter>count</parameter>)
int SPI_execp(void * <parameter>plan</parameter>, Datum * <parameter>values</parameter>, const char * <parameter>nulls</parameter>, long <parameter>count</parameter>)
</synopsis>
</refsynopsisdiv>
......@@ -1162,7 +1162,7 @@ int SPI_execp(void * <parameter>plan</parameter>, Datum * <parameter>values</par
</varlistentry>
<varlistentry>
<term><literal>int <parameter>count</parameter></literal></term>
<term><literal>long <parameter>count</parameter></literal></term>
<listitem>
<para>
maximum number of rows to process or return
......@@ -1375,7 +1375,7 @@ Portal SPI_cursor_find(const char * <parameter>name</parameter>)
<refsynopsisdiv>
<synopsis>
void SPI_cursor_fetch(Portal <parameter>portal</parameter>, bool <parameter>forward</parameter>, int <parameter>count</parameter>)
void SPI_cursor_fetch(Portal <parameter>portal</parameter>, bool <parameter>forward</parameter>, long <parameter>count</parameter>)
</synopsis>
</refsynopsisdiv>
......@@ -1411,7 +1411,7 @@ void SPI_cursor_fetch(Portal <parameter>portal</parameter>, bool <parameter>forw
</varlistentry>
<varlistentry>
<term><literal>int <parameter>count</parameter></literal></term>
<term><literal>long <parameter>count</parameter></literal></term>
<listitem>
<para>
maximum number of rows to fetch
......@@ -1448,7 +1448,7 @@ void SPI_cursor_fetch(Portal <parameter>portal</parameter>, bool <parameter>forw
<refsynopsisdiv>
<synopsis>
void SPI_cursor_move(Portal <parameter>portal</parameter>, bool <parameter>forward</parameter>, int <parameter>count</parameter>)
void SPI_cursor_move(Portal <parameter>portal</parameter>, bool <parameter>forward</parameter>, long <parameter>count</parameter>)
</synopsis>
</refsynopsisdiv>
......@@ -1485,7 +1485,7 @@ void SPI_cursor_move(Portal <parameter>portal</parameter>, bool <parameter>forwa
</varlistentry>
<varlistentry>
<term><literal>int <parameter>count</parameter></literal></term>
<term><literal>long <parameter>count</parameter></literal></term>
<listitem>
<para>
maximum number of rows to move
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.138 2005/05/01 18:56:18 tgl Exp $
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.139 2005/05/02 00:37:06 neilc Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -39,13 +39,13 @@ static void _SPI_prepare_plan(const char *src, _SPI_plan *plan);
static int _SPI_execute_plan(_SPI_plan *plan,
Datum *Values, const char *Nulls,
Snapshot snapshot, Snapshot crosscheck_snapshot,
bool read_only, int tcount);
bool read_only, long tcount);
static int _SPI_pquery(QueryDesc *queryDesc, int tcount);
static int _SPI_pquery(QueryDesc *queryDesc, long tcount);
static void _SPI_error_callback(void *arg);
static void _SPI_cursor_operation(Portal portal, bool forward, int count,
static void _SPI_cursor_operation(Portal portal, bool forward, long count,
DestReceiver *dest);
static _SPI_plan *_SPI_copy_plan(_SPI_plan *plan, int location);
......@@ -278,9 +278,9 @@ SPI_restore_connection(void)
_SPI_curid = _SPI_connected - 1;
}
/* Parse, plan, and execute a querystring */
/* Parse, plan, and execute a query string */
int
SPI_execute(const char *src, bool read_only, int tcount)
SPI_execute(const char *src, bool read_only, long tcount)
{
_SPI_plan plan;
int res;
......@@ -309,7 +309,7 @@ SPI_execute(const char *src, bool read_only, int tcount)
/* Obsolete version of SPI_execute */
int
SPI_exec(const char *src, int tcount)
SPI_exec(const char *src, long tcount)
{
return SPI_execute(src, false, tcount);
}
......@@ -317,7 +317,7 @@ SPI_exec(const char *src, int tcount)
/* Execute a previously prepared plan */
int
SPI_execute_plan(void *plan, Datum *Values, const char *Nulls,
bool read_only, int tcount)
bool read_only, long tcount)
{
int res;
......@@ -342,7 +342,7 @@ SPI_execute_plan(void *plan, Datum *Values, const char *Nulls,
/* Obsolete version of SPI_execute_plan */
int
SPI_execp(void *plan, Datum *Values, const char *Nulls, int tcount)
SPI_execp(void *plan, Datum *Values, const char *Nulls, long tcount)
{
return SPI_execute_plan(plan, Values, Nulls, false, tcount);
}
......@@ -360,7 +360,7 @@ int
SPI_execute_snapshot(void *plan,
Datum *Values, const char *Nulls,
Snapshot snapshot, Snapshot crosscheck_snapshot,
bool read_only, int tcount)
bool read_only, long tcount)
{
int res;
......@@ -979,7 +979,7 @@ SPI_cursor_find(const char *name)
* Fetch rows in a cursor
*/
void
SPI_cursor_fetch(Portal portal, bool forward, int count)
SPI_cursor_fetch(Portal portal, bool forward, long count)
{
_SPI_cursor_operation(portal, forward, count,
CreateDestReceiver(SPI, NULL));
......@@ -993,7 +993,7 @@ SPI_cursor_fetch(Portal portal, bool forward, int count)
* Move in a cursor
*/
void
SPI_cursor_move(Portal portal, bool forward, int count)
SPI_cursor_move(Portal portal, bool forward, long count)
{
_SPI_cursor_operation(portal, forward, count, None_Receiver);
}
......@@ -1309,7 +1309,7 @@ _SPI_prepare_plan(const char *src, _SPI_plan *plan)
static int
_SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls,
Snapshot snapshot, Snapshot crosscheck_snapshot,
bool read_only, int tcount)
bool read_only, long tcount)
{
volatile int res = 0;
Snapshot saveActiveSnapshot;
......@@ -1493,7 +1493,7 @@ fail:
}
static int
_SPI_pquery(QueryDesc *queryDesc, int tcount)
_SPI_pquery(QueryDesc *queryDesc, long tcount)
{
int operation = queryDesc->operation;
int res;
......@@ -1531,7 +1531,7 @@ _SPI_pquery(QueryDesc *queryDesc, int tcount)
ExecutorStart(queryDesc, false);
ExecutorRun(queryDesc, ForwardScanDirection, (long) tcount);
ExecutorRun(queryDesc, ForwardScanDirection, tcount);
_SPI_current->processed = queryDesc->estate->es_processed;
save_lastoid = queryDesc->estate->es_lastoid;
......@@ -1599,7 +1599,7 @@ _SPI_error_callback(void *arg)
* Do a FETCH or MOVE in a cursor
*/
static void
_SPI_cursor_operation(Portal portal, bool forward, int count,
_SPI_cursor_operation(Portal portal, bool forward, long count,
DestReceiver *dest)
{
long nfetched;
......@@ -1621,7 +1621,7 @@ _SPI_cursor_operation(Portal portal, bool forward, int count,
/* Run the cursor */
nfetched = PortalRunFetch(portal,
forward ? FETCH_FORWARD : FETCH_BACKWARD,
(long) count,
count,
dest);
/*
......
......@@ -2,7 +2,7 @@
*
* spi.h
*
* $PostgreSQL: pgsql/src/include/executor/spi.h,v 1.51 2005/03/29 02:53:53 neilc Exp $
* $PostgreSQL: pgsql/src/include/executor/spi.h,v 1.52 2005/05/02 00:37:06 neilc Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -82,17 +82,17 @@ extern int SPI_finish(void);
extern void SPI_push(void);
extern void SPI_pop(void);
extern void SPI_restore_connection(void);
extern int SPI_execute(const char *src, bool read_only, int tcount);
extern int SPI_execute(const char *src, bool read_only, long tcount);
extern int SPI_execute_plan(void *plan, Datum *Values, const char *Nulls,
bool read_only, int tcount);
extern int SPI_exec(const char *src, int tcount);
bool read_only, long tcount);
extern int SPI_exec(const char *src, long tcount);
extern int SPI_execp(void *plan, Datum *Values, const char *Nulls,
int tcount);
long tcount);
extern int SPI_execute_snapshot(void *plan,
Datum *Values, const char *Nulls,
Snapshot snapshot,
Snapshot crosscheck_snapshot,
bool read_only, int tcount);
bool read_only, long tcount);
extern void *SPI_prepare(const char *src, int nargs, Oid *argtypes);
extern void *SPI_saveplan(void *plan);
extern int SPI_freeplan(void *plan);
......@@ -123,8 +123,8 @@ extern void SPI_freetuptable(SPITupleTable *tuptable);
extern Portal SPI_cursor_open(const char *name, void *plan,
Datum *Values, const char *Nulls, bool read_only);
extern Portal SPI_cursor_find(const char *name);
extern void SPI_cursor_fetch(Portal portal, bool forward, int count);
extern void SPI_cursor_move(Portal portal, bool forward, int count);
extern void SPI_cursor_fetch(Portal portal, bool forward, long count);
extern void SPI_cursor_move(Portal portal, bool forward, long count);
extern void SPI_cursor_close(Portal portal);
extern void AtEOXact_SPI(bool isCommit);
......
......@@ -3,7 +3,7 @@
* procedural language
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.136 2005/05/01 18:56:19 tgl Exp $
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.137 2005/05/02 00:37:07 neilc Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
......@@ -158,7 +158,7 @@ static Datum exec_eval_expr(PLpgSQL_execstate *estate,
bool *isNull,
Oid *rettype);
static int exec_run_select(PLpgSQL_execstate *estate,
PLpgSQL_expr *expr, int maxtuples, Portal *portalP);
PLpgSQL_expr *expr, long maxtuples, Portal *portalP);
static void exec_move_row(PLpgSQL_execstate *estate,
PLpgSQL_rec *rec,
PLpgSQL_row *row,
......@@ -3482,7 +3482,7 @@ exec_eval_expr(PLpgSQL_execstate *estate,
*/
static int
exec_run_select(PLpgSQL_execstate *estate,
PLpgSQL_expr *expr, int maxtuples, Portal *portalP)
PLpgSQL_expr *expr, long maxtuples, Portal *portalP)
{
int i;
Datum *values;
......
......@@ -29,7 +29,7 @@
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.60 2005/03/29 00:17:24 tgl Exp $
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.61 2005/05/02 00:37:07 neilc Exp $
*
*********************************************************************
*/
......@@ -1546,8 +1546,8 @@ static int PLy_result_ass_slice(PyObject *, int, int, PyObject *);
static PyObject *PLy_spi_prepare(PyObject *, PyObject *);
static PyObject *PLy_spi_execute(PyObject *, PyObject *);
static PyObject *PLy_spi_execute_query(char *query, int limit);
static PyObject *PLy_spi_execute_plan(PyObject *, PyObject *, int);
static PyObject *PLy_spi_execute_query(char *query, long limit);
static PyObject *PLy_spi_execute_plan(PyObject *, PyObject *, long);
static PyObject *PLy_spi_execute_fetch_result(SPITupleTable *, int, int);
......@@ -1965,7 +1965,7 @@ PLy_spi_execute(PyObject * self, PyObject * args)
char *query;
PyObject *plan;
PyObject *list = NULL;
int limit = 0;
long limit = 0;
/* Can't execute more if we have an unhandled error */
if (PLy_error_in_progress)
......@@ -1974,12 +1974,12 @@ PLy_spi_execute(PyObject * self, PyObject * args)
return NULL;
}
if (PyArg_ParseTuple(args, "s|i", &query, &limit))
if (PyArg_ParseTuple(args, "s|l", &query, &limit))
return PLy_spi_execute_query(query, limit);
PyErr_Clear();
if ((PyArg_ParseTuple(args, "O|Oi", &plan, &list, &limit)) &&
if ((PyArg_ParseTuple(args, "O|Ol", &plan, &list, &limit)) &&
(is_PLyPlanObject(plan)))
return PLy_spi_execute_plan(plan, list, limit);
......@@ -1988,7 +1988,7 @@ PLy_spi_execute(PyObject * self, PyObject * args)
}
static PyObject *
PLy_spi_execute_plan(PyObject * ob, PyObject * list, int limit)
PLy_spi_execute_plan(PyObject * ob, PyObject * list, long limit)
{
volatile int nargs;
int i,
......@@ -2123,7 +2123,7 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, int limit)
}
static PyObject *
PLy_spi_execute_query(char *query, int limit)
PLy_spi_execute_query(char *query, long limit)
{
int rv;
MemoryContext oldcontext;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment