I want to place my most common SQL queary formats in a subroutine and pass the parameters to it in sub calls. 90% of the time my results are perfect, 10% I get quirky errors.

Given your approach, 90/10 is about right. The thing that's tripping you up is quoting, and given the approach you're using, you're going to either have a sub that can handle about 90%, or you're going to push some real ugliness out to clients of the sub.

To insert "now()" into the query, you don't want the <quote>db_update_field</code> to be adding quotes. But to insert "t", you do. See the problem? For both to work, you need to push quoting out to the client, and do

db_update_field("users", $current_id, "last_seen_time", "now()"); db_update_field("users",$current_id,"last_seen_area","'$stuff'");
The second problem with your approach is that when you have a pair of values to update, you need to either invoke db_update_field twice (within a transaction), or you need to implement db_update_fields2, then db_update_fields3, then ... it keeps going downhill.

Instead a brittle, plug-in-the-pieces-to-run-a-query approach, build a set of routines that reflect the semantic actions you're performing.


In reply to Re: Unexpected results in SQL query subs by dws
in thread [untitled node, ID 193356] by Samn

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.