Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: 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:

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-06-25 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.