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 306
    306:       def call(type, bind_arguments={}, *values, &block)
    307:         ps = to_prepared_statement(type, values)
    308:         ps.extend(CallableStatementMethods)
    309:         ps.call(bind_arguments, &block)
    310:       end

delete()

Delete rows matching this dataset

[Source]

         # File lib/sequel/adapters/mysql.rb, line 313
    313:       def delete
    314:         execute_dui(delete_sql){|c| c.affected_rows}
    315:       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 320
    320:       def fetch_rows(sql, &block)
    321:         execute(sql) do |r|
    322:           i = -1
    323:           cols = r.fetch_fields.map{|f| [output_identifier(f.name), MYSQL_TYPES[f.type], i+=1]}
    324:           @columns = cols.map{|c| c.first}
    325:           if opts[:split_multiple_result_sets]
    326:             s = []
    327:             yield_rows(r, cols){|h| s << h}
    328:             yield s
    329:           else
    330:             yield_rows(r, cols, &block)
    331:           end
    332:         end
    333:         self
    334:       end

graph(*)

Don‘t allow graphing a dataset that splits multiple statements

[Source]

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

insert(*values)

Insert a new value into this dataset

[Source]

         # File lib/sequel/adapters/mysql.rb, line 343
    343:       def insert(*values)
    344:         execute_dui(insert_sql(*values)){|c| c.insert_id}
    345:       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 349
    349:       def prepare(type, name=nil, *values)
    350:         ps = to_prepared_statement(type, values)
    351:         ps.extend(PreparedStatementMethods)
    352:         if name
    353:           ps.prepared_statement_name = name
    354:           db.prepared_statements[name] = ps
    355:         end
    356:         ps
    357:       end

replace(*args)

Replace (update or insert) the matching row.

[Source]

         # File lib/sequel/adapters/mysql.rb, line 360
    360:       def replace(*args)
    361:         execute_dui(replace_sql(*args)){|c| c.insert_id}
    362:       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 373
    373:       def split_multiple_result_sets
    374:         raise(Error, "Can't split multiple statements on a graphed dataset") if opts[:graph]
    375:         ds = clone(:split_multiple_result_sets=>true)
    376:         ds.row_proc = proc{|x| x.map{|h| row_proc.call(h)}} if row_proc
    377:         ds
    378:       end

update(values={})

Update the matching rows.

[Source]

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

[Validate]