Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: DBI SQLite statement problem with %

by runrig (Abbot)
on Mar 22, 2016 at 17:18 UTC ( #1158520=note: print w/replies, xml ) Need Help??


in reply to DBI SQLite statement problem with %

I want to avoid to have 2 different contructions of $selection...
Don't avoid it, don't worry about it. Just do it, e.g.:
my @filter; push @filter, "tag1 like '$value1'" if $value1; push @filter, "tag2 like '$value2'" if $value2; $sql .= "WHERE " . join(" AND ", @filter) if @filter;

Replies are listed 'Best First'.
Re^2: DBI SQLite statement problem with %
by Your Mother (Bishop) on Mar 22, 2016 at 19:05 UTC

    Agree++. Part of why I like postfix conditionals so well.

    For the OP, if you're heading down this road, SQL::Abstract is worth looking at. It leads on to things like DBIx::Class. Not everyone agrees ORMs are good for the kids but it's helped me out tremendously during the last decade. :P

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2019-04-25 01:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (124 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!