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 fields.
-
#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.
716 717 718 719 720 721 |
# 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 |
Instance Method Details
#calculate_field_max_length ⇒ Object
calculate max_length of all fields
725 726 727 728 729 730 731 732 733 734 735 736 |
# 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 ⇒ MysqlPR::Field
Returns current field.
739 740 741 742 743 744 |
# 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) ⇒ MysqlPR::Field
Return specified field
763 764 765 766 |
# 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 ⇒ Array<MysqlPR::Field>
Returns all fields.
769 770 771 |
# File 'lib/mysql-pr.rb', line 769 def fetch_fields @fields end |
#fetch_lengths ⇒ Array<Integer>
Returns length of each fields.
774 775 776 777 |
# 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) ⇒ Integer
Set field position
754 755 756 757 758 |
# File 'lib/mysql-pr.rb', line 754 def field_seek(n) ret = @field_index @field_index = n ret end |
#field_tell ⇒ Integer
Returns current field position.
747 748 749 |
# File 'lib/mysql-pr.rb', line 747 def field_tell @field_index end |
#num_fields ⇒ Integer
Returns number of fields.
780 781 782 |
# File 'lib/mysql-pr.rb', line 780 def num_fields @fields.size end |