title: SQL wildcards via Ruby
body: <p>I am trying to use a wildcard or regular expression to give some leeway with user input in retrieving information from a database in a simple library catalog program, written in Ruby. </p>
  
  <p>The code in question (which currently works if there is an exact match):</p>
  
  <pre><code>puts "Enter the title of the book"
  title = gets.chomp
  book = $db.execute("SELECT * FROM books WHERE title LIKE ?", title).first
  
  puts %Q{Title:#{book['title']}
  Author:#{book['auth_first']} #{book['auth_last']}
  Country:#{book['country']}}
  </code></pre>
  
  <p>I am using SQLite 3. In the SQLite terminal I can enter:</p>
  
  <pre><code>SELECT * FROM books WHERE title LIKE 'Moby%'
  </code></pre>
  
  <p>or</p>
  
  <pre><code>SELECT * FROM books WHERE title LIKE "Moby%"
  </code></pre>
  
  <p>and get (assuming there's a proper entry):</p>
  
  <pre><code>Title: Moby-Dick
  Author: Herman Melville
  Country: USA
  </code></pre>
  
  <p>I can't figure out any corresponding way of doing this in my Ruby program.</p>
  
  <p>Is it not possible to use the SQL <code>%</code> wildcard character in this context? If so, do I need to use a Ruby regular expression here? What is a good way of handling this? </p>
  
  <p>(Even putting the <code>?</code> in single quotes (<code>'?'</code>) will cause it to no longer work in the program.)</p>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>(Note: I am essentially just trying to modify the sample code from chapter 9 of <em>Beginning Ruby</em> (Peter Cooper).)</p>