|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * 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 $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -65,7 +65,7 @@ PortalCleanup(Portal portal)
|
65 | 65 | void
|
66 | 66 | PerformPortalFetch(char*name,
|
67 | 67 | boolforward,
|
68 |
| -intcount, |
| 68 | +longcount, |
69 | 69 | CommandDestdest,
|
70 | 70 | char*completionTag)
|
71 | 71 | {
|
@@ -100,14 +100,48 @@ PerformPortalFetch(char *name,
|
100 | 100 | return;
|
101 | 101 | }
|
102 | 102 |
|
103 |
| -/* If zero count,we are done */ |
| 103 | +/* If zero count,handle specially */ |
104 | 104 | 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 | +} |
106 | 140 |
|
107 | 141 | /* Internally, zero count processes all portal rows */
|
108 |
| -if (count==INT_MAX) |
| 142 | +if (count==LONG_MAX) |
109 | 143 | count=0;
|
110 |
| -
|
| 144 | + |
111 | 145 | /*
|
112 | 146 | * switch into the portal context
|
113 | 147 | */
|
|