Class: Mysql::Field
- Inherits:
-
Object
- Object
- Mysql::Field
- 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
-
#charsetnr ⇒ Integer
readonly
Charset id number.
-
#db ⇒ String
readonly
Database name.
-
#decimals ⇒ Integer
readonly
Number of decimals.
-
#default ⇒ String
(also: #def)
readonly
Defualt value.
-
#flags ⇒ Integer
readonly
Flag.
-
#length ⇒ Integer
readonly
Field length.
-
#max_length ⇒ Integer
Maximum width of the field for the result set.
-
#name ⇒ String
readonly
Field name.
-
#org_name ⇒ String
readonly
Original field name.
-
#org_table ⇒ String
readonly
Original table name.
- #result ⇒ Object
-
#table ⇒ String
readonly
Table name.
-
#type ⇒ Integer
readonly
Field type.
Instance Method Summary collapse
-
#initialize(packet) ⇒ Field
constructor
A new instance of Field.
- #inspect ⇒ Object
-
#is_not_null? ⇒ Boolean
True if not null field.
-
#is_num? ⇒ Boolean
True if numeric field.
-
#is_pri_key? ⇒ Boolean
True if primary key field.
-
#to_hash ⇒ Hash
Field information.
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
#charsetnr ⇒ Integer (readonly)
Returns charset id number.
16 17 18 |
# File 'lib/mysql/field.rb', line 16 def charsetnr @charsetnr end |
#db ⇒ String (readonly)
Returns database name.
6 7 8 |
# File 'lib/mysql/field.rb', line 6 def db @db end |
#decimals ⇒ Integer (readonly)
Returns number of decimals.
24 25 26 |
# File 'lib/mysql/field.rb', line 24 def decimals @decimals end |
#default ⇒ String (readonly) Also known as: def
Returns defualt value.
26 27 28 |
# File 'lib/mysql/field.rb', line 26 def default @default end |
#flags ⇒ Integer (readonly)
Returns flag.
22 23 24 |
# File 'lib/mysql/field.rb', line 22 def flags @flags end |
#length ⇒ Integer (readonly)
Returns field length.
18 19 20 |
# File 'lib/mysql/field.rb', line 18 def length @length end |
#max_length ⇒ Integer
Returns 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 |
#name ⇒ String (readonly)
Returns field name.
12 13 14 |
# File 'lib/mysql/field.rb', line 12 def name @name end |
#org_name ⇒ String (readonly)
Returns original field name.
14 15 16 |
# File 'lib/mysql/field.rb', line 14 def org_name @org_name end |
#org_table ⇒ String (readonly)
Returns original table name.
10 11 12 |
# File 'lib/mysql/field.rb', line 10 def org_table @org_table end |
#result ⇒ Object
30 31 32 |
# File 'lib/mysql/field.rb', line 30 def result @result end |
#table ⇒ String (readonly)
Returns table name.
8 9 10 |
# File 'lib/mysql/field.rb', line 8 def table @table end |
#type ⇒ Integer (readonly)
Returns field type.
20 21 22 |
# File 'lib/mysql/field.rb', line 20 def type @type end |
Instance Method Details
#inspect ⇒ Object
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.
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.
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.
75 76 77 |
# File 'lib/mysql/field.rb', line 75 def is_pri_key? @flags & PRI_KEY_FLAG != 0 end |
#to_hash ⇒ Hash
Returns 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 |