Method: SQLite3::Database#execute2

Defined in:
lib/sqlite3/database.rb

#execute2(sql, *bind_vars) ⇒ Object

Executes the given SQL statement, exactly as with #execute. However, the first row returned (either via the block, or in the returned array) is always the names of the columns. Subsequent rows correspond to the data from the result set.

Thus, even if the query itself returns no rows, this method will always return at least one row–the names of the columns.

See also #execute, #query, and #execute_batch for additional ways of executing statements.



207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/sqlite3/database.rb', line 207

def execute2( sql, *bind_vars )
  prepare( sql ) do |stmt|
    result = stmt.execute( *bind_vars )
    if block_given?
      yield result.columns
      result.each { |row| yield row }
    else
      return result.inject( [ result.columns ] ) { |arr,row|
        arr << row; arr }
    end
  end
end