class Sequel::Mysql2::Dataset

Dataset class for MySQL datasets accessed via the native driver.

Constants

STREAMING_SUPPORTED

Public Instance Methods

fetch_rows(sql) { |h| ... } click to toggle source

Yield all rows matching this dataset.

# File lib/sequel/adapters/mysql2.rb, line 155
def fetch_rows(sql)
  execute(sql) do |r|
    self.columns = if identifier_output_method
      r.fields.map!{|c| output_identifier(c.to_s)}
    else
      r.fields
    end
    r.each(:cast_booleans=>convert_tinyint_to_bool?){|h| yield h}
  end
  self
end
paged_each(opts=OPTS, &block) click to toggle source

Use streaming to implement paging if Mysql2 supports it.

Calls superclass method Sequel::Dataset#paged_each
# File lib/sequel/adapters/mysql2.rb, line 168
def paged_each(opts=OPTS, &block)
  if STREAMING_SUPPORTED
    stream.each(&block)
  else
    super
  end
end
stream() click to toggle source

Return a clone of the dataset that will stream rows when iterating over the result set, so it can handle large datasets that won't fit in memory (Requires mysql 0.3.12+ to have an effect).

# File lib/sequel/adapters/mysql2.rb, line 179
def stream
  clone(:stream=>true)
end

Private Instance Methods

convert_tinyint_to_bool?() click to toggle source

Whether to cast tinyint(1) columns to integer instead of boolean. By default, uses the opposite of the database's convert_tinyint_to_bool setting. Exists for compatibility with the mysql adapter.

# File lib/sequel/adapters/mysql2.rb, line 188
def convert_tinyint_to_bool?
  @db.convert_tinyint_to_bool
end
execute(sql, opts=OPTS) click to toggle source

Set the :type option to :select if it hasn't been set.

Calls superclass method Sequel::Dataset#execute
# File lib/sequel/adapters/mysql2.rb, line 193
def execute(sql, opts=OPTS)
  opts = Hash[opts]
  opts[:type] = :select
  opts[:stream] = @opts[:stream]
  super
end
literal_string_append(sql, v) click to toggle source

Handle correct quoting of strings using ::Mysql2::Client#escape.

# File lib/sequel/adapters/mysql2.rb, line 201
def literal_string_append(sql, v)
  s = begin
    db.synchronize(@opts[:server]) do |c| 
      begin
        c.escape(v)
      rescue ::Mysql2::Error => e
        db.send(:raise_error, e)
      end
    end
  end

  sql << APOS << s << APOS
end