Class: Mysql::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql/field.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_TIMESTAMP2 =
17
TYPE_DATETIME2 =
18
TYPE_TIME2 =
19
TYPE_TYPED_ARRAY =
20
TYPE_INVALID =
243
TYPE_BOOL =
244
TYPE_JSON =
245
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
NO_DEFAULT_VALUE_FLAG =
4096
ON_UPDATE_NOW_FLAG =
8192
NUM_FLAG =
32768
PART_KEY_FLAG =
16384
GROUP_FLAG =
32768
UNIQUE_FLAG =
65536
BINCMP_FLAG =
131072
GET_FIXED_FIELDS_FLAG =
1 << 18
FIELD_IN_PART_FUNC_FLAG =
1 << 19
FIELD_IN_ADD_INDEX =
1 << 20
FIELD_IS_RENAMED =
1 << 21
FIELD_FLAGS_STORAGE_MEDIA_MASK =
3 << 22
FIELD_FLAGS_COLUMN_FORMAT_MASK =
3 << 24
FIELD_IS_DROPPED =
1 << 26
EXPLICIT_NULL_FLAG =
1 << 27
FIELD_IS_MARKED =
1 << 28
NOT_SECONDARY_FLAG =
1 << 29

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(packet) ⇒ Field

Returns a new instance of Field.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mysql/field.rb', line 33

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
  @db.force_encoding('utf-8')
  @table.force_encoding('utf-8')
  @org_table.force_encoding('utf-8')
  @name.force_encoding('utf-8')
  @org_name.force_encoding('utf-8')
  @flags |= NUM_FLAG if is_num_type?
  @max_length = nil
end

Instance Attribute Details

#charsetnrInteger (readonly)

Returns charset id number.

Returns:

  • (Integer)

    charset id number



16
17
18
# File 'lib/mysql/field.rb', line 16

def charsetnr
  @charsetnr
end

#dbString (readonly)

Returns database name.

Returns:

  • (String)

    database name



6
7
8
# File 'lib/mysql/field.rb', line 6

def db
  @db
end

#decimalsInteger (readonly)

Returns number of decimals.

Returns:

  • (Integer)

    number of decimals



24
25
26
# File 'lib/mysql/field.rb', line 24

def decimals
  @decimals
end

#defaultString (readonly) Also known as: def

Returns defualt value.

Returns:

  • (String)

    defualt value



26
27
28
# File 'lib/mysql/field.rb', line 26

def default
  @default
end

#flagsInteger (readonly)

Returns flag.

Returns:

  • (Integer)

    flag



22
23
24
# File 'lib/mysql/field.rb', line 22

def flags
  @flags
end

#lengthInteger (readonly)

Returns field length.

Returns:

  • (Integer)

    field length



18
19
20
# File 'lib/mysql/field.rb', line 18

def length
  @length
end

#max_lengthInteger

Returns maximum width of the field for the result set.

Returns:

  • (Integer)

    maximum width of the field for the result set



80
81
82
83
84
85
# File 'lib/mysql/field.rb', line 80

def max_length
  return @max_length if @max_length
  @max_length = 0
  @result&.calculate_field_max_length
  @max_length
end

#nameString (readonly)

Returns field name.

Returns:

  • (String)

    field name



12
13
14
# File 'lib/mysql/field.rb', line 12

def name
  @name
end

#org_nameString (readonly)

Returns original field name.

Returns:

  • (String)

    original field name



14
15
16
# File 'lib/mysql/field.rb', line 14

def org_name
  @org_name
end

#org_tableString (readonly)

Returns original table name.

Returns:

  • (String)

    original table name



10
11
12
# File 'lib/mysql/field.rb', line 10

def org_table
  @org_table
end

#resultObject



30
31
32
# File 'lib/mysql/field.rb', line 30

def result
  @result
end

#tableString (readonly)

Returns table name.

Returns:

  • (String)

    table name



8
9
10
# File 'lib/mysql/field.rb', line 8

def table
  @table
end

#typeInteger (readonly)

Returns field type.

Returns:

  • (Integer)

    field type



20
21
22
# File 'lib/mysql/field.rb', line 20

def type
  @type
end

Instance Method Details

#inspectObject



60
61
62
# File 'lib/mysql/field.rb', line 60

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

#is_not_null?Boolean

Returns true if not null field.

Returns:

  • (Boolean)

    true if not null field.



70
71
72
# File 'lib/mysql/field.rb', line 70

def is_not_null?
  @flags & NOT_NULL_FLAG != 0
end

#is_num?Boolean

Returns true if numeric field.

Returns:

  • (Boolean)

    true if numeric field.



65
66
67
# File 'lib/mysql/field.rb', line 65

def is_num?
  @flags & NUM_FLAG != 0
end

#is_pri_key?Boolean

Returns true if primary key field.

Returns:

  • (Boolean)

    true if primary key field.



75
76
77
# File 'lib/mysql/field.rb', line 75

def is_pri_key?
  @flags & PRI_KEY_FLAG != 0
end

#to_hashHash

Returns field information.

Returns:

  • (Hash)

    field information



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mysql/field.rb', line 46

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