|We don't bite newbies here... much|
Re: sql query subroutine checkby Ovid (Cardinal)
|on Mar 01, 2003 at 23:20 UTC ( #239793=note: print w/replies, xml )||Need Help??|
I've recently become a convert to object-oriented persistence modules. Specifically, I use Class::DBI, though there are others which are good. One of the many benefits of these modules is, when used properly, they allow for greater decoupling of code from the specific database implementation. For example, consider the following SQL:
Later, as the programmer realizes that the field names in the database are not very desriptive, she thinks to change them to description, abbreviation, and product_id. This makes it easier to see what's happening in the database, but also forces her to change her code in every spot where this table is referenced.
As an alternative, I do something like the following:
Then, when I create an object that is persistent in the database, I use this mapping to map my desired accessor names to column names. Outside of the object, code relies on the accessor names and if I need to change the database column names, I just change them in %column_map and my code still works.
While you are probably well into your project, this could save you much grief in the future, particularly in projects where you are developing your database at the same time as you develop the code. For a more complete explanation of this, see my response at caseywest.com.
New address of my CGI Course.
In Section Seekers of Perl Wisdom