Class: Mysql::Field
- Inherits:
-
Object
- Object
- Mysql::Field
- Defined in:
- lib/mysql.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
-
#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
-
#hash ⇒ Hash
Field information.
-
#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.
Constructor Details
#initialize(packet) ⇒ Field
Returns a new instance of Field.
552 553 554 555 556 557 |
# File 'lib/mysql.rb', line 552 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 |
Instance Attribute Details
#charsetnr ⇒ Integer (readonly)
Returns charset id number.
535 536 537 |
# File 'lib/mysql.rb', line 535 def charsetnr @charsetnr end |
#db ⇒ String (readonly)
Returns database name.
525 526 527 |
# File 'lib/mysql.rb', line 525 def db @db end |
#decimals ⇒ Integer (readonly)
Returns number of decimals.
543 544 545 |
# File 'lib/mysql.rb', line 543 def decimals @decimals end |
#default ⇒ String (readonly) Also known as: def
Returns defualt value.
545 546 547 |
# File 'lib/mysql.rb', line 545 def default @default end |
#flags ⇒ Integer (readonly)
Returns flag.
541 542 543 |
# File 'lib/mysql.rb', line 541 def flags @flags end |
#length ⇒ Integer (readonly)
Returns field length.
537 538 539 |
# File 'lib/mysql.rb', line 537 def length @length end |
#max_length ⇒ Integer
Returns maximum width of the field for the result set.
594 595 596 597 598 599 |
# File 'lib/mysql.rb', line 594 def max_length return @max_length if @max_length @max_length = 0 @result.calculate_field_max_length if @result @max_length end |
#name ⇒ String (readonly)
Returns field name.
531 532 533 |
# File 'lib/mysql.rb', line 531 def name @name end |
#org_name ⇒ String (readonly)
Returns original field name.
533 534 535 |
# File 'lib/mysql.rb', line 533 def org_name @org_name end |
#org_table ⇒ String (readonly)
Returns original table name.
529 530 531 |
# File 'lib/mysql.rb', line 529 def org_table @org_table end |
#result ⇒ Object
549 550 551 |
# File 'lib/mysql.rb', line 549 def result @result end |
#table ⇒ String (readonly)
Returns table name.
527 528 529 |
# File 'lib/mysql.rb', line 527 def table @table end |
#type ⇒ Integer (readonly)
Returns field type.
539 540 541 |
# File 'lib/mysql.rb', line 539 def type @type end |
Instance Method Details
#hash ⇒ Hash
Returns field information.
560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'lib/mysql.rb', line 560 def hash { "name" => @name, "table" => @table, "def" => @default, "type" => @type, "length" => @length, "max_length" => max_length, "flags" => @flags, "decimals" => @decimals } end |
#inspect ⇒ Object
574 575 576 |
# File 'lib/mysql.rb', line 574 def inspect "#<Mysql::Field:#{@name}>" end |
#is_not_null? ⇒ Boolean
Returns true if not null field.
584 585 586 |
# File 'lib/mysql.rb', line 584 def is_not_null? @flags & NOT_NULL_FLAG != 0 end |
#is_num? ⇒ Boolean
Returns true if numeric field.
579 580 581 |
# File 'lib/mysql.rb', line 579 def is_num? @flags & NUM_FLAG != 0 end |
#is_pri_key? ⇒ Boolean
Returns true if primary key field.
589 590 591 |
# File 'lib/mysql.rb', line 589 def is_pri_key? @flags & PRI_KEY_FLAG != 0 end |