My Project
Public Member Functions | Static Public Attributes | Protected Member Functions
Field_timestamp Class Reference
Inheritance diagram for Field_timestamp:
Field_temporal_with_date_and_time Field_temporal_with_date Field_temporal Field

List of all members.

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)

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)

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.


Member Function Documentation

Field_timestamp* Field_timestamp::clone ( MEM_ROOT *  mem_root) const [inline, 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.

Implements Field.

Field_timestamp* Field_timestamp::clone ( ) const [inline, 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.

Implements Field.

ulonglong Field_timestamp::date_flags ( const THD *  thd) [protected, virtual]

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.

bool Field_timestamp::get_date_internal ( MYSQL_TIME *  ltime) [protected, virtual]

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.

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.

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.

type_conversion_status Field_timestamp::store_internal ( const MYSQL_TIME *  ltime,
int *  error 
) [protected, virtual]

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.

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.

void Field_timestamp::store_timestamp_internal ( const struct timeval *  tm) [protected, virtual]

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.

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.


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