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

Public Member Functions

 Field_timestamp (uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg)
 Field_timestamp (bool maybe_null_arg, const char *field_name_arg)
enum_field_types type () const
enum ha_base_keytype key_type () const
type_conversion_status store_packed (longlong nr)
type_conversion_status reset (void)
longlong val_int (void)
int cmp (const uchar *, const uchar *)
void make_sort_key (uchar *buff, uint length)
uint32 pack_length () const
void sql_type (String &str) const
bool zero_pack () const
bool get_timestamp (struct timeval *tm, int *warnings)
bool get_date (MYSQL_TIME *ltime, uint fuzzydate)
Field_timestampclone (MEM_ROOT *mem_root) const
Field_timestampclone () const
uchar * pack (uchar *to, const uchar *from, uint max_length __attribute__((unused)), bool low_byte_first)
const uchar * unpack (uchar *to, const uchar *from, uint param_data __attribute__((unused)), bool low_byte_first)
virtual type_conversion_status validate_stored_val (THD *thd)
- Public Member Functions inherited from Field_temporal_with_date_and_time
 Field_temporal_with_date_and_time (uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, uint8 dec_arg)
void store_timestamp (const struct timeval *tm)
- Public Member Functions inherited from Field_temporal_with_date
 Field_temporal_with_date (uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, uint8 int_length_arg, uint8 dec_arg)
 Field_temporal_with_date (bool maybe_null_arg, const char *field_name_arg, uint int_length_arg, uint8 dec_arg)
bool send_binary (Protocol *protocol)
type_conversion_status store_time (MYSQL_TIME *ltime, uint8 dec)
Stringval_str (String *, String *)
longlong val_time_temporal ()
longlong val_date_temporal ()
bool get_time (MYSQL_TIME *ltime)
- Public Member Functions inherited from Field_temporal
 Field_temporal (uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, uint32 len_arg, uint8 dec_arg)
 Field_temporal (bool maybe_null_arg, const char *field_name_arg, uint32 len_arg, uint8 dec_arg)
virtual Item_result result_type () const
virtual uint32 max_display_length ()
virtual bool str_needs_quotes ()
virtual uint is_equal (Create_field *new_field)
Item_result numeric_context_result_type () const
enum Item_result cmp_type () const
enum Derivation derivation () const
uint repertoire () const
const CHARSET_INFOcharset () const
bool can_be_compared_as_longlong () const
bool binary () const
type_conversion_status store (const char *str, uint len, const CHARSET_INFO *cs)
type_conversion_status store_decimal (const my_decimal *decimal)
type_conversion_status store (longlong nr, bool unsigned_val)
type_conversion_status store (double nr)
double val_real ()
my_decimalval_decimal (my_decimal *decimal_value)
- Public Member Functions inherited from Field
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.
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)
longlong val_temporal_by_field_type ()
Stringval_str (String *str)
Stringval_int_as_str (String *val_buffer, my_bool unsigned_flag)
virtual Item_result cast_to_int_type () const
virtual bool eq (Field *field)
virtual bool eq_def (Field *field)
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 void reset_fields ()
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 uint32 key_length () const
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_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
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 bool optimize_range (uint idx, uint part)
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)
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 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 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 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)
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 void hash (ulong *nr, ulong *nr2)

Static Public Attributes

static const int PACK_LENGTH = 4

Protected Member Functions

ulonglong date_flags (const THD *thd)
type_conversion_status store_internal (const MYSQL_TIME *ltime, int *error)
bool get_date_internal (MYSQL_TIME *ltime)
void store_timestamp_internal (const struct timeval *tm)
- Protected Member Functions inherited from Field_temporal_with_date_and_time
void init_timestamp_flags ()
bool convert_TIME_to_timestamp (THD *thd, const MYSQL_TIME *ltime, struct timeval *tm, int *error)
- Protected Member Functions inherited from Field_temporal_with_date
bool get_internal_check_zero (MYSQL_TIME *ltime, uint fuzzydate)
type_conversion_status convert_number_to_TIME (longlong nr, bool unsigned_val, int nanoseconds, MYSQL_TIME *ltime, int *warning)
bool convert_str_to_TIME (const char *str, uint len, const CHARSET_INFO *cs, MYSQL_TIME *ltime, MYSQL_TIME_STATUS *status)
type_conversion_status store_internal_with_round (MYSQL_TIME *ltime, int *warnings)
- Protected Member Functions inherited from Field_temporal
uint8 normalize_dec (uint8 dec_arg)
type_conversion_status store_lldiv_t (const lldiv_t *lld, int *warning)
longlong convert_number_to_datetime (longlong nr, bool unsigned_val, MYSQL_TIME *ltime, int *warning)
void set_warnings (ErrConvString str, int warnings)
ulonglong date_flags ()
void set_datetime_warning (Sql_condition::enum_warning_level level, uint code, ErrConvString str, timestamp_type ts_type, int cuted_increment)
- Protected Member Functions inherited from Field
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 ()

Additional Inherited Members

- Public Types inherited from Field
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 }
- Static Public Member Functions inherited from Field
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 inherited from Field
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
- Static Protected Member Functions inherited from Field
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 inherited from Field_temporal
uint8 dec

Detailed Description

Definition at line 2513 of file field.h.

Constructor & Destructor Documentation

Field_timestamp::Field_timestamp ( uchar *  ptr_arg,
uint32  len_arg,
uchar *  null_ptr_arg,
uchar  null_bit_arg,
enum utype  unireg_check_arg,
const char *  field_name_arg 
)

TIMESTAMP type columns hold date and time values in the range 1970-01-01 00:00:01 UTC to 2038-01-01 00:00:00 UTC, stored as number of seconds since the start of the Unix Epoch (1970-01-01 00:00:01 UTC.)

TIMESTAMP columns can be automatically set on row updates to and/or have CURRENT_TIMESTAMP as default value for inserts.

The implementation of function defaults is heavily entangled with the binary .frm file format. The utype enum is part of the file format specification but is declared a member of the Field class. This constructor accepts a unireg_check value to initialize the column default expression.

Five distinct unireg_check values are used for TIMESTAMP columns to distinguish various cases of DEFAULT or ON UPDATE values. These values are:

  • TIMESTAMP_OLD_FIELD - old timestamp, this has no significance when creating a the Field_timestamp.
  • TIMESTAMP_DN_FIELD - means TIMESTAMP DEFAULT CURRENT_TIMESTAMP.
  • TIMESTAMP_UN_FIELD - means TIMESTAMP DEFAULT <default value>=""> ON UPDATE CURRENT_TIMESTAMP, where <default value>=""> is an implicit or explicit expression other than CURRENT_TIMESTAMP or any synonym thereof (e.g. NOW().)
  • TIMESTAMP_DNUN_FIELD - means DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP.
  • NONE - means that the column has neither DEFAULT CURRENT_TIMESTAMP, nor ON UPDATE CURRENT_TIMESTAMP

Note that columns with TIMESTAMP_OLD_FIELD are no longer created explicitly, the value is meant to preserve the ability to read tables from old databases. Such columns are replaced with their newer counterparts by CREATE TABLE and SHOW CREATE TABLE. This is because we want to prefer NONE unireg_check over TIMESTAMP_OLD_FIELD for "TIMESTAMP DEFAULT 'Const'" field. (Old TIMESTAMP columns allowed such definitions as well but ignored the default value for first the TIMESTAMP column. This is, of course, non-standard.) In most cases a user won't notice any change, only exception being different behavior of old/new TIMESTAMPS columns during ALTER TABLE.

Definition at line 5335 of file field.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Function Documentation

Field_timestamp* Field_timestamp::clone ( MEM_ROOT mem_root) const
inlinevirtual

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.

Implements Field.

Definition at line 2542 of file field.h.

Here is the call graph for this function:

Field_timestamp* Field_timestamp::clone ( ) const
inlinevirtual

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.

Implements Field.

Definition at line 2546 of file field.h.

Here is the call graph for this function:

ulonglong Field_timestamp::date_flags ( const THD *  thd)
protectedvirtual

Flags that are passed as "flag" argument to check_date(), number_to_datetime(), str_to_datetime().

Flags depend on the session sql_mode settings, such as MODE_NO_ZERO_DATE, MODE_NO_ZERO_IN_DATE. Also, Field_newdate, Field_datetime, Field_datetimef add TIME_FUZZY_DATE to the session sql_mode settings, to allow relaxed date format, while Field_timestamp, Field_timestampf do not.

Parameters
thdTHD
Return values
sql_modeflags mixed with the field type flags.

Reimplemented from Field_temporal.

Definition at line 5360 of file field.cc.

bool Field_timestamp::get_date_internal ( MYSQL_TIME ltime)
protectedvirtual

Get a value from record, without checking fuzzy date flags.

Return values
true- if timestamp is 0, ltime is not touched in this case.
false- if timestamp is non-zero.

Implements Field_temporal_with_date.

Definition at line 5385 of file field.cc.

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

Get TIMESTAMP field value as seconds since begging of Unix Epoch

Reimplemented from Field.

Definition at line 5406 of file field.cc.

void Field_timestamp::make_sort_key ( uchar *  buff,
uint  length 
)
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.

Implements Field.

Definition at line 5483 of file field.cc.

type_conversion_status Field_timestamp::store_internal ( const MYSQL_TIME ltime,
int *  error 
)
protectedvirtual

Low level routine to store a MYSQL_TIME value into a field. The value must be already properly rounded or truncated and checked for being a valid TIME/DATE/DATETIME value.

Parameters
INltime MYSQL_TIME value.
OUTerror Error flag vector, set in case of error.
Return values
falseIn case of success.
trueIn case of error.

Implements Field_temporal.

Definition at line 5368 of file field.cc.

Here is the call graph for this function:

type_conversion_status Field_timestamp::store_packed ( longlong  nr)
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 from Field.

Definition at line 5438 of file field.cc.

Here is the call graph for this function:

void Field_timestamp::store_timestamp_internal ( const struct timeval tm)
protectedvirtual

Store "struct timeval" value into field. The value must be properly rounded or truncated according to the number of fractional second digits.

Implements Field_temporal_with_date_and_time.

Definition at line 5425 of file field.cc.

Here is the caller graph for this function:

type_conversion_status Field_timestamp::validate_stored_val ( THD *  thd)
virtual

Validate date value stored in the field.

Now we check whether date value is zero or has zero in date or not and set warning/error message appropriately(depending on the sql_mode).

Reimplemented from Field_temporal_with_date.

Definition at line 5510 of file field.cc.

Here is the call graph for this function:


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