1: sql = <<-SQL
2: SELECT email
3: FROM person, email
4: WHERE person.personid = email.personid
5: AND person.nick = ?
6: ORDER BY nick, type
7: SQL
8:
9: statement = db.prepare(sql)
|
|
- [1-6] Define the SQL command using a "here" document.
- Notice the ? placeholder for the (as of yet) unknown value to be used for the nickname.
- [9] Prepare the SQL statement
- SQL statements that will be repeatably executed with many data values should be prepared before executing.
- Preparation allows the SQL engine to optimize the query strategy for once for a statement (this could be expensive).
|