Class: Innodb::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/innodb/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, record) ⇒ Record

Returns a new instance of Record.



7
8
9
10
# File 'lib/innodb/record.rb', line 7

def initialize(page, record)
  @page = page
  @record = record
end

Instance Attribute Details

#page ⇒ Object (readonly)

Returns the value of attribute page.



4
5
6
# File 'lib/innodb/record.rb', line 4

def page
  @page
end

#record ⇒ Object

Returns the value of attribute record.



5
6
7
# File 'lib/innodb/record.rb', line 5

def record
  @record
end

Instance Method Details

#child_page_number ⇒ Object



40
41
42
# File 'lib/innodb/record.rb', line 40

def child_page_number
  record[:child_page_number]
end

#compare_key(other_key) ⇒ Object

Compare two arrays of fields to determine if they are equal. This follows the same comparison rules as strcmp and others:

0 = a is equal to b
-1 = a is less than b
+1 = a is greater than b


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/innodb/record.rb', line 73

def compare_key(other_key)
  Innodb::Stats.increment :compare_key

  return 0 if other_key.nil? && key.nil?
  return -1 if other_key.nil? || (!key.nil? && other_key.size < key.size)
  return +1 if key.nil? || (!other_key.nil? && other_key.size > key.size)

  key.each_index do |i|
    Innodb::Stats.increment :compare_key_field_comparison
    return -1 if other_key[i] < key[i][:value]
    return +1 if other_key[i] > key[i][:value]
  end

  return 0
end

#fields ⇒ Object



64
65
66
# File 'lib/innodb/record.rb', line 64

def fields
  @fields ||= uncached_fields
end

#header ⇒ Object



12
13
14
# File 'lib/innodb/record.rb', line 12

def header
  record[:header]
end

#key ⇒ Object



24
25
26
# File 'lib/innodb/record.rb', line 24

def key
  record[:key]
end

#key_string ⇒ Object



28
29
30
# File 'lib/innodb/record.rb', line 28

def key_string
  key && key.map { |r| "%s=%s" % [r[:name], r[:value].inspect] }.join(", ")
end

#next ⇒ Object



20
21
22
# File 'lib/innodb/record.rb', line 20

def next
  record[:next]
end

#offset ⇒ Object



16
17
18
# File 'lib/innodb/record.rb', line 16

def offset
  record[:offset]
end

#row ⇒ Object



32
33
34
# File 'lib/innodb/record.rb', line 32

def row
  record[:row]
end

#row_string ⇒ Object



36
37
38
# File 'lib/innodb/record.rb', line 36

def row_string
  row && row.map { |r| "%s=%s" % [r[:name], r[:value].inspect] }.join(", ")
end

#string ⇒ Object



44
45
46
47
48
49
50
# File 'lib/innodb/record.rb', line 44

def string
  if child_page_number
    "(%s) → #%s" % [key_string, child_page_number]
  else
    "(%s) → (%s)" % [key_string, row_string]
  end
end

#uncached_fields ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/innodb/record.rb', line 52

def uncached_fields
  fields_hash = {}
  [:key, :row].each do |group|
    if record[group]
      record[group].each do |column|
        fields_hash[column[:name]] = column[:value]
      end
    end
  end
  fields_hash
end