Class: Innodb::Field
- Inherits:
-
Object
- Object
- Innodb::Field
- Defined in:
- lib/innodb/field.rb
Overview
A single field in an InnoDB record (within an INDEX page). This class provides essential information to parse records, including the length of the fixed-width and variable-width portion of the field.
Constant Summary collapse
- EXTERN_FIELD_SIZE =
Size of a reference to data stored externally to the page.
20
Instance Attribute Summary collapse
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#extern?(record) ⇒ Boolean
Return whether a part of this field is stored externally (off-page).
-
#initialize(position, data_type, *properties) ⇒ Field
constructor
A new instance of Field.
-
#length(record) ⇒ Object
Return the actual length of this variable-length field.
-
#null?(record) ⇒ Boolean
Return whether this field is NULL.
-
#read(record, cursor) ⇒ Object
Read an InnoDB encoded data field.
-
#read_extern(record, cursor) ⇒ Object
Read an InnoDB external pointer field.
Constructor Details
Instance Attribute Details
#position ⇒ Object (readonly)
Returns the value of attribute position.
8 9 10 |
# File 'lib/innodb/field.rb', line 8 def position @position end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/innodb/field.rb', line 8 def type @type end |
Instance Method Details
#extern?(record) ⇒ Boolean
Return whether a part of this field is stored externally (off-page).
24 25 26 |
# File 'lib/innodb/field.rb', line 24 def extern?(record) record[:header][:field_externs][position] end |
#length(record) ⇒ Object
Return the actual length of this variable-length field.
29 30 31 32 33 34 35 36 |
# File 'lib/innodb/field.rb', line 29 def length(record) if type.variable? len = record[:header][:field_lengths][position] else len = type.length end extern?(record) ? len - EXTERN_FIELD_SIZE : len end |
#null?(record) ⇒ Boolean
Return whether this field is NULL.
19 20 21 |
# File 'lib/innodb/field.rb', line 19 def null?(record) type.nullable? && record[:header][:field_nulls][position] end |
#read(record, cursor) ⇒ Object
Read an InnoDB encoded data field.
39 40 41 42 |
# File 'lib/innodb/field.rb', line 39 def read(record, cursor) return :NULL if null?(record) cursor.name(type.name) { type.reader.read(cursor, length(record)) } end |
#read_extern(record, cursor) ⇒ Object
Read an InnoDB external pointer field.
45 46 47 48 |
# File 'lib/innodb/field.rb', line 45 def read_extern(record, cursor) return nil if not extern?(record) cursor.name(type.name) { type.reader.read_extern(cursor) } end |