Class: Sequel::MySQL::Dataset

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

Dataset class for MySQL datasets accessed via the native driver.

### Methods

call delete fetch_rows insert literal prepare replace 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=nil)

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_core/adapters/mysql.rb, line 261
    261:       def call(type, bind_arguments={}, values=nil)
    262:         ps = to_prepared_statement(type, values)
    263:         ps.extend(CallableStatementMethods)
    264:         ps.call(bind_arguments)
    265:       end

delete(opts = nil)

Delete rows matching this dataset

[Source]

         # File lib/sequel_core/adapters/mysql.rb, line 268
    268:       def delete(opts = nil)
    269:         execute_dui(delete_sql(opts)){|c| c.affected_rows}
    270:       end

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

Yield all rows matching this dataset

[Source]

         # File lib/sequel_core/adapters/mysql.rb, line 273
    273:       def fetch_rows(sql)
    274:         execute(sql) do |r|
    275:           column_types = []
    276:           @columns = r.fetch_fields.map{|f| column_types << f.type; output_identifier(f.name)}
    277:           while row = r.fetch_row
    278:             h = {}
    279:             @columns.each_with_index {|f, i| h[f] = convert_type(row[i], column_types[i])}
    280:             yield h
    281:           end
    282:         end
    283:         self
    284:       end

insert(*values)

Insert a new value into this dataset

[Source]

         # File lib/sequel_core/adapters/mysql.rb, line 287
    287:       def insert(*values)
    288:         execute_dui(insert_sql(*values)){|c| c.insert_id}
    289:       end

literal(v)

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

[Source]

         # File lib/sequel_core/adapters/mysql.rb, line 292
    292:       def literal(v)
    293:         case v
    294:         when LiteralString
    295:           v
    296:         when String
    297:           "'#{::Mysql.quote(v)}'"
    298:         else
    299:           super
    300:         end
    301:       end

prepare(type, name=nil, values=nil)

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

[Source]

         # File lib/sequel_core/adapters/mysql.rb, line 305
    305:       def prepare(type, name=nil, values=nil)
    306:         ps = to_prepared_statement(type, values)
    307:         ps.extend(PreparedStatementMethods)
    308:         if name
    309:           ps.prepared_statement_name = name
    310:           db.prepared_statements[name] = ps
    311:         end
    312:         ps
    313:       end

replace(*args)

Replace (update or insert) the matching row.

[Source]

         # File lib/sequel_core/adapters/mysql.rb, line 316
    316:       def replace(*args)
    317:         execute_dui(replace_sql(*args)){|c| c.insert_id}
    318:       end

update(*args)

Update the matching rows.

[Source]

         # File lib/sequel_core/adapters/mysql.rb, line 321
    321:       def update(*args)
    322:         execute_dui(update_sql(*args)){|c| c.affected_rows}
    323:       end

[Validate]