MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Field Class Reference
Inheritance diagram for Field:
Collaboration diagram for Field:

Public Types

enum  utype {
  NONE, DATE, SHIELD, NOEMPTY,
  CASEUP, PNR, BGNR, PGNR,
  YES, NO, REL, CHECK,
  EMPTY, UNKNOWN_FIELD, CASEDN, NEXT_NUMBER,
  INTERVAL_FIELD, BIT_FIELD, TIMESTAMP_OLD_FIELD, CAPITALIZE,
  BLOB_FIELD, TIMESTAMP_DN_FIELD, TIMESTAMP_UN_FIELD, TIMESTAMP_DNUN_FIELD
}
enum  geometry_type {
  GEOM_GEOMETRY = 0, GEOM_POINT = 1, GEOM_LINESTRING = 2, GEOM_POLYGON = 3,
  GEOM_MULTIPOINT = 4, GEOM_MULTILINESTRING = 5, GEOM_MULTIPOLYGON = 6, GEOM_GEOMETRYCOLLECTION = 7
}
enum  imagetype { itRAW, itMBR }
enum  { LAST_NULL_BYTE_UNDEF = 0 }

Public Member Functions

bool has_insert_default_function () const
bool has_update_default_function () const
 Field (uchar *ptr_arg, uint32 length_arg, uchar *null_ptr_arg, uchar null_bit_arg, utype unireg_check_arg, const char *field_name_arg)
 This is used as a table name when the table structure is not set up.
virtual type_conversion_status store (const char *to, uint length, const CHARSET_INFO *cs)=0
virtual type_conversion_status store (double nr)=0
virtual type_conversion_status store (longlong nr, bool unsigned_val)=0
virtual type_conversion_status store_packed (longlong nr)
virtual type_conversion_status store_decimal (const my_decimal *d)=0
virtual type_conversion_status store_time (MYSQL_TIME *ltime, uint8 dec)
type_conversion_status store_time (MYSQL_TIME *ltime)
type_conversion_status store (const char *to, uint length, const CHARSET_INFO *cs, enum_check_fields check_level)
virtual double val_real (void)=0
virtual longlong val_int (void)=0
virtual longlong val_time_temporal ()
virtual longlong val_date_temporal ()
longlong val_temporal_by_field_type ()
virtual my_decimalval_decimal (my_decimal *)=0
Stringval_str (String *str)
virtual Stringval_str (String *, String *)=0
Stringval_int_as_str (String *val_buffer, my_bool unsigned_flag)
virtual bool str_needs_quotes ()
virtual Item_result result_type () const =0
virtual Item_result numeric_context_result_type () const
virtual Item_result cmp_type () const
virtual Item_result cast_to_int_type () const
virtual bool eq (Field *field)
virtual bool eq_def (Field *field)
virtual uint32 pack_length () const
virtual uint32 pack_length_in_rec () const
virtual bool compatible_field_size (uint metadata, Relay_log_info *rli, uint16 mflags, int *order)
virtual uint pack_length_from_metadata (uint field_metadata)
virtual uint row_pack_length () const
virtual int save_field_metadata (uchar *first_byte)
virtual uint32 data_length ()
virtual uint32 sort_length () const
virtual uint32 max_data_length () const
virtual type_conversion_status reset (void)
virtual void reset_fields ()
virtual bool get_timestamp (struct timeval *tm, int *warnings)
virtual void store_timestamp (const timeval *tm)
void store_timestamp (my_time_t sec)
virtual void set_default ()
void evaluate_insert_default_function ()
void evaluate_update_default_function ()
virtual bool binary () const
virtual bool zero_pack () const
virtual enum ha_base_keytype key_type () const
virtual uint32 key_length () const
virtual enum_field_types type () const =0
virtual enum_field_types real_type () const
virtual enum_field_types binlog_type () const
int cmp (const uchar *str)
virtual int cmp_max (const uchar *a, const uchar *b, uint max_len)
virtual int cmp (const uchar *, const uchar *)=0
virtual int cmp_binary (const uchar *a, const uchar *b, uint32 max_length=~0L)
virtual int cmp_offset (uint row_offset)
virtual int cmp_binary_offset (uint row_offset)
virtual int key_cmp (const uchar *a, const uchar *b)
virtual int key_cmp (const uchar *str, uint length)
virtual uint decimals () const
virtual void sql_type (String &str) const =0
bool is_temporal () const
bool is_temporal_with_date () const
bool is_temporal_with_time () const
bool is_temporal_with_date_and_time () const
bool is_null (my_ptrdiff_t row_offset=0) const
bool is_real_null (my_ptrdiff_t row_offset=0) const
bool is_null_in_record (const uchar *record) const
void set_null (my_ptrdiff_t row_offset=0)
void set_notnull (my_ptrdiff_t row_offset=0)
bool maybe_null (void) const
bool real_maybe_null (void) const
uint null_offset (const uchar *record) const
uint null_offset () const
void set_null_ptr (uchar *p_null_ptr, uint p_null_bit)
size_t last_null_byte () const
virtual void make_field (Send_field *)
virtual void make_sort_key (uchar *buff, uint length)=0
virtual bool optimize_range (uint idx, uint part)
virtual bool can_be_compared_as_longlong () const
virtual void free ()
virtual Fieldnew_field (MEM_ROOT *root, TABLE *new_table, bool keep_type)
virtual Fieldnew_key_field (MEM_ROOT *root, TABLE *new_table, uchar *new_ptr, uchar *new_null_ptr, uint new_null_bit)
Fieldnew_key_field (MEM_ROOT *root, TABLE *new_table, uchar *new_ptr)
virtual Fieldclone () const =0
virtual Fieldclone (MEM_ROOT *mem_root) const =0
void move_field (uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg)
void move_field (uchar *ptr_arg)
virtual void move_field_offset (my_ptrdiff_t ptr_diff)
virtual void get_image (uchar *buff, uint length, const CHARSET_INFO *cs)
virtual void set_image (const uchar *buff, uint length, const CHARSET_INFO *cs)
virtual uint get_key_image (uchar *buff, uint length, imagetype type)
virtual void set_key_image (const uchar *buff, uint length)
longlong val_int_offset (uint row_offset)
longlong val_int (const uchar *new_ptr)
Stringval_str (String *str, const uchar *new_ptr)
virtual bool send_binary (Protocol *protocol)
virtual uchar * pack (uchar *to, const uchar *from, uint max_length, bool low_byte_first)
uchar * pack (uchar *to, const uchar *from)
virtual const uchar * unpack (uchar *to, const uchar *from, uint param_data, bool low_byte_first)
const uchar * unpack (uchar *to, const uchar *from)
virtual uint packed_col_length (const uchar *to, uint length)
virtual uint max_packed_col_length (uint max_length)
uint offset (uchar *record)
void copy_from_tmp (int offset)
uint fill_cache_field (struct st_cache_field *copy)
virtual bool get_date (MYSQL_TIME *ltime, uint fuzzydate)
virtual bool get_time (MYSQL_TIME *ltime)
virtual const CHARSET_INFOcharset (void) const
virtual const CHARSET_INFOcharset_for_protocol (void) const
virtual const CHARSET_INFOsort_charset (void) const
virtual bool has_charset (void) const
virtual bool match_collation_to_optimize_range () const
virtual enum Derivation derivation (void) const
virtual uint repertoire (void) const
virtual void set_derivation (enum Derivation derivation_arg)
bool set_warning (Sql_condition::enum_warning_level, unsigned int code, int cuted_increment) const
bool check_overflow (int op_result)
bool check_truncated (int op_result)
bool warn_if_overflow (int op_result)
void init (TABLE *table_arg)
virtual uint32 max_display_length ()=0
virtual uint is_equal (Create_field *new_field)
longlong convert_decimal2longlong (const my_decimal *val, bool unsigned_flag, bool *has_overflow)
virtual uint32 char_length ()
virtual geometry_type get_geometry_type ()
void dbug_print ()
ha_storage_media field_storage_type () const
void set_storage_type (ha_storage_media storage_type_arg)
column_format_type column_format () const
void set_column_format (column_format_type column_format_arg)
virtual type_conversion_status validate_stored_val (THD *thd)
virtual void hash (ulong *nr, ulong *nr2)

Static Public Member Functions

static void * operator new (size_t size) throw ()
static void * operator new (size_t size, MEM_ROOT *mem_root) throw ()
static void operator delete (void *ptr, MEM_ROOT *mem_root)
static void operator delete (void *ptr_arg, size_t size) throw ()
static bool type_can_have_key_part (enum_field_types)
static enum_field_types field_type_merge (enum_field_types, enum_field_types)
static Item_result result_merge_type (enum_field_types)

Public Attributes

uchar * ptr
TABLEtable
TABLEorig_table
const char ** table_name
const char * field_name
LEX_STRING comment
key_map key_start
key_map part_of_key
key_map part_of_key_not_clustered
key_map part_of_sortkey
utype unireg_check
uint32 field_length
uint32 flags
uint16 field_index
uchar null_bit
bool is_created_from_null_item

Protected Member Functions

uchar * pack_int16 (uchar *to, const uchar *from, bool low_byte_first_to)
const uchar * unpack_int16 (uchar *to, const uchar *from, bool low_byte_first_from)
uchar * pack_int24 (uchar *to, const uchar *from, bool low_byte_first_to)
const uchar * unpack_int24 (uchar *to, const uchar *from, bool low_byte_first_from)
uchar * pack_int32 (uchar *to, const uchar *from, bool low_byte_first_to)
const uchar * unpack_int32 (uchar *to, const uchar *from, bool low_byte_first_from)
uchar * pack_int64 (uchar *to, const uchar *from, bool low_byte_first_to)
const uchar * unpack_int64 (uchar *to, const uchar *from, bool low_byte_first_from)
bool field_flags_are_binary ()

Static Protected Member Functions

static void handle_int16 (uchar *to, const uchar *from, bool low_byte_first_from, bool low_byte_first_to)
static void handle_int24 (uchar *to, const uchar *from, bool low_byte_first_from, bool low_byte_first_to)
static void handle_int32 (uchar *to, const uchar *from, bool low_byte_first_from, bool low_byte_first_to)
static void handle_int64 (uchar *to, const uchar *from, bool low_byte_first_from, bool low_byte_first_to)

Protected Attributes

uchar * null_ptr

Friends

class Copy_field
class Item_avg_field
class Item_std_field
class Item_sum_num
class Item_sum_sum
class Item_sum_str
class Item_sum_count
class Item_sum_avg
class Item_sum_std
class Item_sum_min
class Item_sum_max
class Item_func_group_concat
int cre_myisam (char *name, register TABLE *form, uint options, ulonglong auto_increment_value)

Detailed Description

Definition at line 453 of file field.h.

Member Function Documentation

virtual Field* Field::clone ( ) const
pure virtual

Makes a shallow copy of the Field object.

Note
This member function must be overridden in all concrete subclasses. Several of the Field subclasses are concrete even though they are not leaf classes, so the compiler will not always catch this.
Return values
NULLIf memory allocation failed.

Implemented in Field_bit_as_char, Field_bit, Field_set, Field_enum, Field_blob, Field_varstring, Field_string, Field_datetimef, Field_datetime, Field_timef, Field_time, Field_newdate, Field_year, Field_timestampf, Field_timestamp, Field_null, Field_double, Field_float, Field_long, Field_medium, Field_short, Field_tiny, Field_new_decimal, and Field_decimal.

Here is the caller graph for this function:

virtual Field* Field::clone ( MEM_ROOT mem_root) const
pure virtual

Makes a shallow copy of the Field object.

Note
This member function must be overridden in all concrete subclasses. Several of the Field subclasses are concrete even though they are not leaf classes, so the compiler will not always catch this.
Parameters
mem_rootMEM_ROOT to use for memory allocation.
Return values
NULLIf memory allocation failed.

Implemented in Field_bit_as_char, Field_bit, Field_set, Field_enum, Field_blob, Field_varstring, Field_string, Field_datetimef, Field_datetime, Field_timef, Field_time, Field_newdate, Field_year, Field_timestampf, Field_timestamp, Field_null, Field_double, Field_float, Field_long, Field_medium, Field_short, Field_tiny, Field_new_decimal, and Field_decimal.

bool Field::compatible_field_size ( uint  metadata,
Relay_log_info rli,
uint16  mflags,
int *  order 
)
virtual

Check to see if field size is compatible with destination.

This method is used in row-based replication to verify that the slave's field size is less than or equal to the master's field size. The encoded field metadata (from the master or source) is decoded and compared to the size of this field (the slave or destination).

Note

The comparison is made so that if the source data (from the master) is less than the target data (on the slave), -1 is returned in *order_var. This implies that a conversion is necessary, but that it is lossy and can result in truncation of the value.

If the source data is strictly greater than the target data, 1 is returned in *order_var. This implies that the source type can is contained in the target type and that a conversion is necessary but is non-lossy.

If no conversion is required to fit the source type in the target type, 0 is returned in *order_var.

Parameters
field_metadataEncoded size in field metadata
mflagsFlags from the table map event for the table.
order_varPointer to variable where the order between the source field and this field will be returned.
Returns
true if this field's size is compatible with the master's field size, false otherwise.

Reimplemented in Field_bit, Field_string, and Field_new_decimal.

Definition at line 1446 of file field.cc.

Here is the call graph for this function:

longlong Field::convert_decimal2longlong ( const my_decimal val,
bool  unsigned_flag,
bool *  has_overflow 
)

Conversion from decimal to longlong. Checks overflow and returns correct value (min/max) in case of overflow.

Parameters
valvalue to be converted
unsigned_flagtype of integer to which we convert val
has_overflowtrue if there is overflow
Returns
value converted from val

Definition at line 1634 of file field.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Field::eq_def ( Field field)
virtual
Return values
1if the fields are equally defined
0if the fields are unequally defined

Reimplemented in Field_enum, and Field_num.

Definition at line 8762 of file field.cc.

Here is the caller graph for this function:

void Field::evaluate_insert_default_function ( )

Evaluates the INSERT default function and stores the result in the field. If no such function exists for the column, or the function is not valid for the column's data type, invoking this function has no effect.

Definition at line 1903 of file field.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

void Field::evaluate_update_default_function ( )

Evaluates the UPDATE default function, if one exists, and stores the result in the record buffer. If no such function exists for the column, or the function is not valid for the column's data type, invoking this function has no effect.

Definition at line 1909 of file field.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

enum_field_types Field::field_type_merge ( enum_field_types  a,
enum_field_types  b 
)
static

Return type of which can carry value of both given types in UNION result.

Parameters
atype for merging
btype for merging
Returns
type of field

Definition at line 936 of file field.cc.

Here is the caller graph for this function:

bool Field::get_timestamp ( struct timeval tm,
int *  warnings 
)
virtual

Returns timestamp value in "struct timeval" format. This method is used in "SELECT UNIX_TIMESTAMP(field)" to avoid conversion from timestamp to MYSQL_TIME and back.

Reimplemented in Field_timestampf, and Field_timestamp.

Definition at line 1828 of file field.cc.

Here is the caller graph for this function:

uint Field::is_equal ( Create_field new_field)
virtual

Whether a field being created is compatible with a existing one.

Used by the ALTER TABLE code to evaluate whether the new definition of a table is compatible with the old definition so that it can determine if data needs to be copied over (table data change).

Reimplemented in Field_bit, Field_blob, Field_varstring, Field_temporal, Field_new_decimal, Field_str, and Field_num.

Definition at line 6703 of file field.cc.

virtual void Field::make_sort_key ( uchar *  buff,
uint  length 
)
pure virtual

Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comparison. Integers are always in big-endian regardless of hardware architecture. At most length bytes are written into the buffer.

Parameters
buffThe buffer, assumed to be at least length bytes.
lengthNumber of bytes to write.

Implemented in Field_bit, Field_enum, Field_blob, Field_varstring, Field_string, Field_datetime, Field_timef, Field_time, Field_newdate, Field_timestamp, Field_temporal_with_date_and_timef, Field_null, Field_double, Field_float, Field_long, Field_medium, Field_short, Field_tiny, Field_new_decimal, and Field_decimal.

Here is the caller graph for this function:

virtual uint32 Field::max_data_length ( ) const
inlinevirtual

Get the maximum size of the data in packed format.

Returns
Maximum data length of the field when packed using the Field::pack() function.

Reimplemented in Field_bit, Field_blob, and Field_longstr.

Definition at line 717 of file field.h.

virtual Item_result Field::numeric_context_result_type ( ) const
inlinevirtual

Returns Item_result type of a field when it appears in numeric context such as: SELECT time_column + 1; SELECT SUM(time_column); Examples:

  • a column of type TIME, DATETIME, TIMESTAMP act as INT.
  • a column of type TIME(1), DATETIME(1), TIMESTAMP(1) act as DECIMAL with 1 fractional digits.

Reimplemented in Field_temporal, and Field_str.

Definition at line 665 of file field.h.

Here is the caller graph for this function:

Field::pack ( uchar *  to,
const uchar *  from,
uint  max_length,
bool  low_byte_first 
)
virtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Reimplemented in Field_bit, Field_enum, Field_blob, Field_varstring, Field_string, Field_medium, Field_short, Field_tiny, Field_decimal, and Field_real.

Here is the caller graph for this function:

bool Field::real_maybe_null ( void  ) const
inline
Returns
true if this field is NULL-able, false otherwise.

Definition at line 919 of file field.h.

Here is the caller graph for this function:

CPP_UNNAMED_NS_END Item_result Field::result_merge_type ( enum_field_types  field_type)
static

Detect Item_result by given field type of UNION merge result.

Parameters
field_typegiven field type
Returns
Item_result (type of internal MySQL expression result)

Definition at line 1031 of file field.cc.

Here is the caller graph for this function:

bool Field::set_warning ( Sql_condition::enum_warning_level  level,
unsigned int  code,
int  cut_increment 
) const

Produce warning or note about data saved into field.

Parameters
level- level of message (Note/Warning/Error)
code- error code of message to be produced
cut_increment- whenever we should increase cut fields count
Note
This function won't produce warning and increase cut fields counter if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.

if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes. This allows us to avoid notes in optimisation, like convert_constant_item().

Return values
1if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
0otherwise

Definition at line 10581 of file field.cc.

Here is the caller graph for this function:

virtual type_conversion_status Field::store_packed ( longlong  nr)
inlinevirtual

Store a temporal value in packed longlong format into a field. The packed value is compatible with TIME_to_longlong_time_packed(), TIME_to_longlong_date_packed() or TIME_to_longlong_datetime_packed(). Note, the value must be properly rounded or truncated according according to field->decimals().

Parameters
nrtemporal value in packed longlong format.
Return values
falseon success
trueon error

Reimplemented in Field_datetimef, Field_datetime, Field_timef, Field_time, Field_newdate, Field_timestampf, and Field_timestamp.

Definition at line 563 of file field.h.

Here is the caller graph for this function:

type_conversion_status Field::store_time ( MYSQL_TIME ltime,
uint8  dec_arg 
)
virtual

Store MYSQL_TIME value with the given amount of decimal digits into a field.

Note, the "dec" parameter represents number of digits of the Item that previously created the MYSQL_TIME value. It's needed when we store the value into a CHAR/VARCHAR/TEXT field to display the proper amount of fractional digits. For other field types the "dec" value does not matter and is ignored.

Parameters
ltimeTime, date or datetime value.
decNumber of decimals in ltime.
Return values
falseon success
trueon error

This is called when storing a date in a string.

Note
Needs to be changed if/when we want to support different time formats.

Reimplemented in Field_time_common, Field_year, Field_temporal_with_date, Field_new_decimal, Field_real, and Field_num.

Definition at line 1844 of file field.cc.

Here is the caller graph for this function:

type_conversion_status Field::store_time ( MYSQL_TIME ltime)
inline

Store MYSQL_TYPE value into a field when the number of fractional digits is not important or is not know.

Parameters
ltimeTime, date or datetime value.
Return values
falseon success
trueon error

Definition at line 592 of file field.h.

Here is the call graph for this function:

virtual void Field::store_timestamp ( const timeval tm)
inlinevirtual

Stores a timestamp value in timeval format in a field.

Note
  • The default implementation of this interface expects that storing the value will not fail. For most Field descendent classes, this is not the case. However, this interface is only used when the function CURRENT_TIMESTAMP is used as a column default expression, and currently we only allow TIMESTAMP and DATETIME columns to be declared with this as the column default. Hence it is enough that the classes implementing columns with these types either override this interface, or that store_time(MYSQL_TIME*, uint8) does not fail.
  • The column types above interpret decimals() to mean the scale of the fractional seconds.
  • We also have the limitation that the scale of a column must be the same as the scale of the CURRENT_TIMESTAMP. I.e. we only allow
[ TIMESTAMP | DATETIME ] (n) [ DEFAULT | ON UPDATE ] CURRENT_TIMESTAMP (n)

Since this interface relies on the caller to truncate the value according to this Field's scale, it will work with all constructs that we currently allow.

Reimplemented in Mock_field_timestamp.

Definition at line 764 of file field.h.

Here is the caller graph for this function:

void Field::store_timestamp ( my_time_t  sec)
inline

Interface for legacy code. Newer code uses the store_timestamp(const timeval*) interface.

Parameters
timestampA TIMESTAMP value in the my_time_t format.

Definition at line 772 of file field.h.

Here is the call graph for this function:

bool Field::type_can_have_key_part ( enum_field_types  type)
static

Check whether a field type can be partially indexed by a key.

This is a static method, rather than a virtual function, because we need to check the type of a non-Field in mysql_alter_table().

Parameters
typefield type
Return values
TRUEType can have a prefixed key
FALSEType can not have a prefixed key

Definition at line 1126 of file field.cc.

Field::unpack ( uchar *  to,
const uchar *  from,
uint  param_data,
bool  low_byte_first 
)
virtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Reimplemented in Field_bit, Field_enum, Field_blob, Field_varstring, Field_string, Field_medium, Field_short, Field_tiny, Field_new_decimal, Field_decimal, and Field_real.

Here is the caller graph for this function:

virtual longlong Field::val_date_temporal ( )
inlinevirtual

Returns DATE/DATETIME value in packed longlong format. This method should not be called for non-temporal types. Temporal field types override the default method.

Reimplemented in Field_datetimef, Field_time_common, Field_newdate, and Field_temporal_with_date.

Definition at line 616 of file field.h.

Here is the caller graph for this function:

String * Field::val_int_as_str ( String val_buffer,
my_bool  unsigned_val 
)

Interpret field value as an integer but return the result as a string.

This is used for printing bit_fields as numbers while debugging.

Definition at line 1332 of file field.cc.

longlong Field::val_temporal_by_field_type ( )
inline

Returns "native" packed longlong representation of a TIME or DATE/DATETIME field depending on field type.

Definition at line 625 of file field.h.

Here is the call graph for this function:

virtual longlong Field::val_time_temporal ( )
inlinevirtual

Returns TIME value in packed longlong format. This method should not be called for non-temporal types. Temporal field types override the default method.

Reimplemented in Field_timef, Field_time, Field_newdate, and Field_temporal_with_date.

Definition at line 606 of file field.h.

Here is the caller graph for this function:

bool Field::warn_if_overflow ( int  op_result)

Process decimal library return codes and issue warnings for overflow and truncation.

Parameters
op_resultdecimal library return code (E_DEC_* see include/decimal.h)
Return values
0No error or some other errors except overflow
1There was overflow

Definition at line 1310 of file field.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

bool Field::is_created_from_null_item

If true, this field was created in create_tmp_field_from_item from a NULL value. This means that the type of the field is just a guess, and the type may be freely coerced to another type.

See Also
create_tmp_field_from_item
Item_type_holder::get_real_type

Definition at line 540 of file field.h.

uchar* Field::null_ptr
protected

Byte where the NULL bit is stored inside a record. If this Field is a NOT NULL field, this member is NULL.

Definition at line 490 of file field.h.


The documentation for this class was generated from the following files: