Class: Mysql::Result

Inherits:
Object show all
Defined in:
lib/og/store/mysql.rb,
lib/og/vendor/mysql.rb

Overview

Customize the standard mysql resultset to make more compatible with Og.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Result.



499
500
501
502
503
504
505
506
507
508
# File 'lib/og/vendor/mysql.rb', line 499

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.



509
510
511
# File 'lib/og/vendor/mysql.rb', line 509

def eof
  @eof
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/og/store/mysql.rb', line 35

def blank?
  0 == num_rows
end

#data_seek(n) ⇒ Object



511
512
513
# File 'lib/og/vendor/mysql.rb', line 511

def data_seek(n)
  @current_row = n
end

#eachObject



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

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

#each_hash(with_table = nil) ⇒ Object



602
603
604
605
606
# File 'lib/og/vendor/mysql.rb', line 602

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

#each_rowObject



41
42
43
44
45
# File 'lib/og/store/mysql.rb', line 41

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

#fetch_fieldObject



515
516
517
518
519
520
# File 'lib/og/vendor/mysql.rb', line 515

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

#fetch_field_direct(n) ⇒ Object



526
527
528
# File 'lib/og/vendor/mysql.rb', line 526

def fetch_field_direct(n)
  @fields[n]
end

#fetch_fieldsObject



522
523
524
# File 'lib/og/vendor/mysql.rb', line 522

def fetch_fields()
  @fields
end

#fetch_hash(with_table = nil) ⇒ Object



555
556
557
558
559
560
561
562
563
564
# File 'lib/og/vendor/mysql.rb', line 555

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



530
531
532
# File 'lib/og/vendor/mysql.rb', line 530

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

#fetch_rowObject Also known as: next



534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/og/vendor/mysql.rb', line 534

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



566
567
568
# File 'lib/og/vendor/mysql.rb', line 566

def field_seek(n)
  @current_field = n
end

#field_tellObject



570
571
572
# File 'lib/og/vendor/mysql.rb', line 570

def field_tell()
  @current_field
end

#fieldsObject



55
56
57
# File 'lib/og/store/mysql.rb', line 55

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

#first_valueObject



47
48
49
50
51
# File 'lib/og/store/mysql.rb', line 47

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

#freeObject Also known as: close



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

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

#inspectObject



608
609
610
# File 'lib/og/vendor/mysql.rb', line 608

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

#num_fieldsObject



580
581
582
# File 'lib/og/vendor/mysql.rb', line 580

def num_fields()
  @field_count
end

#num_rowsObject



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

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

#row_seek(n) ⇒ Object



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

def row_seek(n)
  @current_row = n
end

#row_tellObject



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

def row_tell()
  @current_row
end