We help IT Professionals succeed at work.
Get Started

Goalposts Moved on VFP Cursors?

Mike Jacobs
Mike Jacobs asked
on
186 Views
Last Modified: 2020-01-07
I appear to have a deep misunderstanding of how VFP cursors work

My code is littered with examples like this as the quickest way to establish the presence of a record meeting arbitrary conditions where a simple INDEXSEEK isn't appropriate

SELECT * FROM (ANYTABLE) WHERE (ANYCONDITION) INTO CURSOR 'JUNK'
IF RECCOUNT('JUNK')>0
      DO SOMETHING
ELSE
      DO SOMETHING_ELSE
ENDIF

This has worked for years.
Suddenly it doesn't.

I was so shocked, I assumed that either my data or my VFP installation had become corrupt.

I eliminated the former by trying it on various different tables from different sources

I eliminated the latter by first, thoroughly uninstalling all traces of VFP, then reinstalling it.

Then repeating the experiment on two other workstations where I had VFP installed.

The result is consistent.

What actually happens is that the Cursor is created with a filter matching (ANYCONDITION) and, if you're running this from a command line, for a few seconds you see the result you expect (eg 0 Records if you know that no records match the condition)  but then the status bar displays the name of the Cursor, its table of origin and the result count followed by RECCOUNT() of the original table (and now Cursor) (eg "Junk (path to table) Record 1/(RECCOUNT('ANYTABLE')") . The cursor is displaying the result count because it is now in a filter which matches ANYCONDITION.  But if I clear the filter (SET FILTER TO) what I have is a full copy of (ANYTABLE) in cursor JUNK.

In contrast, if, instead of  INTO CURSOR 'JUNK' I use INTO DBF 'JUNK' the results are exactly what I expect.

So

1 am I deluded in my expectation that the contents of CURSOR should be identical to the contents of the DBF equivalent?

2 If so, how on earth have I been getting away with it up to now? My software has often depended on this simple test and up till about a week ago neither I nor my clients have ever encountered a problem resulting from the use of such code

3 If not (i.e. we all agree that CURSORS should behave in accord with my prior expectations) how on earth could this behaviour change, simultaneously, on 3 different VFP workstations? (which don't even have the same version of Windows 10 running)
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE