class Mysql::Result

@!visibility public Result set for simple query

Public Class Methods

new(fields, protocol=nil) click to toggle source

@private @param [Array<Mysql::Field>] fields @param [Mysql::Protocol] protocol

Calls superclass method Mysql::ResultBase::new
# File lib/vendor/mysql.rb, line 710
def initialize(fields, protocol=nil)
  super fields
  return unless protocol
  @records = protocol.retr_all_records fields
  fields.each{|f| f.result = self}  # for calculating max_field
end

Public Instance Methods

calculate_field_max_length() click to toggle source

@private calculate max_length of all fields

# File lib/vendor/mysql.rb, line 719
def calculate_field_max_length
  max_length = Array.new(@fields.size, 0)
  @records.each_with_index do |rec, i|
    rec = @records[i] = rec.to_a if rec.is_a? RawRecord
    max_length.each_index do |i|
      max_length[i] = rec[i].length if rec[i] && rec[i].length > max_length[i]
    end
  end
  max_length.each_with_index do |len, i|
    @fields[i].max_length = len
  end
end
fetch_field() click to toggle source

@return [Mysql::Field] current field

# File lib/vendor/mysql.rb, line 733
def fetch_field
  return nil if @field_index >= @fields.length
  ret = @fields[@field_index]
  @field_index += 1
  ret
end
fetch_field_direct(n) click to toggle source

Return specified field @param [Integer] n field index @return [Mysql::Field] field

# File lib/vendor/mysql.rb, line 757
def fetch_field_direct(n)
  raise ClientError, "invalid argument: #{n}" if n < 0 or n >= @fields.length
  @fields[n]
end
fetch_fields() click to toggle source

@return [Array<Mysql::Field>] all fields

# File lib/vendor/mysql.rb, line 763
def fetch_fields
  @fields
end
fetch_lengths() click to toggle source

@return [Array<Integer>] length of each fields

# File lib/vendor/mysql.rb, line 768
def fetch_lengths
  return nil unless @fetched_record
  @fetched_record.map{|c|c.nil? ? 0 : c.length}
end
field_seek(n) click to toggle source

Set field position @param [Integer] n field index @return [Integer] previous position

# File lib/vendor/mysql.rb, line 748
def field_seek(n)
  ret = @field_index
  @field_index = n
  ret
end
field_tell() click to toggle source

@return [Integer] current field position

# File lib/vendor/mysql.rb, line 741
def field_tell
  @field_index
end
num_fields() click to toggle source

@return [Integer] number of fields

# File lib/vendor/mysql.rb, line 774
def num_fields
  @fields.size
end