class Mysql::Field
@!visibility public Field
class
Constants
- AUTO_INCREMENT_FLAG
- BINARY_FLAG
- BINCMP_FLAG
- BLOB_FLAG
- ENUM_FLAG
- GROUP_FLAG
- MULTIPLE_KEY_FLAG
- NOT_NULL_FLAG
Flag
- NUM_FLAG
- PART_KEY_FLAG
- PRI_KEY_FLAG
- SET_FLAG
- TIMESTAMP_FLAG
- TYPE_BIT
- TYPE_BLOB
- TYPE_CHAR
- TYPE_DATE
- TYPE_DATETIME
- TYPE_DECIMAL
Field
type- TYPE_DOUBLE
- TYPE_ENUM
- TYPE_FLOAT
- TYPE_GEOMETRY
- TYPE_INT24
- TYPE_INTERVAL
- TYPE_LONG
- TYPE_LONGLONG
- TYPE_LONG_BLOB
- TYPE_MEDIUM_BLOB
- TYPE_NEWDATE
- TYPE_NEWDECIMAL
- TYPE_NULL
- TYPE_SET
- TYPE_SHORT
- TYPE_STRING
- TYPE_TIME
- TYPE_TIMESTAMP
- TYPE_TINY
- TYPE_TINY_BLOB
- TYPE_VARCHAR
- TYPE_VAR_STRING
- TYPE_YEAR
- UNIQUE_FLAG
- UNIQUE_KEY_FLAG
- UNSIGNED_FLAG
- ZEROFILL_FLAG
Attributes
charsetnr[R]
@return [Integer] charset id number
db[R]
@return [String] database name
decimals[R]
@return [Integer] number of decimals
def[R]
@return [String] defualt value
default[R]
@return [String] defualt value
flags[R]
@return [Integer] flag
length[R]
@return [Integer] field length
max_length[W]
name[R]
@return [String] field name
org_name[R]
@return [String] original field name
org_table[R]
@return [String] original table name
result[RW]
@private
table[R]
@return [String] table name
type[R]
@return [Integer] field type
Public Class Methods
new(packet)
click to toggle source
@attr [Protocol::FieldPacket] packet
# File lib/vendor/mysql.rb, line 541 def initialize(packet) @db, @table, @org_table, @name, @org_name, @charsetnr, @length, @type, @flags, @decimals, @default = packet.db, packet.table, packet.org_table, packet.name, packet.org_name, packet.charsetnr, packet.length, packet.type, packet.flags, packet.decimals, packet.default @flags |= NUM_FLAG if is_num_type? @max_length = nil end
Public Instance Methods
hash()
click to toggle source
@return [Hash] field information
# File lib/vendor/mysql.rb, line 549 def hash { "name" => @name, "table" => @table, "def" => @default, "type" => @type, "length" => @length, "max_length" => max_length, "flags" => @flags, "decimals" => @decimals } end
inspect()
click to toggle source
@private
# File lib/vendor/mysql.rb, line 563 def inspect "#<Mysql::Field:#{@name}>" end
is_not_null?()
click to toggle source
@return [Boolean] true if not null field.
# File lib/vendor/mysql.rb, line 573 def is_not_null? @flags & NOT_NULL_FLAG != 0 end
is_num?()
click to toggle source
@return [Boolean] true if numeric field.
# File lib/vendor/mysql.rb, line 568 def is_num? @flags & NUM_FLAG != 0 end
is_pri_key?()
click to toggle source
@return [Boolean] true if primary key field.
# File lib/vendor/mysql.rb, line 578 def is_pri_key? @flags & PRI_KEY_FLAG != 0 end
max_length()
click to toggle source
@return [Integer] maximum width of the field for the result set
# File lib/vendor/mysql.rb, line 583 def max_length return @max_length if @max_length @max_length = 0 @result.calculate_field_max_length if @result @max_length end
Private Instance Methods
is_num_type?()
click to toggle source
# File lib/vendor/mysql.rb, line 594 def is_num_type? [TYPE_DECIMAL, TYPE_TINY, TYPE_SHORT, TYPE_LONG, TYPE_FLOAT, TYPE_DOUBLE, TYPE_LONGLONG, TYPE_INT24].include?(@type) || (@type == TYPE_TIMESTAMP && (@length == 14 || @length == 8)) end