0

The following method returns an empty array

  def self.select_where(column, value)
    $db.execute(" SELECT *
                  FROM students
                  WHERE ? = ?", column, value)
  end

while the one below returns the proper row of the table.

  def self.select_where(column, value)
    $db.execute(" SELECT *
                  FROM students
                  WHERE #{column} = '#{value}'")
  end

What do I need to change to make the placeholders work? (sqlite3 gem)

user229044
  • 232,980
  • 40
  • 330
  • 338
dwilbank
  • 2,470
  • 2
  • 26
  • 37
  • 2
    You can't use parameters as the name of a column, see [here](http://stackoverflow.com/questions/5870284/can-i-use-parameters-for-the-table-name-in-sqlite3) – bhamby Mar 24 '14 at 02:27
  • 1
    To add to @bhamby's point, the second example works since the string is being evaluated *before* it's passed to `$db.execute` as an entire query. – mralexlau Mar 24 '14 at 02:31

0 Answers0