My Project
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends
Field Class Reference
Inheritance diagram for Field:
Field_bit Field_num Field_str Field_temporal Field_bit_as_char Field_long Field_medium Field_new_decimal Field_real Field_short Field_tiny Field_enum Field_longstr Field_null Field_temporal_with_date Field_time_common

List of all members.

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_INFO * charset (void) const
virtual const CHARSET_INFO * charset_for_protocol (void) const
virtual const CHARSET_INFO * sort_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)

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)

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.

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.

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
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.

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.

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.

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
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.

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.

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.

virtual uint32 Field::max_data_length ( ) const [inline, virtual]

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.

virtual Item_result Field::numeric_context_result_type ( ) const [inline, virtual]

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.

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.

bool Field::real_maybe_null ( void  ) const [inline]
Returns:
true if this field is NULL-able, false otherwise.
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)
bool Field::set_warning ( Sql_condition::enum_warning_level  ,
unsigned int  code,
int  cuted_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
virtual type_conversion_status Field::store_packed ( longlong  nr) [inline, virtual]

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.

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.

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
virtual void Field::store_timestamp ( const timeval *  tm) [inline, virtual]

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.

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.
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
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.

virtual longlong Field::val_date_temporal ( ) [inline, virtual]

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.

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.

longlong Field::val_temporal_by_field_type ( ) [inline]

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

virtual longlong Field::val_time_temporal ( ) [inline, virtual]

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.

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

Member Data Documentation

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
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.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines