Class | Sequel::MySQL::Dataset
In: | lib/sequel/adapters/mysql.rb
Parent: | Sequel::Dataset

Dataset class for MySQL datasets accessed via the native driver.

### Methods

call delete fetch_rows graph insert prepare replace split_multiple_result_sets update

### Included Modules

Sequel::MySQL::DatasetMethods StoredProcedures

### Classes and Modules

Module Sequel::MySQL::Dataset::CallableStatementMethods
Module Sequel::MySQL::Dataset::PreparedStatementMethods
Module Sequel::MySQL::Dataset::StoredProcedureMethods

### Public Instance methods

call(type, bind_arguments={}, *values, &block)

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.

[Source]

         # File lib/sequel/adapters/mysql.rb, line 318
    318:       def call(type, bind_arguments={}, *values, &block)
    319:         ps = to_prepared_statement(type, values)
    320:         ps.extend(CallableStatementMethods)
    321:         ps.call(bind_arguments, &block)
    322:       end

delete()

Delete rows matching this dataset

[Source]

         # File lib/sequel/adapters/mysql.rb, line 325
    325:       def delete
    326:         execute_dui(delete_sql){|c| return c.affected_rows}
    327:       end

fetch_rows(sql) {|s| ...}

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.

[Source]

         # File lib/sequel/adapters/mysql.rb, line 332
    332:       def fetch_rows(sql, &block)
    333:         execute(sql) do |r|
    334:           i = -1
    335:           cols = r.fetch_fields.map do |f|
    336:             # Pretend tinyint is another integer type if its length is not 1, to
    337:             # avoid casting to boolean if Sequel::MySQL.convert_tinyint_to_bool
    338:             # is set.
    339:             type_proc = f.type == 1 && f.length != 1 ? MYSQL_TYPES[2] : MYSQL_TYPES[f.type]
    340:             [output_identifier(f.name), type_proc, i+=1]
    341:           end
    342:           @columns = cols.map{|c| c.first}
    343:           if opts[:split_multiple_result_sets]
    344:             s = []
    345:             yield_rows(r, cols){|h| s << h}
    346:             yield s
    347:           else
    348:             yield_rows(r, cols, &block)
    349:           end
    350:         end
    351:         self
    352:       end

graph(*)

Don‘t allow graphing a dataset that splits multiple statements

[Source]

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

insert(*values)

Insert a new value into this dataset

[Source]

         # File lib/sequel/adapters/mysql.rb, line 361
    361:       def insert(*values)
    362:         execute_dui(insert_sql(*values)){|c| return c.insert_id}
    363:       end

prepare(type, name=nil, *values)

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

[Source]

         # File lib/sequel/adapters/mysql.rb, line 367
    367:       def prepare(type, name=nil, *values)
    368:         ps = to_prepared_statement(type, values)
    369:         ps.extend(PreparedStatementMethods)
    370:         if name
    371:           ps.prepared_statement_name = name
    372:           db.prepared_statements[name] = ps
    373:         end
    374:         ps
    375:       end

replace(*args)

Replace (update or insert) the matching row.

[Source]

         # File lib/sequel/adapters/mysql.rb, line 378
    378:       def replace(*args)
    379:         execute_dui(replace_sql(*args)){|c| return c.insert_id}
    380:       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.

[Source]

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

update(values={})

Update the matching rows.

[Source]

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

[Validate]