Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cursor not being created 1

Status
Not open for further replies.

BlackDice

Programmer
Mar 1, 2004
257
US
I have the following problem. I have an SQL statement something like this:

SELECT table1.field1,table1.field2 INTO CURSOR crsTest

when I use SET STEP ON and step through it in the code window, it returns no cursor at all. But if I go to the command window at that same point in the code and copy and paste the same code, it works and I can browse the cursor and everything. Is this a setting in FoxPro that I'm missing or something? I can't understand why it returns nothing in the code window, but works just fine in the command window. Any help is appreciated. Thanks in advance!

BlackDice

 
You missed FROM clause.
Code:
SELECT table1.field1,table1.field2 [b]FROM table1[/b] INTO CURSOR crsTest

Borislav Borissov
 
sorry, the 'FROM' clause is actually in the real sql statement, I just forgot it in my example. Like I said, it makes a cursor that I can browse if I enter the SELECT statement in the command window, but it doesn't work in the code window. It doesn't even return an empty cursor; the cursor is not created at all in code!

BlackDice

 
Try:
Code:
SELECT table1.field1,table1.field2 FROM table1 INTO CURSOR crsTest
SELECT crsTest
BROWSE NORMAL
in application, to see what happens.
By the way, did you have an error handler somewhere that suppress some error numbers?

You may try:
Code:
old_Error = ON("ERRROR")
ON ERROR
SELECT table1.field1,table1.field2 FROM table1 INTO CURSOR crsTest
SELECT crsTest
BROWSE NORMAL
ON ERROR &old_Error


Borislav Borissov
 
the line "SELECT crsTest" (in your example) doesn't work because that's where it crashes saying the cursor doesn't exist. I do get the error, but that's what it says. Immediately after creating the cursor, I put 'SELECT crsTest' on the next line and it blows up. I thought that even if the cursor contained no records that it should still exist! But directly after creating the cursor on the next line where I try to select it, it crashes saying it doesn't exist. I can stop execution right there and put the same line in the command window and execute it and then let it go to the next line and it goes through the 'SELECT crsTest' line just fine! Here is my actual code:

Code:
select &lcfields ;
FROM dride ;
left Join dtpprates On dtpprates.ratespk = dride.ratedtppfk ;
left Join dtpp On dtpp.tpppk = dtpprates.tppfk ;
left Join CRSCHOSEN On CRSCHOSEN.tpppk = dtpp.tpppk ;
left Join dpass On dpass.passpk = dride.passfk ;
left Join CLIENT On CLIENT.personid = dpass.personidfk ;
INTO Cursor crsbilling 

Select "crsbilling"

it crashes on the line 'Select "crsbilling"'




BlackDice

 
Remove the quotes whaen you do
SELECT crsBilling

And open the DataSession window at this point to see, if it was created and what's in there.

 
What is &lcfields?
A list of field names you want to select I suppose.
What happens if you change the command like this:
Code:
cSelectStat = "select "+lcfields +;
              " FROM dride "+;
              " left Join dtpprates On dtpprates.ratespk = dride.ratedtppfk "+;
              " left Join dtpp On dtpp.tpppk = dtpprates.tppfk "+;
              " left Join CRSCHOSEN On CRSCHOSEN.tpppk = dtpp.tpppk "+;
" left Join dpass On dpass.passpk = dride.passfk "+;
" left Join CLIENT On CLIENT.personid = dpass.personidfk "+;
" INTO Cursor crsbilling"

&cSelectStat


Borislav Borissov
 
bborissov, I tried that on Friday. even just putting one field name in there. what I don't understand is why it works when I copy and paste it in the command window?

Stella740p, there's other tables open, but that one is not listed in the datasession window. but it is when I stop execution right there and paste the exact same code in the command window and execute it!

I can't help but think that this is some type of setting in the VFP environment since I re-installed it a few days ago, and I've never had this type of problem before

BlackDice

 

Would it be any different if you use SUSPEND or DEBUG instead of SET STEP ON?
 
no. no difference. But I have found that if I select another cursor that DOES exist before executing the 'SELECT INTO CURSOR' statement, then it goes through just fine. even though this works, I don't want it to just work, I'd like to know why?

BlackDice

 

Well... Had something similar once - worked form command window, not from program in debug mode, then started to work after I put a ridiculous and redundant command in it. Don't remember what the problem was, but let's try to find out.

What was the command just before the SELECT statement?

Do you use CONFIG.FPW (or a similar configuration file) and what's in it?

How many work areas (tables/cursors) were you using before this one?

Can, by any chance, any of them have the same name as this one?
 

Oh, so you had another SELECT statement just before that one?

Can you show it?

Were you selecting from it in your next SELECT?

Was the previous one created OK?
 

In case I wasn't clear, what was the command preceding the SELECT-SQL (SELECT INTO CURSOR) originally?
 

Hm. A few thoughts then.

What is dride? Are you selecting from another cursor, also created by SELECT-SQL statement? If so, try to put NOFILTER clause in that statement (INTO CURSOR dride NOFILTER). Does it help?

If you stop the program to step in after the SELECT-SQL statement, not before, does it work then?

If, instead of doing SELECT crsBilling right after SELECT-SQL, you put BROWSE LAST command, what table comes up?
What if you check DBF() and ALIAS() after the SELECT-SQL?

And the fact that you SELECT INTO CURSOR right after going into another form could be the right way to dig. Does it overwrite or release some of your variables? Closes some tables somehow? Does it have Data Environment?
 
dride is an actual table. no it still doesn't work if I go into after the select statement. alias() shows a previously selected table. if I use dbf() on crsbilling, that doesn't work. the second form has no data environment. It creates two cursors of its own that aren't used in the first form in any way.

BlackDice

 

What about each of the tables/cursors in the JOINs?
Are any of the cursors created by SELECT-SQL? You can try NOFILTER on them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top