Method: SQLite3::Database#query

Defined in:
lib/sqlite3/database.rb

#query(sql, bind_vars = [], *args) ⇒ 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/sqlite3/database.rb', line 250

def query( sql, bind_vars = [], *args )

  if bind_vars.nil? || !args.empty?
    if args.empty?
      bind_vars = []
    else
      bind_vars = [bind_vars] + args
    end

    warn("\#{caller[0]} is calling SQLite3::Database#query with nil or multiple bind params\nwithout using an array.  Please switch to passing bind parameters as an array.\nSupport for this will be removed in version 2.0.0.\n    eowarn\n  end\n\n  result = prepare( sql ).execute( bind_vars )\n  if block_given?\n    begin\n      yield result\n    ensure\n      result.close\n    end\n  else\n    return result\n  end\nend\n") if $VERBOSE