What is the best way to construct sql with various number of WHERE conditions ? My solution looks ugly:
my ($where, @values);
if ($phone_number)
{
$where = 'AND pnone_number=?';
@values = ($from, $till, $phone_number);
}
else
{
$where = '';
@values = ($from, $till);
}
my $sql = 'SELECT * FROM calls WHERE time between ? AND ? '.$where.' ORDER BY time';
my $res = $dbh->selectall_arrayref($sql, undef, @values) or warn 'error';