class Sequel::SqlAnywhere::Dataset

  1. lib/sequel/adapters/sqlanywhere.rb
Parent: SqlAnywhere

Dataset class for SqlAnywhere datasets accessed via the native driver.

Methods

Public Instance

  1. fetch_rows

Constants

DatasetClass = self  

Public Instance methods

fetch_rows (sql)

Yield all rows matching this dataset. If the dataset is set to split multiple statements, yield arrays of hashes one per statement instead of yielding results for all statements as hashes.

[show source]
# File lib/sequel/adapters/sqlanywhere.rb, line 143
def fetch_rows(sql)
  db = @db
  cps = db.conversion_procs
  api = db.api
  execute(sql) do |rs|
    convert = (convert_smallint_to_bool and db.convert_smallint_to_bool)
    col_infos = []
    api.sqlany_num_cols(rs).times do |i|
      _, _, name, _, type = api.sqlany_get_column_info(rs, i)
      cp = if type == 500
        cps[500] if convert
      else
        cps[type]
      end
      col_infos << [i, output_identifier(name), cp]
    end

    @columns = col_infos.map{|a| a[1]}

    if rs
      while api.sqlany_fetch_next(rs) == 1
        h = {}
        col_infos.each do |i, name, cp|
          _, v = api.sqlany_get_column(rs, i)
          h[name] = cp && v ? cp[v] : v
        end
        yield h
      end
    end
  end
  self
end