OK, I suspect I may be out of luck with this one.

I'm converting a web-based app to SQL (The backend is currently a DBM file. A big one).

I have arranged (for minimum pain) for my SQL tables to be automatically created based on a simple config file, which represents the current data structures. So far so good.

I had this bright idea that instead of users just being able to type in '25/12/2002' for dates, they could also type in '+1 month' or '-3 weeks'. What a great idea (I thought).

I duly wrote the logic which would convert +1 month to DATE(NOW() + INTERVAL '+1 month').

It doesn't work, and I bet you're all laughing at me right now.

(Pause to let laughter subside)

So if a user types '25/12/2002', then DBI does something like:

INSERT INTO table (thisdate) VALUES('2002-12-25') WHERE id = 1;

(My function has converted it to YYYY-MM-DD format).

In the interval style one, DBI does:

INSERT INTO table (thisdate) VALUES ('DATE(NOW() + INTERVAL \'+1 month\')') WHERE id =1

Bzzzzzt!

Unfortunately, since all this SQL code is automatically generated on the fly, it's difficult to 'spot' the date fields, and do them via variable interpolation, rather than via placeholder.

You can see why I think I'm probably out of luck :-)

Anyone see an elegant way around this? Like 'DBI, don't autoquote if it looks like this, otherwise do'. :-|

Otherwise, I have to do some sort of lookup for each element as I build the SQL statement.

<sigh>


In reply to DBI quoting when I don't want it to by Tardis

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.