in reply to SQL LIKE and Binding Variables

SELECT * FROM Songs WHERE Songs.Artist LIKE ? OR Songs.Artist LIKE '?
End then
s/%/%%/ for $artist1, $artist2; $dbh->execute("%$artist1%", "%$artist2%");

(I hope I remember correctly that % is escaped as %% in LIKE queries).

Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: SQL LIKE and Binding Variables
by graff (Chancellor) on Nov 03, 2009 at 06:55 UTC
    (I hope I remember correctly that % is escaped as %% in LIKE queries).

    Um, nope. Perhaps you're confusing SQL LIKE with (s)printf?

      Oracle, PostgreSQL, MySQL, SQLite, and even MS SQL Server have an ESCAPE keyword for this purpose. I'm too lazy today to find out if it is an official SQL standard or just one implementation copying the other one. But five very different databases agreeing on the same syntax for the same feature is simply too good to be just luck.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)