Class Mysql::Result
In: lib/mysql.rb
Parent: Object

Methods

Attributes

eof  [RW] 

Public Class methods

[Source]

# File lib/mysql.rb, line 500
    def initialize(mysql, fields, field_count, data=nil)
      @handle = mysql
      @fields = fields
      @field_count = field_count
      @data = data
      @current_field = 0
      @current_row = 0
      @eof = false
      @row_count = 0
    end

Public Instance methods

[Source]

# File lib/mysql.rb, line 512
    def data_seek(n)
      @current_row = n
    end

[Source]

# File lib/mysql.rb, line 597
    def each()
      while row = fetch_row do
        yield row
      end
    end

[Source]

# File lib/mysql.rb, line 603
    def each_hash(with_table=nil)
      while hash = fetch_hash(with_table) do
        yield hash
      end
    end

[Source]

# File lib/mysql.rb, line 516
    def fetch_field()
      return if @current_field >= @field_count
      f = @fields[@current_field]
      @current_field += 1
      f
    end

[Source]

# File lib/mysql.rb, line 527
    def fetch_field_direct(n)
      @fields[n]
    end

[Source]

# File lib/mysql.rb, line 523
    def fetch_fields()
      @fields
    end

[Source]

# File lib/mysql.rb, line 556
    def fetch_hash(with_table=nil)
      row = fetch_row
      return if row == nil
      hash = {}
      @fields.each_index do |i|
        f = with_table ? @fields[i].table+"."+@fields[i].name : @fields[i].name
        hash[f] = row[i]
      end
      hash
    end

[Source]

# File lib/mysql.rb, line 531
    def fetch_lengths()
      @data ? @data[@current_row].map{|i| i ? i.length : 0} : @lengths
    end

[Source]

# File lib/mysql.rb, line 535
    def fetch_row()
      if @data then
        if @current_row >= @data.length then
          @handle.status = :STATUS_READY
          return
        end
        ret = @data[@current_row]
        @current_row += 1
      else
        return if @eof
        ret = @handle.read_one_row @field_count
        if ret == nil then
          @eof = true
          return
        end
        @lengths = ret.map{|i| i ? i.length : 0}
        @row_count += 1
      end
      ret
    end

[Source]

# File lib/mysql.rb, line 567
    def field_seek(n)
      @current_field = n
    end

[Source]

# File lib/mysql.rb, line 571
    def field_tell()
      @current_field
    end

[Source]

# File lib/mysql.rb, line 575
    def free()
      @handle.skip_result
      @handle = @fields = @data = nil
      GC::start
    end

[Source]

# File lib/mysql.rb, line 609
    def inspect()
      "#<#{self.class}>"
    end

[Source]

# File lib/mysql.rb, line 581
    def num_fields()
      @field_count
    end

[Source]

# File lib/mysql.rb, line 585
    def num_rows()
      @data ? @data.length : @row_count
    end

[Source]

# File lib/mysql.rb, line 589
    def row_seek(n)
      @current_row = n
    end

[Source]

# File lib/mysql.rb, line 593
    def row_tell()
      @current_row
    end

[Validate]