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:

my $cmd_ins = <<"END_SQL"; INSERT INTO product_metadata (desc, abbrv, prdct_id) VALUES (?, ?, ?) END_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:

my %column_map = ( description => 'desc', abbreviation => 'abbrv', product_id => 'prdct_id' );

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.

Cheers,
Ovid

New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)


In reply to Re: sql query subroutine check by Ovid
in thread sql query subroutine check by maksl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.