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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating CURSOR with a variable name 1

Status
Not open for further replies.

fmoore0001

Programmer
Dec 3, 2002
192
US
Guys, can you use a variable name for a CURSOR in SELECT? I have tried to use the following code:

DO CASE
CASE .og.option1.value = 1
SELECT client_id, trustor_id, status, ;
nam_sort, loan_no ;
FROM trustor ;
WHERE &whatkim ;
ORDER BY loan_no ;
INTO CURSOR &cTimifile
CASE .og.option2.value = 2
SELECT client_id, trustor_id, status, ;
nam_sort, loan_no ;
FROM trustor ;
WHERE &whatkim ;
ORDER BY nam_sort ;
INTO CURSOR &cTimifile
ENDCASE

where cTimifile is a variable set to a Unique file name just for the purposes of a sort. I want to use a unique name as multiple users may be using the same report system.

However, if I SELECT (cTimifile) and Browse thereafter, some other file (the current area) appears. Any idea why this is not working.

Frank
 

Sys(2015) or sys(3)

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Yes you may but I am not shure how usefull it may be.

Bear in mind that cursors are created on the users workstation and using a cursor name like cMyCursor will work just fine. Try it yourself. SELECT to a cursor, make this cursor your active work area and then do a ?dbf(). you should get something like c:\temp\8273wr.tmp

Jean


Jean
 

Bear in mind that cursors are created on the users workstation and using a cursor name like cMyCursor will work just fine. Try it yourself. SELECT to a cursor, make this cursor your active work area and then do a ?dbf(). you should get something like c:\temp\8273wr.tmp

I'm not sure I understand the problem. A temporary cursor does not create a table as DBF() would be looking for. If you need a proper DBF() answer use

Code:
cTimifile = sys(2015)
DO CASE
    CASE .og.option1.value = 1
        SELECT client_id, trustor_id, status, ;
                        nam_sort, loan_no ;
            FROM trustor ;
            WHERE &whatkim ;
            ORDER BY loan_no ;
            INTO CURSOR &cTimifile READWRITE
    CASE .og.option2.value = 2
        SELECT client_id, trustor_id, status, ;
                        nam_sort, loan_no ;
            FROM trustor ;
            WHERE &whatkim ;
            ORDER BY nam_sort ;
            INTO CURSOR &cTimifile READWRITE
    ENDCASE
SELECT (cTimifile)
? DBF()


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
I guess was I not clear. What I am doing is working in a multiuser environment, and several people could be in at a time. So, I cannot use a fixed file name. I was trying to use:

cCursorfile = SYS(2015)
*
*
Select
*
*
INTO &cCursorfile

OR

INTO (cCursorfile)

but doing a

SELECT (cCursorfile)
? DBF()

write afterward shows that the cCursorfile value is NOT being created. Any ideas. What I really need to do is to have a CURSOR opened, and then be able to know the path to it to select.

Frank
 
Hi Mike,

Frank is using macro substitution because he wants to avoid name conflit in a multi-user environment. SELECT TO CURSOR creates a temporary table on the user's machine. This temporary table is created in the temp directory of the workstation. Since this temporary table is created on the workstation and not on the server, name conflict is not an issue and Frank can use safely SELECT * FROM myTable INTO CURSOR myCursor without macro substitution.






Jean
 
Hi Frank,


If you still want to use macro substitution try this

cCursorfile = SYS(2015)

Select ...
INTO CURSOR &cCursorfile

SELECT cCursorfile
? DBF()

Jean

Jean
 
Jean, my exact code. Doesn't work on my machine. If the CURSOR name is hard coded, fine. If I try the macro substitution, doesn't create it. Using Fox 7.0

Frank
 
Frank,

You`re right, Replace the last statement by

SELECT &cCursorFile.
?DBF()


You will get the fully qualified name of the temp file.



Jean

Jean
 
That appears to be my problem. The cursor file via a variable is NEVER created, and thus not accessable.

Frank
 
fmoore0001
That appears to be my problem. The cursor file via a variable is NEVER created, and thus not accessable.

Did you try the READWRITE clause?

Jean

Frank is using macro substitution because he wants to avoid name conflit in a multi-user environment. SELECT TO CURSOR creates a temporary table on the user's machine.

I know that, but I still don't see the problrm. If you want a uniquely name cursor name on each user's machine, the suggestion I made works with the READWRITE clause. No conflict since since sys(2015) is "almost" unique, and the tmp file ends up on the user's machine.
Code:
SELECT * from choice1.dbf INTO CURSOR SYS(2015) readwrite
? ALIAS()
? DBF()


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks, Jean. I did not need READWRITE but I will give it a shot and write back.

Frank
 
HI

I have been doing something similar to what Mike suggested. And I have no problem all these years.

In fact the code I use is... and in your case it could appear as..
*************************************
myCursor = "z"+SUBSTR(SYS(2015),4)
DO CASE
CASE .og.option1.value = 1
SELECT client_id, trustor_id, status, ;
nam_sort, loan_no ;
FROM trustor ;
WHERE &whatkim ;
ORDER BY loan_no ;
INTO CURSOR (myCursor)
CASE .og.option2.value = 2
SELECT client_id, trustor_id, status, ;
nam_sort, loan_no ;
FROM trustor ;
WHERE &whatkim ;
ORDER BY nam_sort ;
INTO CURSOR (myCursor)
ENDCASE
IF _tally > 0
myCursorAlias = ALIAS()
ELSE
myCursorAlias = ''
ENDIF
******************
If you use READWRITE then.. then Mikes code should work.

In my code, the cursor name is kept at 8 characters and I have not found a duplication so far. That helps me to keep all my temporary files starting with "z" and so dirctory maintenance becomes more easy. The cursors will get deleted auto when the application closes them, and in case improper closing, they may stay with "z" as starting character and easy to pick and trash.

:)

____________________________________________
Ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top