class Mysql::ResultBase

@!visibility public Result set

Attributes

fields[R]

@return [Array<Mysql::Field>] field list

Public Class Methods

new(fields) click to toggle source

@param [Array of Mysql::Field] fields

# File lib/mysql.rb, line 596
def initialize(fields)
  @fields = fields
  @field_index = 0             # index of field
  @records = []                # all records
  @index = 0                   # index of record
  @fieldname_with_table = nil
  @fetched_record = nil
end

Public Instance Methods

data_seek(n) click to toggle source

Set record position @param [Integer] n record index @return [self] self

# File lib/mysql.rb, line 671
def data_seek(n)
  @index = n
  self
end
each(&block) click to toggle source

Iterate block with record. @yield [Array] record data @return [self] self. If block is not specified, this returns Enumerator.

# File lib/mysql.rb, line 648
def each(&block)
  return enum_for(:each) unless block
  while rec = fetch
    block.call rec
  end
  self
end
each_hash(with_table=nil, &block) click to toggle source

Iterate block with record as Hash. @param [Boolean] with_table if true, hash key is “table_name.field_name”. @yield [Hash] record data @return [self] self. If block is not specified, this returns Enumerator.

# File lib/mysql.rb, line 660
def each_hash(with_table=nil, &block)
  return enum_for(:each_hash, with_table) unless block
  while rec = fetch_hash(with_table)
    block.call rec
  end
  self
end
fetch() click to toggle source

@return [Array] current record data

# File lib/mysql.rb, line 617
def fetch
  @fetched_record = nil
  return nil if @index >= @records.size
  @records[@index] = @records[@index].to_a unless @records[@index].is_a? Array
  @fetched_record = @records[@index]
  @index += 1
  return @fetched_record
end
Also aliased as: fetch_row
fetch_hash(with_table=nil) click to toggle source

Return data of current record as Hash. The hash key is field name. @param [Boolean] with_table if true, hash key is “table_name.field_name”. @return [Hash] current record data

# File lib/mysql.rb, line 631
def fetch_hash(with_table=nil)
  row = fetch
  return nil unless row
  if with_table and @fieldname_with_table.nil?
    @fieldname_with_table = @fields.map{|f| [f.table, f.name].join(".")}
  end
  ret = {}
  @fields.each_index do |i|
    fname = with_table ? @fieldname_with_table[i] : @fields[i].name
    ret[fname] = row[i]
  end
  ret
end
fetch_row()
Alias for: fetch
free() click to toggle source

ignore @return [void]

# File lib/mysql.rb, line 607
def free
end
num_rows()
Alias for: size
row_seek(n) click to toggle source

Set current position of record @param [Integer] n record index @return [Integer] previous position

# File lib/mysql.rb, line 684
def row_seek(n)
  ret = @index
  @index = n
  ret
end
row_tell() click to toggle source

@return [Integer] current record position

# File lib/mysql.rb, line 677
def row_tell
  @index
end
size() click to toggle source

@return [Integer] number of record

# File lib/mysql.rb, line 611
def size
  @records.size
end
Also aliased as: num_rows