Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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:

Hi
, Is there any CPAN Module which helps me to construct the DB query based on given parameter as an argument ?
-Raja

Comment on Dynamic Query construct based on argument
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.

    CountZero

    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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1004473]
Approved by jonnyfolk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2014-12-26 06:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (165 votes), past polls