Class: Mysql::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/og/adapter/mysql/override.rb,
lib/og/vendor/mysql.rb

Overview

:nodoc: all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Result.



565
566
567
568
569
570
571
572
573
574
# File 'lib/og/vendor/mysql.rb', line 565

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.



575
576
577
# File 'lib/og/vendor/mysql.rb', line 575

def eof
  @eof
end

Instance Method Details

#blank?Boolean

:nodoc: all

Returns:

  • (Boolean)


9
10
11
# File 'lib/og/adapter/mysql/override.rb', line 9

def blank?
  0 == num_rows
end

#data_seek(n) ⇒ Object



577
578
579
# File 'lib/og/vendor/mysql.rb', line 577

def data_seek(n)
  @current_row = n
end

#eachObject



661
662
663
664
665
# File 'lib/og/vendor/mysql.rb', line 661

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

#each_hash(with_table = nil) ⇒ Object



667
668
669
670
671
# File 'lib/og/vendor/mysql.rb', line 667

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

#each_rowObject



15
16
17
18
19
# File 'lib/og/adapter/mysql/override.rb', line 15

def each_row
  each do |row|
    yield(row, 0)
  end
end

#fetch_fieldObject



581
582
583
584
585
586
# File 'lib/og/vendor/mysql.rb', line 581

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

#fetch_field_direct(n) ⇒ Object



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

def fetch_field_direct(n)
  @fields[n]
end

#fetch_fieldsObject



588
589
590
# File 'lib/og/vendor/mysql.rb', line 588

def fetch_fields()
  @fields
end

#fetch_hash(with_table = nil) ⇒ Object



621
622
623
624
625
626
627
628
629
630
# File 'lib/og/vendor/mysql.rb', line 621

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



596
597
598
# File 'lib/og/vendor/mysql.rb', line 596

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

#fetch_rowObject Also known as: next



600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# File 'lib/og/vendor/mysql.rb', line 600

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



632
633
634
# File 'lib/og/vendor/mysql.rb', line 632

def field_seek(n)
  @current_field = n
end

#field_tellObject



636
637
638
# File 'lib/og/vendor/mysql.rb', line 636

def field_tell()
  @current_field
end

#fieldsObject



29
30
31
# File 'lib/og/adapter/mysql/override.rb', line 29

def fields
  fetch_fields.collect { |f| f.name }
end

#first_valueObject



21
22
23
24
25
# File 'lib/og/adapter/mysql/override.rb', line 21

def first_value
  val = fetch_row[0]
  free
  return val
end

#freeObject Also known as: close



640
641
642
643
# File 'lib/og/vendor/mysql.rb', line 640

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

#inspectObject



673
674
675
# File 'lib/og/vendor/mysql.rb', line 673

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

#num_fieldsObject



645
646
647
# File 'lib/og/vendor/mysql.rb', line 645

def num_fields()
  @field_count
end

#num_rowsObject



649
650
651
# File 'lib/og/vendor/mysql.rb', line 649

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

#row_seek(n) ⇒ Object



653
654
655
# File 'lib/og/vendor/mysql.rb', line 653

def row_seek(n)
  @current_row = n
end

#row_tellObject



657
658
659
# File 'lib/og/vendor/mysql.rb', line 657

def row_tell()
  @current_row
end