dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

VFP 6: Getting a Writeable Cursor froma R/O Cursor - xbase

This is a discussion on VFP 6: Getting a Writeable Cursor froma R/O Cursor - xbase ; I have a R/O cursor that is an extract from a table. I need it to be R/W so I can run some a what-if scenario on it. I would rather not create a table since I do not want ...


Home > Database Forum > Other Databases > xbase > VFP 6: Getting a Writeable Cursor froma R/O Cursor

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 06-27-2006, 08:44 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default VFP 6: Getting a Writeable Cursor froma R/O Cursor

I have a R/O cursor that is an extract from a table. I need it
to be R/W so I can run some a what-if scenario on it. I would rather
not create a table since I do not want to keep the data. How can I
create a R/W version of the cursor that I have?

Failing that, how can I create a R/W extract from a table? (The
original table must not be modified by the subsequent writes.)

Sincerely,

Gene Wirchenko

Reply With Quote
  #2  
Old 06-27-2006, 09:25 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: VFP 6: Getting a Writeable Cursor froma R/O Cursor

You can use this against a SQL SELECT R/O cursor :

*
* From BostonComputerNewsNetwork @NJ Fox-user 6-22-94
*+
*PURPOSE:
* To Make SQL read-only cursor into R/W cursor
* Must be real file not filtered view
*
*SYNTAX:
* m.retstat = mkcursrw(m.cn)
*PARAMETERS:
* m.cn -(C) Cursor alias name to be made read/writable.
*
*RETURNS:
* m.retstat -(L) .t. made the read-only cursor to R/W cursor.
* .f. the cursor alias name does not correspend
* to a cursor.
*REMARKS:
*SEE ALSO:
*-
*
FUNCTION mkcursrw
PARAMETER m.cn
PRIVATE m.cf, m.retstat
m.cf = DBF(m.cn)
IF ".TMP"=RIGHT(m.cf,4)
USE (m.cf) AGAIN IN 0 ALIAS dummycname
USE IN (m.cn)
USE (m.cf) AGAIN IN 0 ALIAS (m.cn)
USE IN dummycname
SELECT (m.cn)
m.retstat = .t.
ELSE
m.retstat = .f.
ENDIF
RETURN m.retstat


--
Fred
Microsoft Visual FoxPro MVP


"Gene Wirchenko" wrote in message
news:02k3a2l0dcllsclbnpopk8jn58mmai9mbt@4ax.com...
> I have a R/O cursor that is an extract from a table. I need it
> to be R/W so I can run some a what-if scenario on it. I would rather
> not create a table since I do not want to keep the data. How can I
> create a R/W version of the cursor that I have?
>
> Failing that, how can I create a R/W extract from a table? (The
> original table must not be modified by the subsequent writes.)
>
> Sincerely,
>
> Gene Wirchenko
>



Reply With Quote
  #3  
Old 06-28-2006, 04:12 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: VFP 6: Getting a Writeable Cursor froma R/O Cursor

Hi Gene,

> I have a R/O cursor that is an extract from a table. I need it
> to be R/W so I can run some a what-if scenario on it. I would rather
> not create a table since I do not want to keep the data. How can I
> create a R/W version of the cursor that I have?

R/O cursors mostly are hidden filters on the original table.
If you add a dummy field to the field list, then Foxpro mostly builds a separate
cursor which is writable.
Something like
SELECT *, "" as dummy FROM ... INTO CURSOR ...
should do the trick.
Another way:
CREATE a new cursor from the structure of your R/O cursor and append the rows
from R/O cursor.

Regards
Bernhard Sander
Reply With Quote
  #4  
Old 06-28-2006, 01:35 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: VFP 6: Getting a Writeable Cursor froma R/O Cursor

[readded comp.databases.xbase.fox]
[reordered to chronological]

On Wed, 28 Jun 2006 09:29:54 -0400, "Dan"
wrote:

>"Gene Wirchenko" wrote in message
>news:02k3a2l0dcllsclbnpopk8jn58mmai9mbt@4ax.com...
>> I have a R/O cursor that is an extract from a table. I need it
>> to be R/W so I can run some a what-if scenario on it. I would rather
>> not create a table since I do not want to keep the data. How can I
>> create a R/W version of the cursor that I have?
>>
>> Failing that, how can I create a R/W extract from a table? (The
>> original table must not be modified by the subsequent writes.)


>This is what I used to do when I used VFP6.
>
>*--Create cursor
>SELECT * FROM Temp INTO CURSOR ReadOnlyCursor
>
>*--Put structure of cursor into array
>AFIELDS(laStruc, "ReadOnlyCursor")
>
>*--Create new cursor from structure array, new cursor will be read/write
>CREATE CURSOR ReadWriteCursor FROM ARRAY laStruc
>
>*--Append records from read only cursor
>APPEND FROM DBF("ReadOnlyCursor")


This worked nicely. Thank you.

Sincerely,

Gene Wirchenko

Reply With Quote
  #5  
Old 06-28-2006, 01:35 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: VFP 6: Getting a Writeable Cursor froma R/O Cursor

[corrected deleted attribution]

On Wed, 28 Jun 2006 10:12:03 +0200, Bernhard Sander
wrote:

>[Gene Wirchenko:]
>> I have a R/O cursor that is an extract from a table. I need it
>> to be R/W so I can run some a what-if scenario on it. I would rather
>> not create a table since I do not want to keep the data. How can I
>> create a R/W version of the cursor that I have?

>R/O cursors mostly are hidden filters on the original table.


No. I created the cursor with nofilter. This from the VFP 6
On-line Docs:

CURSOR CursorName [NOFILTER], which stores query results in a cursor.
If you specify the name of an open table, Visual FoxPro generates an
error message. After SELECT is executed, the temporary cursor remains
open and is active but is read-only. Once you close this temporary
cursor, it is deleted. Cursors may exist as a temporary file on the
drive or volume specified by SORTWORK.

Why the cursor ends up R/O makes no sense to me, but that is how
it is documented and how VFP 6 behaves.

>If you add a dummy field to the field list, then Foxpro mostly builds a separate
>cursor which is writable.
>Something like
>SELECT *, "" as dummy FROM ... INTO CURSOR ...
>should do the trick.


It did not work for me. VFP said that the cursor was R/O. This
is an old trick to avoid a filter.

>Another way:
>CREATE a new cursor from the structure of your R/O cursor and append the rows
>from R/O cursor.


That did work. Someone posted code for this.

Sincerely,

Gene Wirchenko

Reply With Quote
  #6  
Old 06-28-2006, 02:05 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: VFP 6: Getting a Writeable Cursor froma R/O Cursor

You can also get a read-write cursor from a read-only cursor like this:

Use DBF("read-only-alias") Again Alias RWCursor

It's completely undocumented, but it still works in VFP9 (where it's also
unnecessary ).

Dan

Gene Wirchenko wrote:
> [corrected deleted attribution]
>
> On Wed, 28 Jun 2006 10:12:03 +0200, Bernhard Sander
> wrote:
>
>> [Gene Wirchenko:]
>>> I have a R/O cursor that is an extract from a table. I need it
>>> to be R/W so I can run some a what-if scenario on it. I would
>>> rather not create a table since I do not want to keep the data.
>>> How can I create a R/W version of the cursor that I have?

>> R/O cursors mostly are hidden filters on the original table.

>
> No. I created the cursor with nofilter. This from the VFP 6
> On-line Docs:
>
> CURSOR CursorName [NOFILTER], which stores query results in a cursor.
> If you specify the name of an open table, Visual FoxPro generates an
> error message. After SELECT is executed, the temporary cursor remains
> open and is active but is read-only. Once you close this temporary
> cursor, it is deleted. Cursors may exist as a temporary file on the
> drive or volume specified by SORTWORK.
>
> Why the cursor ends up R/O makes no sense to me, but that is how
> it is documented and how VFP 6 behaves.
>
>> If you add a dummy field to the field list, then Foxpro mostly
>> builds a separate cursor which is writable.
>> Something like
>> SELECT *, "" as dummy FROM ... INTO CURSOR ...
>> should do the trick.

>
> It did not work for me. VFP said that the cursor was R/O. This
> is an old trick to avoid a filter.
>
>> Another way:
>> CREATE a new cursor from the structure of your R/O cursor and append
>> the rows from R/O cursor.

>
> That did work. Someone posted code for this.
>
> Sincerely,
>
> Gene Wirchenko



Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 12:50 PM.