Included Modules

Class/Module Index [+]

Quicksearch

Sequel::MySQL::Dataset

Dataset class for MySQL datasets accessed via the native driver.

Public Instance Methods

call(type, bind_arguments={}, *values, &block) click to toggle source

MySQL is different in that it supports prepared statements but not bound variables outside of prepared statements. The default implementation breaks the use of subselects in prepared statements, so extend the temporary prepared statement that this creates with a module that fixes it.

# File lib/sequel/adapters/mysql.rb, line 310
def call(type, bind_arguments={}, *values, &block)
  ps = to_prepared_statement(type, values)
  ps.extend(CallableStatementMethods)
  ps.call(bind_arguments, &block)
end
delete() click to toggle source

Delete rows matching this dataset

# File lib/sequel/adapters/mysql.rb, line 317
def delete
  execute_dui(delete_sql){|c| return c.affected_rows}
end
fetch_rows(sql, &block) 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, line 324
def fetch_rows(sql, &block)
  execute(sql) do |r|
    i = -1
    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 && f.length != 1 ? MYSQL_TYPES[2] : MYSQL_TYPES[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, &block)
    end
  end
  self
end
graph(*) click to toggle source

Don’t allow graphing a dataset that splits multiple statements

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

Insert a new value into this dataset

# File lib/sequel/adapters/mysql.rb, line 353
def insert(*values)
  execute_dui(insert_sql(*values)){|c| return c.insert_id}
end
prepare(type, name=nil, *values) click to toggle source

Store the given type of prepared statement in the associated database with the given name.

# File lib/sequel/adapters/mysql.rb, line 359
def prepare(type, name=nil, *values)
  ps = to_prepared_statement(type, values)
  ps.extend(PreparedStatementMethods)
  if name
    ps.prepared_statement_name = name
    db.prepared_statements[name] = ps
  end
  ps
end
replace(*args) click to toggle source

Replace (update or insert) the matching row.

# File lib/sequel/adapters/mysql.rb, line 370
def replace(*args)
  execute_dui(replace_sql(*args)){|c| return c.insert_id}
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, line 383
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
update(values={}) click to toggle source

Update the matching rows.

# File lib/sequel/adapters/mysql.rb, line 391
def update(values={})
  execute_dui(update_sql(values)){|c| return c.affected_rows}
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.