Class: Mysql::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql.rb,
lib/mysql/compat.rb,
lib/mysql/constants.rb

Overview

Field class

Constant Summary collapse

TYPE_DECIMAL =

Field type

0
TYPE_TINY =
1
TYPE_SHORT =
2
TYPE_LONG =
3
TYPE_FLOAT =
4
TYPE_DOUBLE =
5
TYPE_NULL =
6
TYPE_TIMESTAMP =
7
TYPE_LONGLONG =
8
TYPE_INT24 =
9
TYPE_DATE =
10
TYPE_TIME =
11
TYPE_DATETIME =
12
TYPE_YEAR =
13
TYPE_NEWDATE =
14
TYPE_VARCHAR =
15
TYPE_BIT =
16
TYPE_NEWDECIMAL =
246
TYPE_ENUM =
247
TYPE_SET =
248
TYPE_TINY_BLOB =
249
TYPE_MEDIUM_BLOB =
250
TYPE_LONG_BLOB =
251
TYPE_BLOB =
252
TYPE_VAR_STRING =
253
TYPE_STRING =
254
TYPE_GEOMETRY =
255
TYPE_CHAR =
TYPE_TINY
TYPE_INTERVAL =
TYPE_ENUM
NOT_NULL_FLAG =

Flag

1
PRI_KEY_FLAG =
2
UNIQUE_KEY_FLAG =
4
MULTIPLE_KEY_FLAG =
8
BLOB_FLAG =
16
UNSIGNED_FLAG =
32
ZEROFILL_FLAG =
64
BINARY_FLAG =
128
ENUM_FLAG =
256
AUTO_INCREMENT_FLAG =
512
TIMESTAMP_FLAG =
1024
SET_FLAG =
2048
NUM_FLAG =
32768
PART_KEY_FLAG =
16384
GROUP_FLAG =
32768
UNIQUE_FLAG =
65536
BINCMP_FLAG =
131072

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(packet) ⇒ Field

Argument

packet
Protocol::FieldPacket


438
439
440
441
442
# File 'lib/mysql.rb', line 438

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?
end

Instance Attribute Details

#charsetnrObject (readonly)

Returns the value of attribute charsetnr.



433
434
435
# File 'lib/mysql.rb', line 433

def charsetnr
  @charsetnr
end

#dbObject (readonly)

Returns the value of attribute db.



433
434
435
# File 'lib/mysql.rb', line 433

def db
  @db
end

#decimalsObject (readonly)

Returns the value of attribute decimals.



433
434
435
# File 'lib/mysql.rb', line 433

def decimals
  @decimals
end

#defaultObject (readonly) Also known as: def

Returns the value of attribute default.



433
434
435
# File 'lib/mysql.rb', line 433

def default
  @default
end

#flagsObject (readonly)

Returns the value of attribute flags.



433
434
435
# File 'lib/mysql.rb', line 433

def flags
  @flags
end

#lengthObject (readonly)

Returns the value of attribute length.



433
434
435
# File 'lib/mysql.rb', line 433

def length
  @length
end

#max_lengthObject

Returns the value of attribute max_length.



200
201
202
# File 'lib/mysql/compat.rb', line 200

def max_length
  @max_length
end

#nameObject (readonly)

Returns the value of attribute name.



433
434
435
# File 'lib/mysql.rb', line 433

def name
  @name
end

#org_nameObject (readonly)

Returns the value of attribute org_name.



433
434
435
# File 'lib/mysql.rb', line 433

def org_name
  @org_name
end

#org_tableObject (readonly)

Returns the value of attribute org_table.



433
434
435
# File 'lib/mysql.rb', line 433

def org_table
  @org_table
end

#tableObject (readonly)

Returns the value of attribute table.



433
434
435
# File 'lib/mysql.rb', line 433

def table
  @table
end

#typeObject (readonly)

Returns the value of attribute type.



433
434
435
# File 'lib/mysql.rb', line 433

def type
  @type
end

Instance Method Details

#hashObject



201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/mysql/compat.rb', line 201

def hash
  {
    "name"       => @name,
    "table"      => @table,
    "def"        => @default,
    "type"       => @type,
    "length"     => @length,
    "max_length" => @max_length,
    "flags"      => @flags,
    "decimals"   => @decimals
  }
end

#inspectObject



213
214
215
# File 'lib/mysql/compat.rb', line 213

def inspect
  "#<Mysql::Field:#{@name}>"
end

#is_not_null?Boolean

Return true if not null field.

Returns:

  • (Boolean)


450
451
452
# File 'lib/mysql.rb', line 450

def is_not_null?
  @flags & NOT_NULL_FLAG != 0
end

#is_num?Boolean

Return true if numeric field.

Returns:

  • (Boolean)


445
446
447
# File 'lib/mysql.rb', line 445

def is_num?
  @flags & NUM_FLAG != 0
end

#is_pri_key?Boolean

Return true if primary key field.

Returns:

  • (Boolean)


455
456
457
# File 'lib/mysql.rb', line 455

def is_pri_key?
  @flags & PRI_KEY_FLAG != 0
end