I have a set of scripts that get installed on various servers. I store the data using DBI, so I can support my clients various SQL servers. Up to this point, I have implemented configuration strings to set the SQL statements for each client to support slight differences in field names, or table names depending on client standard operating procedure, etc. While this works, it seems very unelegant and not the easiest to maintain.

For each of 5 different tables I insert new records, retrieve records by a user number (5-10 records max), retrieve records by a primary key or retrieve all records for summation. All the data is stored in an object so it is either going from the database to the object or the object to the database. My module functions are basically, db->save, db->get_user_recs, db->get_record, db->get_all_recs, and I pass the table_name and any parameter.

I am seeking suggestions on how my database module might be able to map the pieces of the user object back forth to the sql database and create decent sql without resorting to putting the raw sql statements into a configuration file, but still with the flexibility to add or subtract a field or tweak a field name.

g_White

In reply to Creating a Flexible Database Module by gwhite

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.