Class: Mysql::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-mysql/field.rb,
lib/ffi-mysql/constants.rb

Overview

Information about one column.

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(c_field) ⇒ Field

Returns a new instance of Field.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ffi-mysql/field.rb', line 25

def initialize(c_field)
    @name =             c_field[:name]
    @org_name =         c_field[:org_name]
    @table =            c_field[:table]
    @org_table =        c_field[:org_table]
    @db =               c_field[:db]
    @catalog =          c_field[:catalog]
    @def =              c_field[:def]
    @length =           c_field[:length]
    @max_length =       c_field[:max_length]
    @name_length =      c_field[:name_length]
    @org_name_length =  c_field[:org_name_length]
    @table_length =     c_field[:table_length]
    @org_table_length = c_field[:org_table_length]
    @db_length =        c_field[:db_length]
    @catalog_length =   c_field[:catalog_length]
    @def_length =       c_field[:def_length]
    @flags =            c_field[:flags]
    @decimals =         c_field[:decimals]
    @charsetnr =        c_field[:charsetnr]
    # @type =             C::FieldType[c_field[:type]]
    @type =             c_field[:type]
    @flags |= NUM_FLAG if is_num_type?
end

Instance Attribute Details

#catalogObject (readonly)

Returns the value of attribute catalog.



9
10
11
# File 'lib/ffi-mysql/field.rb', line 9

def catalog
  @catalog
end

#catalog_lengthObject (readonly)

Returns the value of attribute catalog_length.



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

def catalog_length
  @catalog_length
end

#charsetnrObject (readonly)

Returns the value of attribute charsetnr.



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

def charsetnr
  @charsetnr
end

#dbObject (readonly)

Returns the value of attribute db.



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

def db
  @db
end

#db_lengthObject (readonly)

Returns the value of attribute db_length.



17
18
19
# File 'lib/ffi-mysql/field.rb', line 17

def db_length
  @db_length
end

#decimalsObject (readonly)

Returns the value of attribute decimals.



21
22
23
# File 'lib/ffi-mysql/field.rb', line 21

def decimals
  @decimals
end

#defObject (readonly)

Returns the value of attribute def.



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

def def
  @def
end

#def_lengthObject (readonly)

Returns the value of attribute def_length.



19
20
21
# File 'lib/ffi-mysql/field.rb', line 19

def def_length
  @def_length
end

#flagsObject (readonly)

Returns the value of attribute flags.



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

def flags
  @flags
end

#lengthObject (readonly)

Returns the value of attribute length.



11
12
13
# File 'lib/ffi-mysql/field.rb', line 11

def length
  @length
end

#max_lengthObject (readonly)

Returns the value of attribute max_length.



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

def max_length
  @max_length
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/ffi-mysql/field.rb', line 4

def name
  @name
end

#name_lengthObject (readonly)

Returns the value of attribute name_length.



13
14
15
# File 'lib/ffi-mysql/field.rb', line 13

def name_length
  @name_length
end

#org_nameObject (readonly)

Returns the value of attribute org_name.



5
6
7
# File 'lib/ffi-mysql/field.rb', line 5

def org_name
  @org_name
end

#org_name_lengthObject (readonly)

Returns the value of attribute org_name_length.



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

def org_name_length
  @org_name_length
end

#org_tableObject (readonly)

Returns the value of attribute org_table.



7
8
9
# File 'lib/ffi-mysql/field.rb', line 7

def org_table
  @org_table
end

#org_table_lengthObject (readonly)

Returns the value of attribute org_table_length.



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

def org_table_length
  @org_table_length
end

#tableObject (readonly)

Returns the value of attribute table.



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

def table
  @table
end

#table_lengthObject (readonly)

Returns the value of attribute table_length.



15
16
17
# File 'lib/ffi-mysql/field.rb', line 15

def table_length
  @table_length
end

#typeObject (readonly)

Returns the value of attribute type.



23
24
25
# File 'lib/ffi-mysql/field.rb', line 23

def type
  @type
end

Instance Method Details

#hashHash

Returns this field as a hash.

Returns:

  • (Hash)

    this field as a hash



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ffi-mysql/field.rb', line 66

def hash
    h = {}
    h['name'] = @name
    h['table'] = @table
    h['def'] = @def
    h['length'] = @length
    h['max_length'] = @max_length
    h['flags'] = @flags
    h['decimals'] = @decimals
    h['type'] = @type
    h
end

#inspectObject



79
80
81
# File 'lib/ffi-mysql/field.rb', line 79

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

#is_not_null?Boolean

Returns true if this field is not null.

Returns:

  • (Boolean)

    true if this field is not null



51
52
53
# File 'lib/ffi-mysql/field.rb', line 51

def is_not_null?
    @flags & NOT_NULL_FLAG != 0
end

#is_num?Boolean

Returns true if this is a numeric field.

Returns:

  • (Boolean)

    true if this is a numeric field



56
57
58
# File 'lib/ffi-mysql/field.rb', line 56

def is_num?
    @flags & NUM_FLAG != 0
end

#is_pri_key?Boolean

Returns true if this field is a primary key.

Returns:

  • (Boolean)

    true if this field is a primary key



61
62
63
# File 'lib/ffi-mysql/field.rb', line 61

def is_pri_key?
    @flags & PRI_KEY_FLAG != 0
end