in reply to Abstracting SQL without Stored Procedures

I'm already tensing myself for the downvotes :)

A few years ago, when I didn't know any better, I actually did something similar to what you're suggesting.

But I did it with the dreaded 'require'

I haven't done it since, as my skills have developed a tad since then, but it might just be a bad idea that works in your case.

What I did was this:

1.) Created a file called: queries.pl

In this file, I put things like:

$Q_FINDMAX = 'select max(note_id) from pat_notes'; $Q_FINDMIN = 'select min(note_id) from pat_notes'; . . etc...
and then, in my script: parse_notes.pl, I used:
require ('/prod/parse/queries.pl');
After that, it's just a matter of using the $Q_ variable names to refer to the queries.

The advantage of doing it this way is that it allowed the SQL folks to update/tune SQL without having to go into the actual Perl script to find them.

It's probably not the *best* way to do this sort of thing, but maybe it's good enough for what you're after? The syntax might be a little off (like I said, I haven't done this in a while, and I don't have any examples in front of me to refer to

Trek

Replies are listed 'Best First'.
Re^2: Abstracting SQL without Stored Procedures
by astroboy (Chaplain) on Sep 30, 2004 at 20:18 UTC

    I like this approach. And I also like the comment by Kevin Meltzer and/or Brent Michalski in "Writing CGI Applicatins in Perl": "I know many people who cringe at the require() function. They would rather have everything be a module. My philosphy is that require() is quick and simple, and if Larry is going to leave it in the language, I am going to use it."

    I used require for exactly the same purpose as suggested above - so that someone who doesn't know perl can modify the meta-data. Worked a treat