class Sequel::MySQL::Dataset

Public Instance Methods

fetch_rows(sql) { |s| ... } click to toggle source

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.

    # File lib/sequel/adapters/mysql.rb
310 def fetch_rows(sql)
311   execute(sql) do |r|
312     i = -1
313     cps = db.conversion_procs
314     cols = r.fetch_fields.map do |f| 
315       # Pretend tinyint is another integer type if its length is not 1, to
316       # avoid casting to boolean if convert_tinyint_to_bool is set.
317       type_proc = f.type == 1 && cast_tinyint_integer?(f) ? cps[2] : cps[f.type]
318       [output_identifier(f.name), type_proc, i+=1]
319     end
320     self.columns = cols.map(&:first)
321     if opts[:split_multiple_result_sets]
322       s = []
323       yield_rows(r, cols){|h| s << h}
324       yield s
325     else
326       yield_rows(r, cols){|h| yield h}
327     end
328   end
329   self
330 end
graph(*) click to toggle source

Don’t allow graphing a dataset that splits multiple statements

Calls superclass method Sequel::Dataset#graph
    # File lib/sequel/adapters/mysql.rb
333 def graph(*)
334   raise(Error, "Can't graph a dataset that splits multiple result sets") if opts[:split_multiple_result_sets]
335   super
336 end
split_multiple_result_sets() click to toggle source

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.

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

Private Instance Methods

cast_tinyint_integer?(field) click to toggle source

Whether a tinyint field should be casted as an integer. By default, casts to integer if the field length is not 1. Can be overwritten to make tinyint casting dataset dependent.

    # File lib/sequel/adapters/mysql.rb
359 def cast_tinyint_integer?(field)
360   field.length != 1
361 end
execute(sql, opts=OPTS) click to toggle source
Calls superclass method Sequel::Dataset#execute
    # File lib/sequel/adapters/mysql.rb
363 def execute(sql, opts=OPTS)
364   opts = Hash[opts]
365   opts[:type] = :select
366   super
367 end
literal_string_append(sql, v) click to toggle source

Handle correct quoting of strings using ::MySQL.quote.

    # File lib/sequel/adapters/mysql.rb
370 def literal_string_append(sql, v)
371   sql << "'" << ::Mysql.quote(v) << "'"
372 end
yield_rows(r, cols) { |h| ... } click to toggle source

Yield each row of the given result set r with columns cols as a hash with symbol keys

    # File lib/sequel/adapters/mysql.rb
376 def yield_rows(r, cols)
377   while row = r.fetch_row
378     h = {}
379     cols.each{|n, p, i| v = row[i]; h[n] = (v && p) ? p.call(v) : v}
380     yield h
381   end
382 end