class Sequel::MySQL::Dataset

  1. lib/sequel/adapters/mysql.rb
Parent: MySQL

Dataset class for MySQL datasets accessed via the native driver.

Methods

Public Instance

  1. fetch_rows
  2. graph
  3. split_multiple_result_sets

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/mysql.rb, line 295
def fetch_rows(sql)
  execute(sql) do |r|
    i = -1
    cps = db.conversion_procs
    cols = r.fetch_fields.map do |f| 
      # Pretend tinyint is another integer type if its length is not 1, to
      # avoid casting to boolean if Sequel::MySQL.convert_tinyint_to_bool
      # is set.
      type_proc = f.type == 1 && cast_tinyint_integer?(f) ? cps[2] : cps[f.type]
      [output_identifier(f.name), type_proc, i+=1]
    end
    @columns = cols.map{|c| c.first}
    if opts[:split_multiple_result_sets]
      s = []
      yield_rows(r, cols){|h| s << h}
      yield s
    else
      yield_rows(r, cols){|h| yield h}
    end
  end
  self
end
graph (*)

Don’t allow graphing a dataset that splits multiple statements

[show source]
# File lib/sequel/adapters/mysql.rb, line 319
def graph(*)
  raise(Error, "Can't graph a dataset that splits multiple result sets") if opts[:split_multiple_result_sets]
  super
end
split_multiple_result_sets ()

Makes each yield arrays of rows, with each array containing the rows for a given result set. Does not work with graphing. So you can submit SQL with multiple statements and easily determine which statement returned which results.

Modifies the row_proc of the returned dataset so that it still works as expected (running on the hashes instead of on the arrays of hashes). If you modify the row_proc afterward, note that it will receive an array of hashes instead of a hash.

[show source]
# File lib/sequel/adapters/mysql.rb, line 333
def split_multiple_result_sets
  raise(Error, "Can't split multiple statements on a graphed dataset") if opts[:graph]
  ds = clone(:split_multiple_result_sets=>true)
  ds.row_proc = proc{|x| x.map{|h| row_proc.call(h)}} if row_proc
  ds
end