Home: Perl Programming Help: DBI:
SQL query wrappers



PerlKid
stranger

Feb 28, 2002, 1:01 AM


Views: 6789
SQL query wrappers

Anyone tried making an SQL wrapper, so you can do stuff like:
[perl]my $rec = $DB->select({
cols =>[@cols],
tables =>[@tables],
cond =>{%cond},
opts =>"order by Title"
})->fetchrow_hashref();[/perl]

Looking through some posts on other boards, there seems to be mixed opinions on this. Some say it's easier to just write out queries in long hand. Others think it's much cleaner looking and easier to make a module to automate the creation of queries at the expense of posibly limiting the complexity of the type of queries you can do.

I started writing one knowing this, so I at least made a sub to let me write them in longhand when needed. So far for boolean queries, I can do global AND and OR searches, and ORs on individual keys where an array of values is passed instead of a scalar. Also made it so the condition can be a scalar or array so I could prewrite the conditions to add some flexibility.

What do you think? Is this worthwhile or worthless? Ideas are also appeciated. Smile
--Philip
FuzzyLogic at PerlMad dot com


Kanji
User / Moderator

Mar 1, 2002, 5:20 AM


Views: 6776
Re: [PerlKid] SQL query wrappers

I don't think it's at all worthless, but neither is it original ... --k.
--k.