Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Andy Kramek
  Where is Andy Kramek?
 Hot Springs Village
 Arkansas - United States
 Andy Kramek
 To: Eric den Doop
  Where is Eric den Doop?
 Houten
 Netherlands
 Eric den Doop
 Tags
Subject: RE: beware of sql cursor read/write trick
Thread ID: 5535 Message ID: 228884 # Views: 3 # Ratings: 0
Version: Unknown Category: General VFP Topics
Date: Friday, May 22, 2009 12:20:59 PM         
   


> Hello,
>
> I think most of you know about the trick in VFP5/6 to read and write in a read only cursor:
>
> select yourfields from sometables where something = .T. into cursor readonlycursor
> select readonlycursor
> lcDbf = dbf()
> use (lcDbf) again alias newalias in 0
>
> -----
> now watch this:
>
> create table test (fielda C(2))
> for i = 1 to 10
> appe blan
> repl fielda with transf(i)
> endfor
> sele * from testtable into cursor testcursor
> sele testcursor
> ?alias() && as expected
> ?dbf() && as expected because VFP sets a filter on this simple query
> lcFile = dbf()
> use (lcFile) again alias cursorrw in 0
> sele cursorrw
> repl all fielda with "AA"
> ? 'contents of cursorrw'
> scan
> ? fielda
> endscan
> ? 'contents of testtable'
> sele testtable
> scan
> ? fielda
> endscan
>
> perhaps this is common knowledge, but I just thought I'd share this with you.
> --
> Eric den Doop
> www.foxite.com - The Home Of The Visual FoxPro Experts

Ummm, Eric, First I think you have an entirely separate issue - a typo here!

Your first line is "CREATE TABLE test" but your SQL is "SELE * FROM testtable INTO CURSOR testcursor", and later, "? 'contents of testtable' ...SELE testtable"

But your source is NOT name "testTable" it is "test" so not surprisingly the code gives an error. I can only assume you had a table named "testtable" lying around because when I run your code I get "Locate Table Dialog" on the first SQL SELECT (as expected!)

Second you are correct about the behavior - this is because VFP sets a filter by default insuch queries. The simple solution in earlier versions of VFP is to add a WHERE clause to your query like this:
SELECT * FROM testtable WHERE .T. INTO CURSOR testcursor

(Of course, in later versions you just use the NOFILTER clause in such queries)

Regards
Andy Kramek
Microsoft MVP (Visual FoxPro)
Tightline Computers Inc, Akron Ohio, USA

ENTIRE THREAD

beware of sql cursor read/write trick Posted by Eric den Doop @ 11/30/2001 8:46:00 PM
RE: beware of sql cursor read/write trick Posted by drCipher @ 11/30/2001 9:31:20 PM
RE: beware of sql cursor read/write trick Posted by Eric den Doop @ 11/30/2001 9:46:32 PM
RE: beware of sql cursor read/write trick Posted by Phisit Thaeochanthuek @ 5/22/2009 5:41:07 AM
RE: beware of sql cursor read/write trick Posted by Andy Kramek @ 5/22/2009 12:20:59 PM
RE: beware of sql cursor read/write trick Posted by Eric den Doop @ 5/22/2009 12:31:00 PM
RE: beware of sql cursor read/write trick Posted by tushar @ 5/22/2009 12:35:01 PM
RE: beware of sql cursor read/write trick Posted by Ammar Hadi @ 5/22/2009 4:41:25 PM
RE: beware of sql cursor read/write trick Posted by tushar @ 5/22/2009 6:29:46 PM