class Sequel::MySQL::Dataset

  1. lib/sequel/adapters/mysql.rb
Superclass: Dataset

Methods

Public Instance

  1. fetch_rows
  2. graph
  3. split_multiple_result_sets

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
305 def fetch_rows(sql)
306   execute(sql) do |r|
307     i = -1
308     cps = db.conversion_procs
309     cols = r.fetch_fields.map do |f| 
310       # Pretend tinyint is another integer type if its length is not 1, to
311       # avoid casting to boolean if convert_tinyint_to_bool is set.
312       type_proc = f.type == 1 && cast_tinyint_integer?(f) ? cps[2] : cps[f.type]
313       [output_identifier(f.name), type_proc, i+=1]
314     end
315     self.columns = cols.map(&:first)
316     if opts[:split_multiple_result_sets]
317       s = []
318       yield_rows(r, cols){|h| s << h}
319       yield s
320     else
321       yield_rows(r, cols){|h| yield h}
322     end
323   end
324   self
325 end
graph(*)

Don’t allow graphing a dataset that splits multiple statements

[show source]
    # File lib/sequel/adapters/mysql.rb
328 def graph(*)
329   raise(Error, "Can't graph a dataset that splits multiple result sets") if opts[:split_multiple_result_sets]
330   super
331 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
342 def split_multiple_result_sets
343   raise(Error, "Can't split multiple statements on a graphed dataset") if opts[:graph]
344   ds = clone(:split_multiple_result_sets=>true)
345   ds = ds.with_row_proc(proc{|x| x.map{|h| row_proc.call(h)}}) if row_proc
346   ds
347 end