Ugh I had to write so much of code that resembles what you have there - that at the end I wrote my own little DB "abstraction" (more like SQL generator and executer) to re-factor all that. It generates SQL by using placeholder for everything (values) and based on fields available in data/form and table.
So I ended up with something like:
$DB->insert_record(
table => 'mytable',
data => $form,
);
# But if you want timestamp => NOW() it should not be used as
# placeholder so I added another parameter marking which fields
# should be included as they are ... Of course this particular
# example would better been done by setting default value of
# timestamp field to NOW() and sending nothing here....
$form->{timestamp} ||= 'NOW()';
$DB->insert_record(
table => 'mytable',
data => $form,
as_is_fields => $form->{timestamp} eq 'NOW()' ? [qw/timestamp/] : [
+],
);
Now days I just pass around hashrefs from CGI to my DB-thing (through HTML::Entity and Data::FormValidator first), and from DB-thing to TemplateToolkit on output. And just take care to use same field names in all of those - so that DB-thing could do it's magic.
Have you tried freelancing/outsourcing? Check out
Scriptlance - I work there since 2003. For more info about Scriptlance and freelancing in general check out
my home node.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.