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   insert   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

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 293
293:       def call(type, bind_arguments={}, values=nil)
294:         ps = to_prepared_statement(type, values)
295:         ps.extend(CallableStatementMethods)
296:         ps.call(bind_arguments)
297:       end

Delete rows matching this dataset

[Source]

     # File lib/sequel/adapters/mysql.rb, line 300
300:       def delete(opts = (defarg=true;nil))
301:         execute_dui(defarg ? delete_sql : delete_sql(opts)){|c| c.affected_rows}
302:       end

Yield all rows matching this dataset

[Source]

     # File lib/sequel/adapters/mysql.rb, line 305
305:       def fetch_rows(sql)
306:         execute(sql) do |r|
307:           column_types = []
308:           @columns = r.fetch_fields.map{|f| column_types << f.type; output_identifier(f.name)}
309:           while row = r.fetch_row
310:             h = {}
311:             @columns.each_with_index {|f, i| h[f] = convert_type(row[i], column_types[i])}
312:             yield h
313:           end
314:         end
315:         self
316:       end

Insert a new value into this dataset

[Source]

     # File lib/sequel/adapters/mysql.rb, line 319
319:       def insert(*values)
320:         execute_dui(insert_sql(*values)){|c| c.insert_id}
321:       end

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

[Source]

     # File lib/sequel/adapters/mysql.rb, line 325
325:       def prepare(type, name=nil, values=nil)
326:         ps = to_prepared_statement(type, values)
327:         ps.extend(PreparedStatementMethods)
328:         if name
329:           ps.prepared_statement_name = name
330:           db.prepared_statements[name] = ps
331:         end
332:         ps
333:       end

Replace (update or insert) the matching row.

[Source]

     # File lib/sequel/adapters/mysql.rb, line 336
336:       def replace(*args)
337:         execute_dui(replace_sql(*args)){|c| c.insert_id}
338:       end

Update the matching rows.

[Source]

     # File lib/sequel/adapters/mysql.rb, line 341
341:       def update(values={}, opts=(defarg=true;nil))
342:         execute_dui(defarg ? update_sql(values) : update_sql(values, opts)){|c| c.affected_rows}
343:       end

[Validate]