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

Deleteing a cursor and returning to original table 1

Status
Not open for further replies.

FoxEgg

Programmer
Mar 24, 2002
749
AU
I have been struggling with this forever
I wanted to browse the table... but it was seriously slow

Code:
BROW fields ENTRY_NUM :4 :H= '#', PRINT :P='!' :4 :H= 'Pr', TRANSFER :6 :P='!!!' :H= 'T/F' , percent_fe :5 :H= '%', FILE_NUM :R :28 :P='!!!!!!!!!!!!!!!!!!' :H= 'File Number',  LAST_NAME :R :18 :H= 'Last Name', item_numb :R :10 :H= 'Item #', idx_sequen :5, SERVICE :24 :R  TIMEOUT(15) NOMENU for file_num = fnum && 250299 removed -->> service :10
DO ortho2014

so I tried SELECT
It seems faster... but how do I now clear the SELECT or the Cursor so I can get back to my original table ?


Code:
select ENTRY_NUM, PRINT, TRANSFER, FILE_NUM, LAST_NAME, First_NAME, idx_sequen, service ,recno() as rec ;
   from 1;
   where file_num = "CA910126FQ";
   into cursor mycursor
BROWSE

It is probably very straightforward but I cant seem to nail it.

Thoughts appreciated

FoxEgg

FPD2.6 Legacy Human
Sydney, Australia
 
When you Select like this, from one table and without at least one of the keywords ReadWrite or NoFilter, you normally work with the actual table. This happens since VFP has added a "filter behind the scene". Simply issue Set Filter, and you will work with the table as normal.
 
You don't need to "clear" the cursor. Your original data still exists, in its original workarea.

You can demonstrate that as follows:
Code:
select .. etc. etc.
   into cursor mycursor
BROWSE 

SELECT 1
BROWSE

See? Your original data was there all the time. You just needed to switch to the relevant work area.

If and when you are sure you no longer need the cursor, just do:

Code:
USE IN Mycursor

and it will be gone forever (or until the next time you do the SELECT).

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks !!!

Found the READWRITE in the 'so called ' HELP file ... obscure to say the least

So I did this

Code:
select ENTRY_NUM, PRINT, TRANSFER, FILE_NUM, LAST_NAME, First_NAME, idx_sequen, service ,recno() as rec ;
   from 1;
   where file_num = "CA910126FQ";
   into cursor mycursor readwrite
BROWSE

then I did a BROWSE and got the same CURSOR
Then I did a SET FILTER TO and got the same CURSOR AGAIN !!

Grrr

I must be doing something wrong

JF



FPD2.6 Legacy Human
Sydney, Australia
 
Hi Mike (and thanks)

I tried the SELE 1 and it asked me to validate the table
Which I did
and then it gave me a FILE IN USE error

Can I turn off the validation ask ?

J



FPD2.6 Legacy Human
Sydney, Australia
 
And, by the way, referring to a work area by its number is a very bad idea. That's because the work area numbers are likely to change as you open and close the tables - plus numbers are harder to keep track off. Better to give the work area a meaningful name (by using the ALIAS clause when you open the table), and refer to it by that name thereafter.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes, you can disable table validation (using SET TABLEVALIDATE), but that's got nothing to do with your problem. You've clearly got your aliases and work areas in a bit of a twist. I suggest you start by getting rid of the references to numeric work areas, as per my previous post.

But the main point is that your original data is still there. You just need to switch to the relevant work area. If you still can't see how to do that, then open the Data Session window (by typing SET in the command window). That will show you all the open aliases, including MyCursor and your original table. Select the original table, and click on Browse.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
but how do I now clear the SELECT or the Cursor so I can get back to my original table ?

To answer the original question, you "clear" (or close) a cursor created in any way the same way you "clear" (or close) a table opened with USE. You USE.

Code:
Use Customer  && Customer is now open
Use  && now it isn't

A cursor (whether from CREATE CURSOR or SELECT - SQL) acts pretty much the same as a table. It uses a workarea that you can reclaim with USE.
 
As Mike has said and explained: referring to a [Data Table] work area by its number is a very bad idea

From the beginning you should have done something like the following:
Code:
* --- NOTE - In the following, the [b]IN 0[/b] 'tells' VFP to open into [b]NEXT[/b] available work area wherever that might be ---
USE [u]MyTable[/u] IN 0 
* --- And you can specify an Alias or use the Default (the table name) ---

* --- From here forward, refer to your original table by its Alias (MyTable) ---
SELECT <whatever>;
   FROM [u]MyTable[/u];
   where file_num = "CA910126FQ";
   into cursor mycursor readwrite
SELECT [u]MyCursor[/u]
BROWSE
* --- If you want to Close the cursor ---
USE IN MyCursor  && If the cursor is currently SELECTED, you can merely USE
* --- Also note that you do not [u]DELETE[/u] a Cursor ---
* --- A Cursor exists in Memory Only, so when you [b]USE[/b] it, it 'disappears' ---

* --- Return to original data table ---
SELECT [u]MyTable[/u]  && NOTE refer to original table by its Alias not its work area number
<do whatever>

Good Luck,
JRB-Bldr


 
FoxEgg said:
Found the READWRITE in the 'so called ' HELP file ... obscure to say the least

1. READWRITE is giving readwrite access to a cursor, editing it will now NOT edit the DBF. Wanting to edit the table you USE it and put it into a GRID control in a FORM and use the TEXTBOXES inside the columns with all their properties lie FORMAT, INPUTMASK, etc. You set captions of the columns via GRID.COLUMNX.HEADER.CAPTION. The whole thing about PICTURE :)P) and :H only works for sake of compatibility, nd as you know some of the compatibility is lost.

You can't do DOS in Windows. Stop complaining about this. Forget about running a mix of FPD and VFP code, you might not even get FPD code fully running.

2. What is obscure?
The help is very comprehensive in it's reference section about each and any COMMAND and FUNCTION, all the base CLASSes.
Every reference topic has Syntax, description of parameter, samples, notices and remarks, "Also see" section and more.

Other parts of the help include concepts like OOP or how to program for shared access to data.

If you copy the dv_foxhelp.chm and change extension to .ZIP, you get unzipped almost 5000 files, mostly the htm sources. Some topics are very short, others would be several pages when printed, so we could talk about a 10,000 page book here.

Some portions are still about core XBASE commands, that stayed, but this is about VFP9, not about FPD.

The help won't give you anything on things only kept for compatibility, it is not a FP2.6 help, neither FPD nor FPW, you better refer back to these old manuals, if you want to know/remember about details of this, or you start using the new object oriented part of VFP. You also expect a Windows 10 book to contain a comprehensive section about DOS commands?

Bye, Olaf.
 
Thanks to everyone for their assistance... I really do appreciate it . ..
I also respect the knowledge of folk who have been long time contributors.

I rarely present a problem here unless I have tried to solve it myself....

Thanks Olaf, I stand humbled....

But as an engineer and a surgeon I disagree with your statement


FPD2.6 Legacy Human
Sydney, Australia
 
Sorry, if you feel repelled. I can't solve all your misunderstandings and enlighten you in a breeze, though.

Simply take it for granted a full compatibility only is really available with the old Fox product.
I met a new old dbase developer thinking he could move to VFP, but some things are really deprecated after 7 versions.
For example setting FONT for a EDIT or whatever the dbase legacy comand like it was.

In regard to this very problem a query into cursor is not your solution, you either BROWSE the table as is, and limit FIELDS, SET FITLER, or you go the full jump into Winforms and use a Grid.

Querying into cursor readwrite won't give you write access to the DBF, you'd need one of the following:
1. updateable cursoradapter (newest thing)
2. updable local view
3. updateable sql passthrough cursor (only a good choice for remote data access)

With these you can use a query to get only the data you really want the user to see and edit, but you also don't get headers and format masks, etc.
So all you get in general from VFP9 is it's runtime working up to Windows 10 still not dying out, but not all legacy look&feel.

If you're uncomfortable with the help now, it' just because you don't even remotely know what to search for. Come here and ask about concepts. We're still here.

Bye, Olaf.
 
But as an engineer and a surgeon I disagree with your statement

I'm not sure what you're disagreeing with, but SELECT ... INTO CURSOR has been with us since FPD so it's certainly nothing new. You asked how to "clear" a cursor (which I assume means close, and you did not disagree) and "return to the table" which is core Xbase behavior that well predates VFP and has nothing to do with the VFP help file.

It's basic workarea and alias management and it dates to the earliest versions of dBase.

I'm sure you're a terrifically skilled surgeon and engineer, but the issue in this thread has nothing to do with being a skilled surgeon or engineer or even a faulty help file. It's a lack of understanding of core functionality.

Don't shoot the messenger. We're genuinely interested in helping.
 
Yes, as dan says you lack basic knowledge, I'm even very sure we already showed you.

Anyway, use this as enlightening tutorial about what happens by a SQL SELECT query:

1. Open up a freach VFP
2. Open up the datasession window. Just isseu the command SET, only SET with nothing after it. Or in the menu: Windows -> Data Session.

There can be many datasessions and the upper combobox will enable you to switch between them, especially if several forms with private datasessions run. Since that isn't the case now, the only entry inn that combobox is "Default(1)" the default datasession nummber 1.
3. USE thedbf IN 1 (obviously that's what you did, as you query FROM 1.
4. Do your query -
Code:
   Select ENTRY_NUM, PRINT, TRANSFER, FILE_NUM, LAST_NAME, First_NAME, idx_sequen, service ,recno() as rec ;
   from 1;
   where file_num = "CA910126FQ";
   into cursor mycursor READWRITE
Just as a remark: From 1 is a very brave move, it works, it selects from the DBF in workarea 1, it'll not fail, if there is something open in it, Still you should query from the DBF file, I'll get back to this later.
3. Watch the datasession: You now have "thedbf" open in workarea 1 AND "mycursor" in Workarea 2 (sql simply picks the next best free workarea)

So now you see (and could have seen ourself before) the cursor does not OVERLAY the DBF, it's simpoly its own workarea, it's own alias, it's own DBF, indeed a cursor is nothing but a DBF, too. Click on "mycursor" and ? DBF(), you'll see a random file name similar to what SYS(2015) generates with extension TMP. A cursor is a temp file.

Does that clear up things? If not yet: Notice working in this cursor works in workarea 2 on the TMP file, it doesn't act on the DBF file in workarea 1. You can't solve your problem not getting the browse window look with a SQL query, as it detaches you from the DBF. So either you live with BROWSE not having all your formats and captions, or you go for a grid to bind the DBF to. A cursor is not your solution, unless you begin to program storing back changes via UPDATE-SQL of only changed records. That would not only involve learning the update-sql, but also the concept of buffering, GETNEXTMODIFIED(), GETFLDSTATE() and much more. It's too much to beigin with.

That's were the tutorial steps end.

The best you can do to get closer to your origial BROWSE is get a reference to the native unmodified BROWSE window and act on it's inner structure:
BROWSE NAME oBrowse NOWAIT
oBrowse.Column1.Header1.Caption = "This is column 1"
oBrowse.Column2.Text1.Format="!" && (column2 should be charcter type data, then it's displayed all upper case

Also take a deeper look at the BROWSE Command and all it's options, eg FORMAT, the BROWSE help topic has a sample on that with SET FORMAT and BROWSE FORMAT.

Bye, Olaf.
 
Whoops.. accidentally sent my last message a bit early (obviously I am inexperienced) I did a Control-V and it sent the message incomplete.... Sorry for the delayed completion.





I stated that "may I politely say that I disagree with your statement. Olaf wrote...

[comment]
2. What is obscure?
The help is very comprehensive in it's reference section about each and any COMMAND and FUNCTION, all the base CLASSes.
Every reference topic has Syntax, description of parameter, samples, notices and remarks, "Also see" section and more.

[/comment]

I note that ....
tbleken (Programmer) was kind enough to suggest that this READWRITE might help .. so I looked up READWRITE in the "Help" aka I did and F1 in VFP8 ... looked for the SELECT command and READWRITE does not even appear till line 80 ... and it certainly isn't in the introduction .. I might be a fool but one reference in line 80 would hardly be called exactly "comprehensive"

Here is a copy of my HELP to demonstrate the point

[comment]

This a direct copy from the HELP FILE

Retrieves data from one or more tables. The SELECT SQL command is built into Visual FoxPro like any other Visual FoxPro command. When you use SELECT to pose a query, Visual FoxPro interprets the query and retrieves the specified data from the tables. You can create a SELECT query from within the following:

Command window
Visual FoxPro program as with any other Visual FoxPro command
Query Designer
SELECT [ALL | DISTINCT] [TOP nExpr [PERCENT]] [Alias.] Select_Item
[[AS] Column_Name] [, [Alias.] Select_Item [[AS] Column_Name] ...]
FROM [FORCE] [DatabaseName!] Table [[AS] Local_Alias]
[ [INNER | LEFT [OUTER] | RIGHT [OUTER] | FULL [OUTER] JOIN DatabaseName!]
Table [[AS] Local_Alias] [ON JoinCondition ...]
[[INTO Destination] | [TO FILE FileName [ADDITIVE] | TO PRINTER [PROMPT] | TO SCREEN]]
[PREFERENCE PreferenceName] [NOCONSOLE] [NOWAIT]
[WHERE JoinCondition [AND JoinCondition ...] [AND | OR FilterCondition [AND | OR FilterCondition ...]]]
[GROUP BY GroupColumn [, GroupColumn ...]] [HAVING FilterCondition] [UNION [ALL] SELECTCommand]
[ORDER BY Order_Item [ASC | DESC] [, Order_Item [ASC | DESC] ...]]

[/i]

NOTE there is not one reference to [b]READWRITE[/b] whatsoever... not one reference !

[b][/comment][/b]

Hence I made my my somewhat critical comment of the 'F1 HELP' in VFP 8
No criticism of the "messengers"

I am very grateful for the helpful suggestion from tbleken to look at the READWRITE the reference which, I repeat, actually doesn't appear to line 80

And yes I "lack knowledge"... and no I am "not shooting the messenger"

I was timorous enough to criticize my VFP8 version



[b][comment]
[/b]
[i]tbleken said "To specify that the cursor is temporary and modifiable, use READWRITE. If the source table or tables use autoincrementing, the settings are not inherited by the READWRITE cursor[/i]
[b][/comment][/b]

As a basic user, a very basic user .... I would think it fair to say that any reference to READWRITE that doesn't appear in the headline summary and at best only rates a 'cursory mention' qualifies itself as fairly salutary 'help'.. and since this was a proposed solution to my problem... and I was just someone asking for assistance, I looked at the proposed helpful solution from tbleken

I am sorry too to anyone if I offended anyone by mentioning this

[b][comment]
[/b]You can't do DOS in Windows. Stop complaining about this. Forget about running a mix of FPD and VFP code, you might not even get FPD code fully running.
[b][/comment]
[/b]

Not my intention to complain....In fact I did not complain,,,, have look back at my original question.... Look back in history, most of my replies begin as 'Thanks'

It never has been my intention to "complain" . Sorry if anyone perceived it as such .... I was simply asking for help.



I have been running my simple little FPD26 code for 30 years (and it has NEVER had a glitch) and I was simply seeking the kind assistance of anyone kind enough to assist for a quick fix to solve one line of code that I had ....

As poor old DOS FPD26 is no longer supported on 64 Bit machines,,, and VFP8 will tolerate running on these 64 bit machines... I thought that it worth a try for a quick conversion....

I thought that this quick any 'nasty' conversion of this BROWSE command (FPD6 to VFP8) would help my good secretaries....
Might not be 2016 most efficient code... all it needs to do is work.

ALSO

If you take a quick look back through my several years of requests, this should show that i am neither an abuser of the privilege of everyone's kind assistance... nor a sophisticated coder with access to all sorts of resources...


In this current case... I think I have been provided solutions that I can work/play with in the interim.


Genuinely.... Thanks to all for your positive contributors....

May I close with a surgical aphorism.. you get a better response by tapping someone gently with a rose than clubbing them with a hammer...

I agree "Don't shoot the messenger. We're genuinely interested in helping. "

I know that... you guys are great...
But my reference to my background training is that I am not an idiot...
and my complaint was not about your (plural) kind assistance it was about a F1 Help which took 80 lines before READWRITE appeared... I thought that was a little thin.

My suggestion is don't shoot the person asking the question, I am genuinely interested in solving my little problem

Regards to all

Lets move on... I thank all for their constructive assistance....

JF


PS I learnt that <Control-V> does not appear to do a copy in this Reply Window... it did a SEND (or it did on my computer !)


FPD2.6 Legacy Human
Sydney, Australia
 
Whoops.. accidentally sent my last message a bit early ....I did a Control-V and it sent the message incomplete.

You might find the following points helpful:

1. If you accidentally send your message before you are ready, you can use the Edit button to amend it, or the Delete button to delete it and start again. Both buttons are located to the bottom-right of your post. They are available for a limited time after you posted or last edited the message.

2. There is no [comment] tag. The tag you wanted in this case is [ignore]
[/ignore].

3. To format program code, use [ignore]
Code:
 and
[/ignore] tags.

4. If you are unsure about the effect of the above tags, you can use the Preview button to check.

5. There is useful help window available for this stuff. Click on the question mark icon on the editing toolbar (just to the left of the Preview button).

6. CTRL+V does not send the reply. I don't know why that happened in your case. CTRL+V does a paste, just like it does everywhere else in Windows.

I hope you find the above useful.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks Mike,

I forgot about the

"
"

tags

As an aside and as quiet observer on this forum for many many years you have been an awesome and polite assistant for so many people....

Even for us uneducated folk in the antipodes....

Is there any reason that someone should not propose you for an MBE ?

For services to the hopeless new souls of VFP and for 'the ghosts of FoxPro past'

Foxy




FPD2.6 Legacy Human
Sydney, Australia
 
>NOTE there is not one reference to READWRITE whatsoever... not one reference !

Yes, because READWRITE is not a clause of the BROWSE command, why should it be explained there? It's a clause of SELECT-SQL and to be precise it is explained in the "SELECT - SQL Command - INTO or TO Clause" topic, because SELECT-SQL is so complex, that it has several topic pages.

You puzzle me here !??? Why are you complaining about the BROWSE topic?

Once you have been advised to use READWRITE you also find this in the correct help topic just by searching this word:
readwrite_ilfntr.png


The BROWSE command is explained in it's full entirety. You rather complain about why you don't get any advice from the BROWSE help topic on why the browse is or can be in read-only mode, all it says about this is you can set fields readonly via :R, so I may share that part of the problem with you, but then you should ask that question here and not how you can get back to the DBF.

I don't see you asking why you can't edit a cursor you did with a SQL select in a BROWSE window. You came here with a completely different question.

Bye, Olaf.
 
PS I learnt that <Control-V> does not appear to do a copy in this Reply Window... it did a SEND (or it did on my computer !)

CTRL-V shouldn't do a copy anywhere in Windows. It's the shortcut for Paste.
 
FoxEgg,

You have no need to apologize, that's perhaps vice versa, but you have a misconception here, too.

I don't see you as angry about us, but you are complaining about VFP and the help file by all definitions of complaining and I defend the product.
As a sidenote: This is the final stage a product can have after having a business success - its consumers defending it against criticism.

I confront you with some knowledge gaps and they are very fundamental, too fundamental for someone doing this for so long and having been pointed to several things already several times for sure. And I was even not pointing out everything I saw wrong this time, though I'm very sure we already pointed out using workarea numbers has become a very bad concept.

I know all this is just a sidetrack of your job. Yes, I remember a discussion we had about your situation. But you're just not making the necessary step to redo the code in VFP9 style. No time for that, no bugdet for that, I know, but you can't force VFP9 to work like legacy. There is much compatibilty and dan already pointed out some things even weren't different in old fox. Still overall you can't get a legacy app running with all its aspects in VFP. Using new concepts is OK for a fix, obviously there is no other way. It's also natural to not get things right the first time. For example I spent the last three weeks mainly getting shared memory access right, though I even found a VFP sample to start with. Sorry, but mainly you're standing in your own way, barking up the wrong forrest.

I know the situation you are near a solution and ask a detail question. This is not giving anybody else an insight in where you are and what is the real and more general problem.

Bye, Olaf.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top