Been writing foxpro since 2.6 so 40 years. Never been able to get this to work. for umpteenth time searched web for hours but no luck. HELP!
Select * from mytable into cursor mycursor1
select * from mycursor1 into cursor mycursor2
results: mycursor1 contains the data from mytable as it should. mycursor2 gets created (all the columns are there) but contains no data. it is always empty.
As I said in my comment, the above DOES work if done from native VFP command window. Here is pseudocode for what does NOT work. I use the VFE framework.
Create a view named mycursor1 This view is never queried. It is semi permanent meaning it is created when the user comes into my Point-Of-Sale screen and released when they leave. While in the POS screens the contents of this view is displayed in a grid. As items are sold I use VFE business objects to add the items to this view and they are shown in that grid. When the user finishes ringing up a sale, I loop thru the view moving the contents of the view to another view (basically scan...replace statements...endscan but I do that with VFE business object commands). Then the data is saved from that 2nd view. Mycursor1 gets emptied (VFE's bo.cancel(.t.) so it is ready to ring up another sale. This part has worked flawlessly for over 30 years and is superfast.
I am inserting some new code just before I move the data from mycursor1 to the 2nd view for saving. That new code does an SQL Select (my database is all native VFP), so Select * from the view named mycursor1 into cursor mycursor2. This where the issue arises. As I said before, I am stepping thru the code. I see the 5 records in mycursor1. Mycursor2 gets created and contains all the fields from mycursor1 but mycursor2 is empty.
I believe this is happening because mycursor1 never get queried and is loaded from code/business objects instead of from VFP via a requery. I am going to do some testing today to see if I can prove that. I will post my results.
Gia has suggested other ways to move the data from mycursor1 to mycursor2. I do not believe that will accomplish my need. Why? I do not need to simply move the data from mycursor1 to mycursor2. When a sale is rang up in my POS screens, it contains rows something like +1 Snickers Bars then +3 Hershey Bars then -1 Snickers Bars, so 3 rows in mycursor1. The reason I am using an SQL select to move the data from mycursor1 to mycursor2 is to use a GROUP BY so that mycursor2 contains the contents of mycursor1 except grouped by item thereby getting rid of the minus (voids). So in this example I would end up with just 1 row in mycursor2 of +3 Hershey Bars. Hope that makes sense.
Thanks, John
In your notes I noticed you were talking about a view. Views are buffered by default and in your case you might have it table buffered. In that case your select from that view wouldn't return any rows, unless you add WITH (BUFFERING=.T.) clause.
Here is a code piece that would simulate what might be happening:
SET MULTILOCKS ON
SELECT * FROM _samples+'data\customer' WHERE .F. INTO CURSOR cursor1 READWRITE
CURSORSETPROP("Buffering",5,'cursor1')
APPEND FROM customer
browse
SELECT * FROM cursor1 INTO CURSOR cursor2 && No rows
*SELECT * FROM cursor1 WITH (buffering=.T.) INTO CURSOR cursor2 && has rows
browse