Method: SQLite3::ResultSet#next
- Defined in:
- lib/sqlite3/resultset.rb
#next ⇒ Object
Obtain the next row from the cursor. If there are no more rows to be had, this will return nil
. If type translation is active on the corresponding database, the values in the row will be translated according to their types.
The returned value will be an array, unless Database#results_as_hash has been set to true
, in which case the returned value will be a hash.
For arrays, the column names are accessible via the fields
property, and the column types are accessible via the types
property.
For hashes, the column names are the keys of the hash, and the column types are accessible via the types
property.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/sqlite3/resultset.rb', line 103 def next if @db.results_as_hash return next_hash end row = @stmt.step return nil if @stmt.done? if @db.type_translation row = @stmt.types.zip(row).map do |type, value| @db.translator.translate( type, value ) end end if row.respond_to?(:fields) # FIXME: this can only happen if the translator returns something # that responds to `fields`. Since we're removing the translator # in 2.0, we can remove this branch in 2.0. row = ArrayWithTypes.new(row) else # FIXME: the `fields` and `types` methods are deprecated on this # object for version 2.0, so we can safely remove this branch # as well. row = ArrayWithTypesAndFields.new(row) end row.fields = @stmt.columns row.types = @stmt.types row end |