in reply to How do Monks programatically construct SQL selects

I am reinventing this particular wheel right now. I am working on a "mart" type application; the idea is basically to have common cases (and not so common, but complicated ones) wrapped into their own classes; each provides a sql() method, which are collated together to create the final query.

I use Class::DBI to store these components in a database: as Fields, Filters, Joins and Groups (purely an organizational thing). You can get some cute optimizations with this, for example if a field is selected from another table it usually is inserted as a subselected, but if a filter is added on that same table, a join (inner) is automatically included and the field uses that as well.

The real advantage of this for me is that it provides methods to quickly construct html forms for these queries (coupled with Template::Toolkit a Filter "knows" how to draw itself), after which I can just give the parsed CGI.pm query object to the SQL thing and get back the complete SQL statement. Makes working with sessions trivial as well.

I am not sure how many people would find this sort of thing useful, but in this case it's been working pretty well so far.

  • Comment on Re: How do Monks programatically construct SQL selects

Replies are listed 'Best First'.
Re: Re: How do Monks programatically construct SQL selects
by dragonchild (Archbishop) on Sep 03, 2003 at 13:10 UTC
    I am reinventing this particular wheel right now.

    Actually, you're not. You're using components (like Class::DBI and Template::ToolKit) to create a custom application. The particular wheel in question is supplied, in your case, by Class::DBI. The OP was discussing how to code the functionality provided by Class::DBI, which you are intelligently using. :-)

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.