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!

Best way to validate code?

Status
Not open for further replies.

Aseem1234

Programmer
Nov 26, 2003
33
0
0
US
What is the best way...using field validation in the database itself, using masks and format in the form, or having code to handle the situation?

I know that each situation would depend on the application, but are there any issues that pop up using one method over another?
 
sorry I meant the best way to validate input
 
If your framework doesn't include a business object that validates the data, and you have more than one form or application that adds/edits the data, then the Database validation is probably the way to go. Otherwise, you have to trackdown all the code references (possibly in multiple applications) if you need to change field sizes (types?) or the validation rules.

Rick
 
Aseem1234,

There are pros and cons of both methods.

If you write the validation rules at the database level:

- The rules will be enforced across all applications, without the individual programmers needing to know what those rules are.

- If a rule changes, it only needs to be altered in one place.

- If you upsize the database, it might be possible to upsize the rule automatically (depending on the upsizing rule you use).

If you write your own code to do the validation:

- You have more control over the timing of the validation. This is an important issue. Assuming the table is buffered, a rule held in the database won't fire until you try to commit (usually in the Save button). If the form has many fields, the user might make a mistake in the first field but not know about it until they are ready to save. If, as a result of the validation failure, they have to revert, they have wasted a lot of time and energy filling in the rest of the fields for nothing.

- You still have to write code to deal with validation failures (although it is possible to do so in a more generic way).

You mentioned input masks and the like. These only validate one aspect of the data, and would normally not be used in isolation.

When I started with VFP 3.0, I tried putting all my rules in the DBC. Eventually, I drifted back to doing it the old way, in Valid events. That feels more comfortable to me.

But your situation might be different.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top