Class: MysqlPR::Result
- Inherits:
-
ResultBase
- Object
- ResultBase
- MysqlPR::Result
- Defined in:
- lib/mysql-pr.rb
Overview
Result set for simple query
Instance Attribute Summary
Attributes inherited from ResultBase
Instance Method Summary collapse
-
#calculate_field_max_length ⇒ Object
Calculate max_length of all fields.
-
#fetch_field ⇒ MysqlPR::Field?
Current field.
-
#fetch_field_direct(n) ⇒ MysqlPR::Field
Return specified field.
-
#fetch_fields ⇒ Array<MysqlPR::Field>
All fields.
-
#fetch_lengths ⇒ Array<Integer>?
Length of each field.
-
#field_seek(n) ⇒ Integer
Set field position.
-
#field_tell ⇒ Integer
Current field position.
-
#initialize(fields, protocol = nil) ⇒ Result
constructor
A new instance of Result.
-
#num_fields ⇒ Integer
Number of fields.
Methods inherited from ResultBase
#data_seek, #each, #each_hash, #fetch, #fetch_hash, #free, #row_seek, #row_tell, #size
Constructor Details
#initialize(fields, protocol = nil) ⇒ Result
Returns a new instance of Result.
746 747 748 749 750 751 752 |
# File 'lib/mysql-pr.rb', line 746 def initialize(fields, protocol = nil) super(fields) return unless protocol @records = protocol.retr_all_records(fields.size) fields.each { |f| f.result = self } end |
Instance Method Details
#calculate_field_max_length ⇒ Object
Calculate max_length of all fields
755 756 757 758 759 760 761 762 763 764 765 766 |
# File 'lib/mysql-pr.rb', line 755 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 |j| max_length[j] = rec[j].length if rec[j] && rec[j].length > max_length[j] end end max_length.each_with_index do |len, i| @fields[i].max_length = len end end |
#fetch_field ⇒ MysqlPR::Field?
Returns current field.
769 770 771 772 773 774 775 |
# File 'lib/mysql-pr.rb', line 769 def fetch_field return nil if @field_index >= @fields.length ret = @fields[@field_index] @field_index += 1 ret end |
#fetch_field_direct(n) ⇒ MysqlPR::Field
Return specified field
794 795 796 797 798 |
# File 'lib/mysql-pr.rb', line 794 def fetch_field_direct(n) raise ClientError, "invalid argument: #{n}" if n.negative? || n >= @fields.length @fields[n] end |
#fetch_fields ⇒ Array<MysqlPR::Field>
Returns all fields.
801 802 803 |
# File 'lib/mysql-pr.rb', line 801 def fetch_fields @fields end |
#fetch_lengths ⇒ Array<Integer>?
Returns length of each field.
806 807 808 809 810 |
# File 'lib/mysql-pr.rb', line 806 def fetch_lengths return nil unless @fetched_record @fetched_record.map { |c| c.nil? ? 0 : c.length } end |
#field_seek(n) ⇒ Integer
Set field position
785 786 787 788 789 |
# File 'lib/mysql-pr.rb', line 785 def field_seek(n) ret = @field_index @field_index = n ret end |
#field_tell ⇒ Integer
Returns current field position.
778 779 780 |
# File 'lib/mysql-pr.rb', line 778 def field_tell @field_index end |
#num_fields ⇒ Integer
Returns number of fields.
813 814 815 |
# File 'lib/mysql-pr.rb', line 813 def num_fields @fields.size end |