in reply to Re: DBI placeholders and like statement
in thread DBI placeholders and like statement

I was having the same problem using sqlite on a Mac. And this syntax works as well.
$sth=$dbh->prepare(qq{SELECT title,books.author,notes,books.titlei +d,pubyear,books.authorid FROM books WHERE notes like ? ORDER BY lower(title)}) or die "Couldn't prepare your statement: " . $dbh->errstr; $sth->execute("%$Notes%") or die "Couldn't execute your statement: + " . $sth->errstr;

Replies are listed 'Best First'.
Re^3: DBI placeholders and like statement
by stevieb (Canon) on Nov 16, 2024 at 11:13 UTC

    It is so odd that I was having difficulty with this just yesterday. I must have been missing something obvious, because this works for me:

    use warnings; use strict; use Test::Thing; my $Test = Test::Thing->new; my $q = qq{ SELECT x FROM y.z WHERE a LIKE ? LIMIT 1 }; my ($result) = $Test->db->dbh->selectrow_array($q, undef, "1111%");

    Details masked, and normally query calls are hidden in the backend. However, that test succeeded.

    I can't even imagine what I was trying yesterday to have it fail. Again, it is so very interesting that this specific issue was brought up here after 10+ years.