Class: Mysql::Result

Inherits:
Object show all
Defined in:
lib/mysql.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mysql, fields, field_count, data = nil) ⇒ Result

Returns a new instance of Result.



580
581
582
583
584
585
586
587
588
589
# File 'lib/mysql.rb', line 580

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

Instance Attribute Details

#eofObject

Returns the value of attribute eof.



590
591
592
# File 'lib/mysql.rb', line 590

def eof
  @eof
end

Instance Method Details

#data_seek(n) ⇒ Object



592
593
594
# File 'lib/mysql.rb', line 592

def data_seek(n)
  @current_row = n
end

#eachObject



676
677
678
679
680
# File 'lib/mysql.rb', line 676

def each()
  while row = fetch_row do
	yield row
  end
end

#each_hash(with_table = nil) ⇒ Object



682
683
684
685
686
# File 'lib/mysql.rb', line 682

def each_hash(with_table=nil)
  while hash = fetch_hash(with_table) do
	yield hash
  end
end

#fetch_fieldObject



596
597
598
599
600
601
# File 'lib/mysql.rb', line 596

def fetch_field()
  return if @current_field >= @field_count
  f = @fields[@current_field]
  @current_field += 1
  f
end

#fetch_field_direct(n) ⇒ Object



607
608
609
# File 'lib/mysql.rb', line 607

def fetch_field_direct(n)
  @fields[n]
end

#fetch_fieldsObject



603
604
605
# File 'lib/mysql.rb', line 603

def fetch_fields()
  @fields
end

#fetch_hash(with_table = nil) ⇒ Object



636
637
638
639
640
641
642
643
644
645
# File 'lib/mysql.rb', line 636

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

#fetch_lengthsObject



611
612
613
# File 'lib/mysql.rb', line 611

def fetch_lengths()
  @data ? @data[@current_row].map{|i| i ? i.length : 0} : @lengths
end

#fetch_rowObject



615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
# File 'lib/mysql.rb', line 615

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

#field_seek(n) ⇒ Object



647
648
649
# File 'lib/mysql.rb', line 647

def field_seek(n)
  @current_field = n
end

#field_tellObject



651
652
653
# File 'lib/mysql.rb', line 651

def field_tell()
  @current_field
end

#freeObject



655
656
657
658
# File 'lib/mysql.rb', line 655

def free()
  @handle.skip_result
  @handle = @fields = @data = nil
end

#inspectObject



688
689
690
# File 'lib/mysql.rb', line 688

def inspect()
  "#<#{self.class}>"
end

#num_fieldsObject



660
661
662
# File 'lib/mysql.rb', line 660

def num_fields()
  @field_count
end

#num_rowsObject



664
665
666
# File 'lib/mysql.rb', line 664

def num_rows()
  @data ? @data.length : @row_count
end

#row_seek(n) ⇒ Object



668
669
670
# File 'lib/mysql.rb', line 668

def row_seek(n)
  @current_row = n
end

#row_tellObject



672
673
674
# File 'lib/mysql.rb', line 672

def row_tell()
  @current_row
end