i started this writeup earlier when i was at work ... but couldn't get it finished ( the lull in the day came to an abrupt end ).

i've been looking into easier, faster ways of generating some of my SQL queries. ( faster on the coding time, at least ). i've poked around a bit in the Class::DBI perldoc, but it looks like using it for more complicated joins ( like LEFT JOINs when they're needed ) would be almost more of a hassle than a help ...

the first place i've been looking to replace some of my SQL is actually in my INSERT/UPDATE queries. i tend to do this a lot:

sub storeData { my $self = shift; my @fields = qw/ foo bar baz quid quux /; my $insStmt = "INSERT INTO table VALUES ( " ; $insStmt .= "? " x ( scalar( @fields ) +1 ); $insStmt .= " ) "; my $updStmt = "UPDATE table SET " . join( "$_ = ?, ", @fields; $updStmt .= "WHERE id = ? "; $useSql = ( $id ? $updStmt : $insStmt );
then run through all the usual prepare, execute, bind_params, etc. as needed ( working off the @fields array.

it's fairly maintainable. adding an element to @fields gets the column added to the ins/upd statements, but I'm starting to wonder how much easier it could get.

would Class::DBI be an appropriate solution?


In reply to 'automating' SQL queries, use Class::DBI? by geektron

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.