Class: DB::MariaDB::Native::Field

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/db/mariadb/native/field.rb

Overview

A field (column) in a result set with metadata and type information.

Instance Method Summary collapse

Instance Method Details

#boolean?Boolean

Check if this field represents a boolean type.

Returns:

  • (Boolean)


108
109
110
# File 'lib/db/mariadb/native/field.rb', line 108

def boolean?
  self[:length] == 1 && (self[:type] == :tiny || self[:type] == :long)
end

#inspectObject

Generate a string representation of the field.



130
131
132
# File 'lib/db/mariadb/native/field.rb', line 130

def inspect
  "\#<#{self.class} name=#{self.name} type=#{self.type} length=#{self[:length]}>"
end

#nameObject

Get the field name.



114
115
116
# File 'lib/db/mariadb/native/field.rb', line 114

def name
  self[:name]
end

#typeObject

Get the field type, with boolean detection.



120
121
122
123
124
125
126
# File 'lib/db/mariadb/native/field.rb', line 120

def type
  if boolean?
    :boolean
  else
    self[:type]
  end
end