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 paramters 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.
250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/sqlite3/database.rb', line 250 def query( sql, *bind_vars ) result = prepare( sql ).execute( *bind_vars ) if block_given? begin yield result ensure result.close end else return result end end |