Skip to content

Commit f478856

Browse files
author
Neil Conway
committed
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.
1 parent 6c412f0 commit f478856

File tree

5 files changed

+49
-49
lines changed

5 files changed

+49
-49
lines changed

doc/src/sgml/spi.sgml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/spi.sgml,v 1.40 2005/03/29 02:53:53 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/spi.sgml,v 1.41 2005/05/02 00:37:06 neilc Exp $
33
-->
44

55
<chapter id="spi">
@@ -292,7 +292,7 @@ void SPI_pop(void)
292292

293293
<refsynopsisdiv>
294294
<synopsis>
295-
int SPI_execute(const char * <parameter>command</parameter>, bool <parameter>read_only</parameter>, int <parameter>count</parameter>)
295+
int SPI_execute(const char * <parameter>command</parameter>, bool <parameter>read_only</parameter>, long <parameter>count</parameter>)
296296
</synopsis>
297297
</refsynopsisdiv>
298298

@@ -423,7 +423,7 @@ typedef struct
423423
</varlistentry>
424424

425425
<varlistentry>
426-
<term><literal>int <parameter>count</parameter></literal></term>
426+
<term><literal>long <parameter>count</parameter></literal></term>
427427
<listitem>
428428
<para>
429429
maximum number of rows to process or return
@@ -598,7 +598,7 @@ typedef struct
598598

599599
<refsynopsisdiv>
600600
<synopsis>
601-
int SPI_exec(const char * <parameter>command</parameter>, int <parameter>count</parameter>)
601+
int SPI_exec(const char * <parameter>command</parameter>, long <parameter>count</parameter>)
602602
</synopsis>
603603
</refsynopsisdiv>
604604

@@ -627,7 +627,7 @@ int SPI_exec(const char * <parameter>command</parameter>, int <parameter>count</
627627
</varlistentry>
628628

629629
<varlistentry>
630-
<term><literal>int <parameter>count</parameter></literal></term>
630+
<term><literal>long <parameter>count</parameter></literal></term>
631631
<listitem>
632632
<para>
633633
maximum number of rows to process or return
@@ -963,7 +963,7 @@ bool SPI_is_cursor_plan(void * <parameter>plan</parameter>)
963963
<refsynopsisdiv>
964964
<synopsis>
965965
int SPI_execute_plan(void * <parameter>plan</parameter>, Datum * <parameter>values</parameter>, const char * <parameter>nulls</parameter>,
966-
bool <parameter>read_only</parameter>, int <parameter>count</parameter>)
966+
bool <parameter>read_only</parameter>, long <parameter>count</parameter>)
967967
</synopsis>
968968
</refsynopsisdiv>
969969

@@ -1030,7 +1030,7 @@ int SPI_execute_plan(void * <parameter>plan</parameter>, Datum * <parameter>valu
10301030
</varlistentry>
10311031

10321032
<varlistentry>
1033-
<term><literal>int <parameter>count</parameter></literal></term>
1033+
<term><literal>long <parameter>count</parameter></literal></term>
10341034
<listitem>
10351035
<para>
10361036
maximum number of rows to process or return
@@ -1104,7 +1104,7 @@ int SPI_execute_plan(void * <parameter>plan</parameter>, Datum * <parameter>valu
11041104

11051105
<refsynopsisdiv>
11061106
<synopsis>
1107-
int SPI_execp(void * <parameter>plan</parameter>, Datum * <parameter>values</parameter>, const char * <parameter>nulls</parameter>, int <parameter>count</parameter>)
1107+
int SPI_execp(void * <parameter>plan</parameter>, Datum * <parameter>values</parameter>, const char * <parameter>nulls</parameter>, long <parameter>count</parameter>)
11081108
</synopsis>
11091109
</refsynopsisdiv>
11101110

@@ -1162,7 +1162,7 @@ int SPI_execp(void * <parameter>plan</parameter>, Datum * <parameter>values</par
11621162
</varlistentry>
11631163

11641164
<varlistentry>
1165-
<term><literal>int <parameter>count</parameter></literal></term>
1165+
<term><literal>long <parameter>count</parameter></literal></term>
11661166
<listitem>
11671167
<para>
11681168
maximum number of rows to process or return
@@ -1375,7 +1375,7 @@ Portal SPI_cursor_find(const char * <parameter>name</parameter>)
13751375

13761376
<refsynopsisdiv>
13771377
<synopsis>
1378-
void SPI_cursor_fetch(Portal <parameter>portal</parameter>, bool <parameter>forward</parameter>, int <parameter>count</parameter>)
1378+
void SPI_cursor_fetch(Portal <parameter>portal</parameter>, bool <parameter>forward</parameter>, long <parameter>count</parameter>)
13791379
</synopsis>
13801380
</refsynopsisdiv>
13811381

@@ -1411,7 +1411,7 @@ void SPI_cursor_fetch(Portal <parameter>portal</parameter>, bool <parameter>forw
14111411
</varlistentry>
14121412

14131413
<varlistentry>
1414-
<term><literal>int <parameter>count</parameter></literal></term>
1414+
<term><literal>long <parameter>count</parameter></literal></term>
14151415
<listitem>
14161416
<para>
14171417
maximum number of rows to fetch
@@ -1448,7 +1448,7 @@ void SPI_cursor_fetch(Portal <parameter>portal</parameter>, bool <parameter>forw
14481448

14491449
<refsynopsisdiv>
14501450
<synopsis>
1451-
void SPI_cursor_move(Portal <parameter>portal</parameter>, bool <parameter>forward</parameter>, int <parameter>count</parameter>)
1451+
void SPI_cursor_move(Portal <parameter>portal</parameter>, bool <parameter>forward</parameter>, long <parameter>count</parameter>)
14521452
</synopsis>
14531453
</refsynopsisdiv>
14541454

@@ -1485,7 +1485,7 @@ void SPI_cursor_move(Portal <parameter>portal</parameter>, bool <parameter>forwa
14851485
</varlistentry>
14861486

14871487
<varlistentry>
1488-
<term><literal>int <parameter>count</parameter></literal></term>
1488+
<term><literal>long <parameter>count</parameter></literal></term>
14891489
<listitem>
14901490
<para>
14911491
maximum number of rows to move

src/backend/executor/spi.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.138 2005/05/01 18:56:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.139 2005/05/02 00:37:06 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -39,13 +39,13 @@ static void _SPI_prepare_plan(const char *src, _SPI_plan *plan);
3939
static int _SPI_execute_plan(_SPI_plan *plan,
4040
Datum *Values, const char *Nulls,
4141
Snapshot snapshot, Snapshot crosscheck_snapshot,
42-
bool read_only, int tcount);
42+
bool read_only, long tcount);
4343

44-
static int _SPI_pquery(QueryDesc *queryDesc, int tcount);
44+
static int _SPI_pquery(QueryDesc *queryDesc, long tcount);
4545

4646
static void _SPI_error_callback(void *arg);
4747

48-
static void _SPI_cursor_operation(Portal portal, bool forward, int count,
48+
static void _SPI_cursor_operation(Portal portal, bool forward, long count,
4949
DestReceiver *dest);
5050

5151
static _SPI_plan *_SPI_copy_plan(_SPI_plan *plan, int location);
@@ -278,9 +278,9 @@ SPI_restore_connection(void)
278278
_SPI_curid = _SPI_connected - 1;
279279
}
280280

281-
/* Parse, plan, and execute a querystring */
281+
/* Parse, plan, and execute a query string */
282282
int
283-
SPI_execute(const char *src, bool read_only, int tcount)
283+
SPI_execute(const char *src, bool read_only, long tcount)
284284
{
285285
_SPI_plan plan;
286286
int res;
@@ -309,15 +309,15 @@ SPI_execute(const char *src, bool read_only, int tcount)
309309

310310
/* Obsolete version of SPI_execute */
311311
int
312-
SPI_exec(const char *src, int tcount)
312+
SPI_exec(const char *src, long tcount)
313313
{
314314
return SPI_execute(src, false, tcount);
315315
}
316316

317317
/* Execute a previously prepared plan */
318318
int
319319
SPI_execute_plan(void *plan, Datum *Values, const char *Nulls,
320-
bool read_only, int tcount)
320+
bool read_only, long tcount)
321321
{
322322
int res;
323323

@@ -342,7 +342,7 @@ SPI_execute_plan(void *plan, Datum *Values, const char *Nulls,
342342

343343
/* Obsolete version of SPI_execute_plan */
344344
int
345-
SPI_execp(void *plan, Datum *Values, const char *Nulls, int tcount)
345+
SPI_execp(void *plan, Datum *Values, const char *Nulls, long tcount)
346346
{
347347
return SPI_execute_plan(plan, Values, Nulls, false, tcount);
348348
}
@@ -360,7 +360,7 @@ int
360360
SPI_execute_snapshot(void *plan,
361361
Datum *Values, const char *Nulls,
362362
Snapshot snapshot, Snapshot crosscheck_snapshot,
363-
bool read_only, int tcount)
363+
bool read_only, long tcount)
364364
{
365365
int res;
366366

@@ -979,7 +979,7 @@ SPI_cursor_find(const char *name)
979979
* Fetch rows in a cursor
980980
*/
981981
void
982-
SPI_cursor_fetch(Portal portal, bool forward, int count)
982+
SPI_cursor_fetch(Portal portal, bool forward, long count)
983983
{
984984
_SPI_cursor_operation(portal, forward, count,
985985
CreateDestReceiver(SPI, NULL));
@@ -993,7 +993,7 @@ SPI_cursor_fetch(Portal portal, bool forward, int count)
993993
* Move in a cursor
994994
*/
995995
void
996-
SPI_cursor_move(Portal portal, bool forward, int count)
996+
SPI_cursor_move(Portal portal, bool forward, long count)
997997
{
998998
_SPI_cursor_operation(portal, forward, count, None_Receiver);
999999
}
@@ -1309,7 +1309,7 @@ _SPI_prepare_plan(const char *src, _SPI_plan *plan)
13091309
static int
13101310
_SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls,
13111311
Snapshot snapshot, Snapshot crosscheck_snapshot,
1312-
bool read_only, int tcount)
1312+
bool read_only, long tcount)
13131313
{
13141314
volatile int res = 0;
13151315
Snapshot saveActiveSnapshot;
@@ -1493,7 +1493,7 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls,
14931493
}
14941494

14951495
static int
1496-
_SPI_pquery(QueryDesc *queryDesc, int tcount)
1496+
_SPI_pquery(QueryDesc *queryDesc, long tcount)
14971497
{
14981498
int operation = queryDesc->operation;
14991499
int res;
@@ -1531,7 +1531,7 @@ _SPI_pquery(QueryDesc *queryDesc, int tcount)
15311531

15321532
ExecutorStart(queryDesc, false);
15331533

1534-
ExecutorRun(queryDesc, ForwardScanDirection, (long) tcount);
1534+
ExecutorRun(queryDesc, ForwardScanDirection, tcount);
15351535

15361536
_SPI_current->processed = queryDesc->estate->es_processed;
15371537
save_lastoid = queryDesc->estate->es_lastoid;
@@ -1599,7 +1599,7 @@ _SPI_error_callback(void *arg)
15991599
* Do a FETCH or MOVE in a cursor
16001600
*/
16011601
static void
1602-
_SPI_cursor_operation(Portal portal, bool forward, int count,
1602+
_SPI_cursor_operation(Portal portal, bool forward, long count,
16031603
DestReceiver *dest)
16041604
{
16051605
long nfetched;
@@ -1621,7 +1621,7 @@ _SPI_cursor_operation(Portal portal, bool forward, int count,
16211621
/* Run the cursor */
16221622
nfetched = PortalRunFetch(portal,
16231623
forward ? FETCH_FORWARD : FETCH_BACKWARD,
1624-
(long) count,
1624+
count,
16251625
dest);
16261626

16271627
/*

src/include/executor/spi.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* spi.h
44
*
5-
* $PostgreSQL: pgsql/src/include/executor/spi.h,v 1.51 2005/03/29 02:53:53 neilc Exp $
5+
* $PostgreSQL: pgsql/src/include/executor/spi.h,v 1.52 2005/05/02 00:37:06 neilc Exp $
66
*
77
*-------------------------------------------------------------------------
88
*/
@@ -82,17 +82,17 @@ extern int SPI_finish(void);
8282
extern void SPI_push(void);
8383
extern void SPI_pop(void);
8484
extern void SPI_restore_connection(void);
85-
extern int SPI_execute(const char *src, bool read_only, int tcount);
85+
extern int SPI_execute(const char *src, bool read_only, long tcount);
8686
extern int SPI_execute_plan(void *plan, Datum *Values, const char *Nulls,
87-
bool read_only, int tcount);
88-
extern int SPI_exec(const char *src, int tcount);
87+
bool read_only, long tcount);
88+
extern int SPI_exec(const char *src, long tcount);
8989
extern int SPI_execp(void *plan, Datum *Values, const char *Nulls,
90-
int tcount);
90+
long tcount);
9191
extern int SPI_execute_snapshot(void *plan,
9292
Datum *Values, const char *Nulls,
9393
Snapshot snapshot,
9494
Snapshot crosscheck_snapshot,
95-
bool read_only, int tcount);
95+
bool read_only, long tcount);
9696
extern void *SPI_prepare(const char *src, int nargs, Oid *argtypes);
9797
extern void *SPI_saveplan(void *plan);
9898
extern int SPI_freeplan(void *plan);
@@ -123,8 +123,8 @@ extern void SPI_freetuptable(SPITupleTable *tuptable);
123123
extern Portal SPI_cursor_open(const char *name, void *plan,
124124
Datum *Values, const char *Nulls, bool read_only);
125125
extern Portal SPI_cursor_find(const char *name);
126-
extern void SPI_cursor_fetch(Portal portal, bool forward, int count);
127-
extern void SPI_cursor_move(Portal portal, bool forward, int count);
126+
extern void SPI_cursor_fetch(Portal portal, bool forward, long count);
127+
extern void SPI_cursor_move(Portal portal, bool forward, long count);
128128
extern void SPI_cursor_close(Portal portal);
129129

130130
extern void AtEOXact_SPI(bool isCommit);

src/pl/plpgsql/src/pl_exec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.136 2005/05/01 18:56:19 tgl Exp $
6+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.137 2005/05/02 00:37:07 neilc Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -158,7 +158,7 @@ static Datum exec_eval_expr(PLpgSQL_execstate *estate,
158158
bool *isNull,
159159
Oid *rettype);
160160
static int exec_run_select(PLpgSQL_execstate *estate,
161-
PLpgSQL_expr *expr, int maxtuples, Portal *portalP);
161+
PLpgSQL_expr *expr, long maxtuples, Portal *portalP);
162162
static void exec_move_row(PLpgSQL_execstate *estate,
163163
PLpgSQL_rec *rec,
164164
PLpgSQL_row *row,
@@ -3482,7 +3482,7 @@ exec_eval_expr(PLpgSQL_execstate *estate,
34823482
*/
34833483
static int
34843484
exec_run_select(PLpgSQL_execstate *estate,
3485-
PLpgSQL_expr *expr, int maxtuples, Portal *portalP)
3485+
PLpgSQL_expr *expr, long maxtuples, Portal *portalP)
34863486
{
34873487
int i;
34883488
Datum *values;

src/pl/plpython/plpython.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
3030
*
3131
* IDENTIFICATION
32-
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.60 2005/03/29 00:17:24 tgl Exp $
32+
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.61 2005/05/02 00:37:07 neilc Exp $
3333
*
3434
*********************************************************************
3535
*/
@@ -1546,8 +1546,8 @@ static int PLy_result_ass_slice(PyObject *, int, int, PyObject *);
15461546

15471547
static PyObject *PLy_spi_prepare(PyObject *, PyObject *);
15481548
static PyObject *PLy_spi_execute(PyObject *, PyObject *);
1549-
static PyObject *PLy_spi_execute_query(char *query, int limit);
1550-
static PyObject *PLy_spi_execute_plan(PyObject *, PyObject *, int);
1549+
static PyObject *PLy_spi_execute_query(char *query, long limit);
1550+
static PyObject *PLy_spi_execute_plan(PyObject *, PyObject *, long);
15511551
static PyObject *PLy_spi_execute_fetch_result(SPITupleTable *, int, int);
15521552

15531553

@@ -1965,7 +1965,7 @@ PLy_spi_execute(PyObject * self, PyObject * args)
19651965
char *query;
19661966
PyObject *plan;
19671967
PyObject *list = NULL;
1968-
int limit = 0;
1968+
long limit = 0;
19691969

19701970
/* Can't execute more if we have an unhandled error */
19711971
if (PLy_error_in_progress)
@@ -1974,12 +1974,12 @@ PLy_spi_execute(PyObject * self, PyObject * args)
19741974
return NULL;
19751975
}
19761976

1977-
if (PyArg_ParseTuple(args, "s|i", &query, &limit))
1977+
if (PyArg_ParseTuple(args, "s|l", &query, &limit))
19781978
return PLy_spi_execute_query(query, limit);
19791979

19801980
PyErr_Clear();
19811981

1982-
if ((PyArg_ParseTuple(args, "O|Oi", &plan, &list, &limit)) &&
1982+
if ((PyArg_ParseTuple(args, "O|Ol", &plan, &list, &limit)) &&
19831983
(is_PLyPlanObject(plan)))
19841984
return PLy_spi_execute_plan(plan, list, limit);
19851985

@@ -1988,7 +1988,7 @@ PLy_spi_execute(PyObject * self, PyObject * args)
19881988
}
19891989

19901990
static PyObject *
1991-
PLy_spi_execute_plan(PyObject * ob, PyObject * list, int limit)
1991+
PLy_spi_execute_plan(PyObject * ob, PyObject * list, long limit)
19921992
{
19931993
volatile int nargs;
19941994
int i,
@@ -2123,7 +2123,7 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, int limit)
21232123
}
21242124

21252125
static PyObject *
2126-
PLy_spi_execute_query(char *query, int limit)
2126+
PLy_spi_execute_query(char *query, long limit)
21272127
{
21282128
int rv;
21292129
MemoryContext oldcontext;

0 commit comments

Comments
 (0)