How to refresh foxpro cursors?
After creating a cursor readwrite by a select query, I update some values in it, and then delete rows that do not match some criteria. the problem here is:
For example; If I have 30 record and update them, then delete 10, the record number will not change! It will still be 30. Is there a way to tell the cursor to refresh or reload so the rec number would match exactly what I have?
I'm running a select
to create cursor read write:
update
delete
B开发者_运维技巧ut the record number doesn't change, even though when I browse my cursor there are lesser records than before?
You can do something nearly equivalent to 'pack', which is just run a query against the cursor that eliminates the deleted rows:
SELECT * FROM mycursor INTO CURSOR mycursor READWRITE WHERE NOT DELETED()
When you DELETE records in FoxPro, the records are marked as deleted but not removed until a PACK command is issued. Since attempting to PACK a cursor with result in a "Invalid operation for the cursor." error you must issue your COUNT and other commands with a WHERE NOT DELETED() clause so you only operate on the records that have not been marked as deleted.
Regarding browsing the table and not seeing the deleted records, I suspect you have SET DELETED ON which will hide the deleted records from the browse window.
SELECT * FROM myTable INTO CURSOR myCusror READWRITE
COUNT FOR NOT DELETED()
GO TOP
DELETE NEXT 1
COUNT FOR DELETED()
COUNT FOR NOT DELETED()
COPY TO myNewTable FOR NOT DELETED()
If the goal is to be able to make changes and have them saved when you want, you may be better off just using the actual table and turning buffering on.
If you are using Visual Foxpro and have your tables in a DataBase Container, you could use updatable views to accomplish this. Views are basically the same as a cursor, but after you are done editing you can issue a TableUpdate() to send the changes to the Table or a TableRevert() to undone the changes.
Also, a Requery() will refresh the view you are working with.
精彩评论