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

Dataset class for MySQL datasets accessed via the native driver.

Methods

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 316
316:       def call(type, bind_arguments={}, *values, &block)
317:         ps = to_prepared_statement(type, values)
318:         ps.extend(CallableStatementMethods)
319:         ps.call(bind_arguments, &block)
320:       end

Delete rows matching this dataset

[Source]

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

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

Don‘t allow graphing a dataset that splits multiple statements

[Source]

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

Insert a new value into this dataset

[Source]

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

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

[Source]

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

Replace (update or insert) the matching row.

[Source]

     # File lib/sequel/adapters/mysql.rb, line 376
376:       def replace(*args)
377:         execute_dui(replace_sql(*args)){|c| return c.insert_id}
378:       end

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 389
389:       def split_multiple_result_sets
390:         raise(Error, "Can't split multiple statements on a graphed dataset") if opts[:graph]
391:         ds = clone(:split_multiple_result_sets=>true)
392:         ds.row_proc = proc{|x| x.map{|h| row_proc.call(h)}} if row_proc
393:         ds
394:       end

Update the matching rows.

[Source]

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

[Validate]