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

SQL select to R/W cursor in 6.0 2

Status
Not open for further replies.

bon011

Programmer
Jun 2, 2002
155
CZ
I am working in VFP 6.0 and there isn't any possibility to select some data from table to cursor with SQL statment and then update this cursor.

So I wrote this function that makes from noeditable cursor editable cursor:

function r2rw(aCursor)
local i, cFname, nSize, cType, cField

select * from &aCursor into cursor tmp_cursor
select &aCursor
use in &aCursor
create cursor &aCursor(xdc I)
select "tmp_cursor"
for i=1 to fcount()
cFname=field(i)
cType=type(cFname)
nSize=fsize(cFname)
cField=right(cFname,10)+" "+cType+"("+trans(nSIze)+")"
select &aCursor
alter table &aCursor add column &cField
select "tmp_cursor"
endfor
alter table &aCursor drop column xdc
select * from tmp_cursor into array tmp_array
insert into &aCursor from array tmp_array

select &aCursor
for i=1 to fcount()
cFname=field(i)
index on &cFname tag &cFname
endfor
endfunc
 
You can make a cursor created with a SQL Select statement writeable if you USE it AGAIN in another work area:
Code:
select * from &aCursor into cursor tmp_cursor
use dbf('tmp_cursor') again in 0 alias NewCursor
NewCursor is now writeable.



-BP
 
This is good solution too.
 
I'm running it exactly as you say and keep getting the message: "Alias is not found"? Thank you!
 
iyarosh,

Did you enclose the name you pass to the DBF() function in quotes? Also, make sure there's no typo in the name.

One thing that's bitten me on occassion is if I forget to include the IN 0 clause or don't SELECT 0 first. Otherwise, it tries to open the new alias in the same workarea as the old alias, and it closes the old alias first.


-BP (Barbara Peisch)
 
ma'am barbara,

short, direct, and yet very effective. here's a star for you. [2thumbsup]


kilroy [trooper]
philippines
"and that's what we call creativity..."
 

the one with the DBF() function and the AGAIN clause.


kilroy [trooper]
philippines
"and that's what we call creativity..."
 
Everything seems to be in order, but still does not work. I have a short program (function) in which the first step creates this cursor:
select ~~~~~~~~~
into cursor curTemp
Then I try to reuse it and this is where I get "Alias is not found" message:
Use dbf('curTemp') again in 0 alias curBase

This function is getting called from another place in which select 0 statement exist. Could that be it? I highly appreciate your responses. Thank you!
 
Barbara,

Aparently FoxPro did not like the order; when i swapped the statements around it started working. Here is my working statement:
Use dbf('curTemp') again alias curBase in 0

Thank you for valuable and effective solutions.
 
I just tried the syntax
Code:
use dbf('temp') again in 0 alias NewCursor
and didn't get an error. There was probably something else wrong, but as long as it's working now, it doesn't really matter.


-BP (Barbara Peisch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top