class MysqlPR::Result

@!visibility public Result set for simple query

Public Class Methods

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

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

Calls superclass method MysqlPR::ResultBase::new
# File lib/mysql-pr.rb, line 716
def initialize(fields, protocol=nil)
  super fields
  return unless protocol
  @records = protocol.retr_all_records fields.size
  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/mysql-pr.rb, line 725
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 [MysqlPR::Field] current field

# File lib/mysql-pr.rb, line 739
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 [MysqlPR::Field] field

# File lib/mysql-pr.rb, line 763
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<MysqlPR::Field>] all fields

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

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

# File lib/mysql-pr.rb, line 774
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/mysql-pr.rb, line 754
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/mysql-pr.rb, line 747
def field_tell
  @field_index
end
num_fields() click to toggle source

@return [Integer] number of fields

# File lib/mysql-pr.rb, line 780
def num_fields
  @fields.size
end