Method: SQLite3::Database#get_first_value

Defined in:
lib/sqlite3/database.rb

#get_first_value(sql, *bind_vars) ⇒ Object

A convenience method for obtaining the first value of the first row of a result set, and discarding all other values and rows. It is otherwise identical to #execute.

See also #get_first_row.



378
379
380
381
382
383
384
385
# File 'lib/sqlite3/database.rb', line 378

def get_first_value(sql, *bind_vars)
  query(sql, bind_vars) do |rs|
    if (row = rs.next)
      return @results_as_hash ? row[rs.columns[0]] : row[0]
    end
  end
  nil
end