class Sequel::SqlAnywhere::Dataset

Public Instance Methods

fetch_rows(sql) { |h| ... } click to toggle source
# File lib/sequel/adapters/sqlanywhere.rb, line 141
def fetch_rows(sql)
  db = @db
  cps = db.conversion_procs
  api = db.api
  execute(sql) do |rs|
    convert = 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

    self.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