<premise>
I have never received any formal education about relational databases. I think I'm a decent Perl programmer, though. Now my current work requires me to work a lot with relational db's. Moreover I don't know the structure of our own db('s) which is also an obstacle. However I'm slowly learning and thus beginnig to cope with both problems. Generally I try to stay "on the Perl" side as much as possible, rather than to delve into SQL.
</premise>

Now, I'm often using SQL::Abstract to build queries. Needless to say, it greatly helps me. But I have a problem: when all of the values are determined, SA gives me a $where clause with placeholders and a @bind array with the corresponding values. So far, so fine. OTOH sometimes I'd need, so to say, to leave some values unspecified at clause-buildup-time.

The reason why I want to do what I've described at the end of the last paragraph is that I'm writing a closure around a lexical $sth (that I'm using as a callback), and in the arguments passed to $sth->execute() I want to include some arguments passed to the closure itself.

Let me get straight: I do have a solution to the problem. But I find it inelegant, not terribly reliable and on the whole unpleasant. Currently I give to some of the values passed to the where() method a special formatting and I later reprocess @bind with an ad hoc sub to substitute the "unspecified" values with those I want.

All in all I'd like something that would hardcode in $where all the values that are, say, defined and put a placeholder if a value is undef.

Any idea?


In reply to Question re SQL::Abstract (or something similar, whose existence I ignore!) by blazar

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.