dbTalk Databases Forums  

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

comp.databases.xbase.fox comp.databases.xbase.fox


Discuss VFP 6: Getting a Writeable Cursor froma R/O Cursor in the comp.databases.xbase.fox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Gene Wirchenko
 
Posts: n/a

Default VFP 6: Getting a Writeable Cursor froma R/O Cursor - 06-27-2006 , 07:44 PM






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   
Fred Taylor
 
Posts: n/a

Default Re: VFP 6: Getting a Writeable Cursor froma R/O Cursor - 06-27-2006 , 08:25 PM






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" <genew (AT) ucantrade (DOT) com.NOTHERE> wrote

Quote:
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   
Bernhard Sander
 
Posts: n/a

Default Re: VFP 6: Getting a Writeable Cursor froma R/O Cursor - 06-28-2006 , 03:12 AM



Hi Gene,

Quote:
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   
Gene Wirchenko
 
Posts: n/a

Default Re: VFP 6: Getting a Writeable Cursor froma R/O Cursor - 06-28-2006 , 12:35 PM



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

On Wed, 28 Jun 2006 09:29:54 -0400, "Dan" <delliott (AT) midwestecoat (DOT) com>
wrote:

Quote:
"Gene Wirchenko" <genew (AT) ucantrade (DOT) com.NOTHERE> wrote in message
news:02k3a2l0dcllsclbnpopk8jn58mmai9mbt (AT) 4ax (DOT) 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   
Gene Wirchenko
 
Posts: n/a

Default Re: VFP 6: Getting a Writeable Cursor froma R/O Cursor - 06-28-2006 , 12:35 PM



[corrected deleted attribution]

On Wed, 28 Jun 2006 10:12:03 +0200, Bernhard Sander
<fuchs (AT) individsoft (DOT) de> wrote:

Quote:
[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.

Quote:
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.

Quote:
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   
Dan Freeman
 
Posts: n/a

Default Re: VFP 6: Getting a Writeable Cursor froma R/O Cursor - 06-28-2006 , 01:05 PM



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 <g>).

Dan

Gene Wirchenko wrote:
Quote:
[corrected deleted attribution]

On Wed, 28 Jun 2006 10:12:03 +0200, Bernhard Sander
fuchs (AT) individsoft (DOT) de> 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.