Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Dynamic Query construct based on argument

by kulls (Hermit)
on Nov 19, 2012 at 06:05 UTC ( #1004473=perlquestion: print w/replies, xml ) Need Help??
kulls has asked for the wisdom of the Perl Monks concerning the following question:

, Is there any CPAN Module which helps me to construct the DB query based on given parameter as an argument ?
  • Comment on Dynamic Query construct based on argument

Replies are listed 'Best First'.
Re: Dynamic Query construct based on argument
by ColonelPanic (Friar) on Nov 19, 2012 at 08:50 UTC

    Well, DBI, Perl's standard way of interfacing with databases, lets you do just that. You can make an SQL statement with parameters that can be set later:

    my $dbh = DBI->connect(...connection parameters...); my $get_foo = $dbh->prepare("select foo from table where bar=?"); $get_foo->execute(3); #select foo where bar=3 $get_foo->execute($baz); #select foo where bar=$baz

    Perhaps you meant something different by constructing a query. If so, you need to specify what you mean. SQL is a whole programming language in itself.

    When's the last time you used duct tape on a duct? --Larry Wall
Re: Dynamic Query construct based on argument
by CountZero (Bishop) on Nov 19, 2012 at 11:21 UTC
    Perhaps SQL::Abstract can help you. It transforms a Perl data-structure into valid SQL.


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1004473]
Approved by jonnyfolk
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2018-05-27 08:44 GMT
Find Nodes?
    Voting Booth?