class Mysql::ResultBase
@!visibility public Result
set
Attributes
@return [Array<Mysql::Field>] field list
Public Class Methods
@param [Array of Mysql::Field] fields
# File lib/vendor/mysql.rb, line 609 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
Set record position @param [Integer] n record index @return [self] self
# File lib/vendor/mysql.rb, line 684 def data_seek(n) @index = n self end
Iterate block with record. @yield [Array] record data @return [self] self. If block is not specified, this returns Enumerator.
# File lib/vendor/mysql.rb, line 661 def each(&block) return enum_for(:each) unless block while rec = fetch block.call rec end self end
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/vendor/mysql.rb, line 673 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
@return [Array] current record data
# File lib/vendor/mysql.rb, line 630 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
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/vendor/mysql.rb, line 644 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
ignore @return [void]
# File lib/vendor/mysql.rb, line 620 def free end
Set current position of record @param [Integer] n record index @return [Integer] previous position
# File lib/vendor/mysql.rb, line 697 def row_seek(n) ret = @index @index = n ret end
@return [Integer] current record position
# File lib/vendor/mysql.rb, line 690 def row_tell @index end
@return [Integer] number of record
# File lib/vendor/mysql.rb, line 624 def size @records.size end