Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit33f0108

Browse files
committed
Cause FETCH 1 to return the current cursor row, or zero if at
beginning/end of cursor.Have MOVE return 0/1 depending on cursor position.Matches SQL spec.Pass cursor counter from parser as a long rather than int.Doc updates.
1 parenta0fa011 commit33f0108

File tree

7 files changed

+56
-57
lines changed

7 files changed

+56
-57
lines changed

‎doc/src/sgml/ref/fetch.sgml

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/fetch.sgml,v 1.21 2002/04/21 19:02:39 thomas Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/fetch.sgml,v 1.22 2002/12/30 15:31:47 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -89,7 +89,7 @@ FETCH [ FORWARD | BACKWARD | RELATIVE ] [ <replaceable class="PARAMETER">#</repl
8989
<para>
9090
A signed integer that specifies how many rows to fetch.
9191
Note that a negative integer is equivalent to changing the sense of
92-
FORWARD and BACKWARD.
92+
FORWARD and BACKWARD. Zero re-fetches the current row.
9393
</para>
9494
</listitem>
9595
</varlistentry>
@@ -180,30 +180,6 @@ WARNING: FETCH/ABSOLUTE not supported, using RELATIVE
180180
</listitem>
181181
</varlistentry>
182182

183-
<varlistentry>
184-
<term><computeroutput>
185-
ERROR: FETCH/RELATIVE at current position is not supported
186-
</computeroutput></term>
187-
<listitem>
188-
<para>
189-
<acronym>SQL92</acronym> allows one to repetitively retrieve the cursor
190-
at its <quote>current position</quote> using the syntax
191-
<synopsis>
192-
FETCH RELATIVE 0 FROM <replaceable class="PARAMETER">cursor</replaceable>.
193-
</synopsis>
194-
</para>
195-
196-
<para>
197-
<productname>PostgreSQL</productname> does not currently support
198-
this notion; in fact the value zero is reserved to indicate that
199-
all rows should be retrieved and is equivalent to specifying the ALL keyword.
200-
If the RELATIVE keyword has been used, <productname>PostgreSQL</productname>
201-
assumes that the user intended <acronym>SQL92</acronym> behavior
202-
and returns this error message.
203-
</para>
204-
</listitem>
205-
</varlistentry>
206-
207183
</variablelist>
208184
</para>
209185
</refsect2>

‎doc/src/sgml/ref/move.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/move.sgml,v 1.14 2002/11/13 00:44:08 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/move.sgml,v 1.15 2002/12/30 15:31:47 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -35,8 +35,8 @@ MOVE [ <replaceable class="PARAMETER">direction</replaceable> ]
3535
Description
3636
</title>
3737
<para>
38-
<command>MOVE</command> allows a user to move cursor position aspecified
39-
number of rows.
38+
<command>MOVE</command> allows a user to movethecursor position a
39+
specifiednumber of rows.
4040
<command>MOVE</command> works like the <command>FETCH</command> command,
4141
but only positions the cursor and does not return rows.
4242
<replaceable class="PARAMETER">LAST</replaceable> moves to the end

‎src/backend/commands/portalcmds.c

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.6 2002/12/15 16:17:42 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.7 2002/12/30 15:31:47 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -65,7 +65,7 @@ PortalCleanup(Portal portal)
6565
void
6666
PerformPortalFetch(char*name,
6767
boolforward,
68-
intcount,
68+
longcount,
6969
CommandDestdest,
7070
char*completionTag)
7171
{
@@ -100,14 +100,48 @@ PerformPortalFetch(char *name,
100100
return;
101101
}
102102

103-
/* If zero count,we are done */
103+
/* If zero count,handle specially */
104104
if (count==0)
105-
return;
105+
{
106+
boolon_row= false;
107+
108+
/* Are we sitting on a row? */
109+
oldcontext=MemoryContextSwitchTo(PortalGetHeapMemory(portal));
110+
queryDesc=PortalGetQueryDesc(portal);
111+
estate=queryDesc->estate;
112+
if (portal->atStart== false&&portal->atEnd== false)
113+
on_row= true;
114+
MemoryContextSwitchTo(oldcontext);
115+
116+
if (dest==None)
117+
{
118+
/* MOVE 0 returns 0/1 based on if FETCH 0 would return a row */
119+
if (completionTag&&on_row)
120+
strcpy(completionTag,"MOVE 1");
121+
return;
122+
}
123+
else
124+
{
125+
/* If we are not on a row, FETCH 0 returns nothing */
126+
if (!on_row)
127+
return;
128+
129+
/* Since we are sitting on a row, return the row */
130+
/* Back up so we can reread the row */
131+
PerformPortalFetch(name, false/* backward */,1,
132+
None,/* throw away output */
133+
NULL/* do not modify the command tag */);
134+
135+
/* Set up to fetch one row */
136+
count=1;
137+
forward= true;
138+
}
139+
}
106140

107141
/* Internally, zero count processes all portal rows */
108-
if (count==INT_MAX)
142+
if (count==LONG_MAX)
109143
count=0;
110-
144+
111145
/*
112146
* switch into the portal context
113147
*/

‎src/backend/parser/gram.y

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.388 2002/12/12 20:35:13 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.389 2002/12/30 15:31:47 momjian Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -2591,13 +2591,6 @@ comment_text:
25912591
FetchStmt:FETCH direction fetch_how_many from_in name
25922592
{
25932593
FetchStmt *n = makeNode(FetchStmt);
2594-
if ($2 == RELATIVE)
2595-
{
2596-
if ($3 ==0)
2597-
elog(ERROR,
2598-
"FETCH / RELATIVE at current position is not supported");
2599-
$2 = FORWARD;
2600-
}
26012594
if ($3 <0)
26022595
{
26032596
$3 = -$3;
@@ -2629,10 +2622,6 @@ FetchStmt:FETCH direction fetch_how_many from_in name
26292622
| FETCH direction from_in name
26302623
{
26312624
FetchStmt *n = makeNode(FetchStmt);
2632-
if ($2 == RELATIVE)
2633-
{
2634-
$2 = FORWARD;
2635-
}
26362625
n->direction =$2;
26372626
n->howMany =1;
26382627
n->portalname =$4;
@@ -2719,20 +2708,20 @@ FetchStmt:FETCH direction fetch_how_many from_in name
27192708

27202709
direction:FORWARD{$$ = FORWARD; }
27212710
| BACKWARD{$$ = BACKWARD; }
2722-
| RELATIVE{$$ =RELATIVE; }
2711+
| RELATIVE{$$ =FORWARD; }
27232712
| ABSOLUTE
27242713
{
27252714
elog(NOTICE,
27262715
"FETCH / ABSOLUTE not supported, using RELATIVE");
2727-
$$ =RELATIVE;
2716+
$$ =FORWARD;
27282717
}
27292718
;
27302719

27312720
fetch_how_many:
27322721
Iconst{$$ =$1; }
27332722
|'-' Iconst{$$ = -$2; }
2734-
| ALL{$$ =INT_MAX; }
2735-
| LAST{$$ =INT_MAX; }
2723+
| ALL{$$ =LONG_MAX; }
2724+
| LAST{$$ =LONG_MAX; }
27362725
| NEXT{$$ =1; }
27372726
| PRIOR{$$ = -1; }
27382727
;

‎src/backend/tcop/utility.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.185 2002/12/06 05:00:31 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.186 2002/12/30 15:31:48 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -257,7 +257,7 @@ ProcessUtility(Node *parsetree,
257257
FetchStmt*stmt= (FetchStmt*)parsetree;
258258
char*portalName=stmt->portalname;
259259
boolforward;
260-
intcount;
260+
longcount;
261261

262262
forward= (bool) (stmt->direction==FORWARD);
263263

‎src/include/commands/portalcmds.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: portalcmds.h,v 1.3 2002/11/13 00:44:09 momjian Exp $
10+
* $Id: portalcmds.h,v 1.4 2002/12/30 15:31:50 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -25,7 +25,7 @@
2525
*BadArg if forward invalid.
2626
*"ERROR" if portal not found.
2727
*/
28-
externvoidPerformPortalFetch(char*name,boolforward,intcount,
28+
externvoidPerformPortalFetch(char*name,boolforward,longcount,
2929
CommandDestdest,char*completionTag);
3030

3131
/*

‎src/include/nodes/parsenodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: parsenodes.h,v 1.223 2002/12/12 20:35:16 tgl Exp $
10+
* $Id: parsenodes.h,v 1.224 2002/12/30 15:31:51 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1198,7 +1198,7 @@ typedef struct FetchStmt
11981198
{
11991199
NodeTagtype;
12001200
intdirection;/* FORWARD or BACKWARD */
1201-
inthowMany;/* amount to fetch */
1201+
longhowMany;/* amount to fetch */
12021202
char*portalname;/* name of portal (cursor) */
12031203
boolismove;/* TRUE if MOVE */
12041204
}FetchStmt;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp