[ next ] [ prev ] [ contents ] [ up to Appendix B -- Database Example ] Invitation To Ruby

Executing the SQL Statement

  1: statement.execute(ARGV[0])
  2: 
  3: while row = statement.fetch
  4:   puts row[0] if row
  5: end
  6: 
  7: statement.finish

  • [1] Execute the prepared SQL statement.
    • Pass in the value of nickname we want to look up (from the ARGV argument list)

  • [3] Fetch a single row from the database.

  • [4] Print the first field of the result row (i.e. the email value)
    • Note: row is a DB Row object that will work like either an Array or a Hash
      • row[n] will return the nth element in the row.
      • row['name'] will return the elemented named name.

  • [7] When you are done with the statement, make sure you release any resources associated with statement by calling its finish method.


[ next ] [ prev ] [ contents ] [ up to Appendix B -- Database Example ] Copyright 2002 by Jim Weirich.
All rights reserved.