|There's more than one way to do things|
DBI quoting when I don't want it toby Tardis (Pilgrim)
|on Aug 21, 2002 at 13:10 UTC||Need Help??|
Tardis has asked for the
wisdom of the Perl Monks concerning the following question:
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.