class Sequel::MySQL::Dataset
Public Instance Methods
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 293 def fetch_rows(sql) 294 execute(sql) do |r| 295 i = -1 296 cps = db.conversion_procs 297 cols = r.fetch_fields.map do |f| 298 # Pretend tinyint is another integer type if its length is not 1, to 299 # avoid casting to boolean if convert_tinyint_to_bool is set. 300 type_proc = f.type == 1 && cast_tinyint_integer?(f) ? cps[2] : cps[f.type] 301 [output_identifier(f.name), type_proc, i+=1] 302 end 303 self.columns = cols.map(&:first) 304 if opts[:split_multiple_result_sets] 305 s = [] 306 yield_rows(r, cols){|h| s << h} 307 yield s 308 else 309 yield_rows(r, cols){|h| yield h} 310 end 311 end 312 self 313 end
Don’t allow graphing a dataset that splits multiple statements
Sequel::Dataset#graph
# File lib/sequel/adapters/mysql.rb 316 def graph(*) 317 raise(Error, "Can't graph a dataset that splits multiple result sets") if opts[:split_multiple_result_sets] 318 super 319 end
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 330 def split_multiple_result_sets 331 raise(Error, "Can't split multiple statements on a graphed dataset") if opts[:graph] 332 ds = clone(:split_multiple_result_sets=>true) 333 ds = ds.with_row_proc(proc{|x| x.map{|h| row_proc.call(h)}}) if row_proc 334 ds 335 end
Private Instance Methods
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 342 def cast_tinyint_integer?(field) 343 field.length != 1 344 end
Sequel::Dataset#execute
# File lib/sequel/adapters/mysql.rb 346 def execute(sql, opts=OPTS) 347 opts = Hash[opts] 348 opts[:type] = :select 349 super 350 end
Handle correct quoting of strings using ::MySQL.quote.
# File lib/sequel/adapters/mysql.rb 353 def literal_string_append(sql, v) 354 sql << "'" << ::Mysql.quote(v) << "'" 355 end
Yield each row of the given result set r with columns cols as a hash with symbol keys
# File lib/sequel/adapters/mysql.rb 359 def yield_rows(r, cols) 360 while row = r.fetch_row 361 h = {} 362 cols.each{|n, p, i| v = row[i]; h[n] = (v && p) ? p.call(v) : v} 363 yield h 364 end 365 end