Method: SQLite3::Database#query

Defined in:
lib/sqlite3/database.rb

#query(sql, bind_vars = []) ⇒ Object

This is a convenience method for creating a statement, binding parameters to it, and calling execute:

result = db.query( "select * from foo where a=?", [5])
# is the same as
result = db.prepare( "select * from foo where a=?" ).execute( 5 )

You must be sure to call close on the ResultSet instance that is returned, or you could have problems with locks on the table. If called with a block, close will be invoked implicitly when the block terminates.



352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/sqlite3/database.rb', line 352

def query(sql, bind_vars = [])
  result = prepare(sql).execute(bind_vars)
  if block_given?
    begin
      yield result
    ensure
      result.close
    end
  else
    result
  end
end