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

Is it better to open all tables for an application...

Status
Not open for further replies.

rpp

Programmer
Feb 28, 2002
32
0
0
US
Hello again.

Is it better to open all tables for an application at startup...or open the tables individualy as required by the forms?

The pitfall with the later is opening different forms that use the same tables produce errors.

What is the pitfall with the former method?

Thanks in advance!
 
There is no "best" way. For the quickest opening of forms, first open all the tables, and then use Private Datasessions in your forms so you effectively open them AGAIN. Of course this does take up more resources, but it also allows multiple copies of a given non-modal form to be used without "steping on" the record pointers in the other forms.

On the other hand, if you have a potentially non-stable network, or you have any plans to upgrade to client-server type data access (e.g. remote views), then you'll only want to keep any table open as long as necessary, to avoid corruption and/or connection contention.

Rick
 
Thanks,

I did not consider the potential of client-server issues, but that makes sense.

Do VIEWS encounter the same issue of being open more than once, and if a view is closed for one form is closed for other forms also?

Rich
 
Rpp,

This is a good question. It is one that I have thought about since Foxbase days -- and I still don't know the answer.

In the old days, I would open all my tables at the start of the app, and keep them open the whole time. The advantages of that were better performance (slightly) and easier programming. The disadvantage was the slight increased risk of table corruption if something went wrong.

Lately, I have been doing what Rick suggested: Give each form a private data session, and open the tables either via the data environment or in the Load of the form. That's still easy to program, and nowadays the performance issue is negligible.

But that's just my opinion -- and I'm still not sure I'd be interested in hearing other people's views.

Mike

Mike Lewis
Edinburgh, Scotland
 
rpp

I open the tables required for each form as they load, my application allows you to drill down from one form to another that may also require the same table, the way i do it is to record what files are opened by what form.

So in the forms Init you would have something like;

if used("Customer") = .f.
USE "Customer" IN 0 ORDER Account ALIAS Customer SHARE
thisform.addproperty ("Customer", .t.)
else
thisform.addproperty ("Customer", .f.)
endif

And when closing the form;

if thisform.Customer = .t.
sele Customer
use
endif

Im sure there are better ways, and calling the above code from a sub would be an improvement, but it does work for me.


GuiltyMaggot - The best rock band in the world!
 
According RGBEAN there is really 'no best' way to handle tables. It all depends on your needs and resources. If disk access is not an issue then you open each time you need a file.

I prefer opening all on time, it runs the APP quicker. I only change relationships when I need to in the various forms and functions. I also keep an array record of the status of my tables each time a function call is made. When the control returns to the calling function, I reinstate the Tables statuses.

It is a nightmare always opening table on a slow network. The users often blame your APP.
 
Better is relative, but keep one thing in mind, the USE statement is one of the slowest commands in VFP. If you take the hit up front when your application starts you can distract the users with the "dancing chickens" splash screen.

The rest of time the application will perform USE AGAIN. The difference is this. USE must get the file layout (header record) and initial buffer from the file on the network and set it up in the internal cache. The USE AGAIN will look at the cache and save the time to pull down the information from the network. Local is faster, obviously.

So forms will automatically be doing the USE AGAIN if the files are already opened and they instantiate faster.

_RAS

 
What I'd like to see is the code for the "dancing chickens" splash screen...THAT is a must have!! :)

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
rschummer,

Welcome to the forum. Great to have you with us Rick. Took me a second to realize who you were, I think I was too busy staring at the dancing chickens!

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
rschummer

Welcome Rick. Pretty soon with all the 'experts' that joined Tek-Tips recently we could have our own little "virtual" Devcon. ;-)

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top