|Syntactic Confectionery Delight|
Re: (jeffa) 3Re: Test if string is already quote()'d?by Seumas (Curate)
|on Jun 17, 2003 at 22:10 UTC||Need Help??|
Heh... Well, it's funny you should mention a DBI abstraction layer, because that's exactly what I'm working on. I didn't like anything that I already saw out there because it usually included far more than I needed or not nearly enough.
Mine works pretty well for what I need, but as I'm going back through my code to tidy things up and regain some consistancy across the board, I'm finding that little things like "when to quote a value" are popping up.
The original way I was handling this back in the day when I was new to SQL and the DBI was to take input and stuff it into one hash and then create another hash where I'd put sql quoted values. Something like this:
my %formdata = $query->Vars;
Followed by a per-instance quote() of values as needed. But that was obviously stupid because now I have two sets of the same data that I have to balanc. One for calculations and conditions and manipulation and the other for inserting into the database or performing queries on. And then you run into the problem of "wait, if I do this quote() here, will the value be as up to date as possible? Or will the other version of this value be changed and this will get stale?
Like I say, this code is a little old. *grin*
Almost all of my code now uses prepare()->execute()->fetch() or a shorthand equivalent like fetchall_arrayref(). And placeholders almost every chance I get. And I really stay away from do(), if nothing else than it just doesn't "feel" right in most situations.
It's actually in the conversion of my code to something more acceptable like this that has caused me to run into some logical and syntactic issues like the one this thread was about.
I finally devised a perfect (for me) solution for implementing my INSERTS for my abstraction layer and I'll post that a little later in this thread. It seems more elegant (to me) than the others I have found in "abstraction layers" for DBI around the net.
By the way, just so everyone understands, this isn't a big corporate project. This is just a small project of mine that has been running for about five years now. This code is the engine for an approximately 16,000 line auction engine that runs my heavily used auction site (well, about 30,000 accounts). This is a one man non-programmer's endeavor, hence the stupid questions and lack of normal project "preperation". :)