MySQL 9.1.0
Source Code Documentation
|
Files | |
file | sql_time.cc |
Implementation of server functions to handle date and time. | |
file | sql_time.h |
Interface for server time utilities. | |
Functions | |
my_time_flags_t | DatetimeConversionFlags (const THD *thd) |
Generate flags to use when converting a string to a date or datetime value. More... | |
static uint | to_ascii (const CHARSET_INFO *cs, const char *src, size_t src_length, char *dst, size_t dst_length) |
Convert a string to 8-bit representation, for use in str_to_time/str_to_date/str_to_date. More... | |
bool | str_to_time (const CHARSET_INFO *cs, const char *str, size_t length, MYSQL_TIME *l_time, my_time_flags_t flags, MYSQL_TIME_STATUS *status) |
Character set-aware version of str_to_time(). More... | |
bool | str_to_datetime (const CHARSET_INFO *cs, const char *str, size_t length, MYSQL_TIME *l_time, my_time_flags_t flags, MYSQL_TIME_STATUS *status) |
Character set-aware version of str_to_datetime(). More... | |
bool | str_to_datetime_with_warn (String *str, MYSQL_TIME *l_time, my_time_flags_t flags) |
Convert a timestamp string to a MYSQL_TIME value and produce a warning if string was truncated during conversion. More... | |
static bool | lldiv_t_to_datetime (lldiv_t lld, MYSQL_TIME *ltime, my_time_flags_t flags, int *warnings) |
Convert lldiv_t to datetime. More... | |
bool | decimal_to_datetime (const my_decimal *decimal, MYSQL_TIME *ltime, my_time_flags_t flags) |
Convert decimal value to datetime. More... | |
bool | my_decimal_to_datetime_with_warn (const my_decimal *decimal, MYSQL_TIME *ltime, my_time_flags_t flags) |
Convert decimal value to datetime value with a warning. More... | |
bool | double_to_datetime (double nr, MYSQL_TIME *ltime, my_time_flags_t flags) |
Convert double value to datetime. More... | |
bool | my_double_to_datetime_with_warn (double nr, MYSQL_TIME *ltime, my_time_flags_t flags) |
Convert double value to datetime value with a warning. More... | |
bool | my_longlong_to_datetime_with_warn (longlong nr, MYSQL_TIME *ltime, my_time_flags_t flags) |
Convert longlong value to datetime value with a warning. More... | |
static bool | lldiv_t_to_time (lldiv_t lld, MYSQL_TIME *ltime, int *warnings) |
Convert lldiv_t value to time with nanosecond rounding. More... | |
bool | decimal_to_time (const my_decimal *decimal, MYSQL_TIME *ltime) |
Convert decimal number to TIME. More... | |
bool | my_decimal_to_time_with_warn (const my_decimal *decimal, MYSQL_TIME *ltime) |
Convert decimal number to TIME. More... | |
bool | double_to_time (double nr, MYSQL_TIME *ltime) |
Convert double number to TIME. More... | |
bool | my_double_to_time_with_warn (double nr, MYSQL_TIME *ltime) |
Convert double number to TIME. More... | |
bool | my_longlong_to_time_with_warn (longlong nr, MYSQL_TIME *ltime) |
Convert longlong number to TIME. More... | |
bool | datetime_with_no_zero_in_date_to_timeval (const MYSQL_TIME *ltime, const Time_zone &tz, my_timeval *tm, int *warnings) |
Converts a datetime in MYSQL_TIME representation to corresponding struct timeval value. More... | |
bool | datetime_to_timeval (const MYSQL_TIME *ltime, const Time_zone &tz, my_timeval *tm, int *warnings) |
Convert a datetime MYSQL_TIME representation to corresponding "struct timeval" value. More... | |
bool | str_to_time_with_warn (String *str, MYSQL_TIME *l_time) |
Convert a time string to a MYSQL_TIME struct and produce a warning if string was cut during conversion. More... | |
void | time_to_datetime (THD *thd, const MYSQL_TIME *ltime, MYSQL_TIME *ltime2) |
Convert time to datetime. More... | |
const char * | get_date_time_format_str (const Known_date_time_format *format, enum_mysql_timestamp_type type) |
Return format string according format name. More... | |
void | make_time (const Date_time_format *format, const MYSQL_TIME *l_time, String *str, uint dec) |
Convert TIME value to String. More... | |
void | make_date (const Date_time_format *format, const MYSQL_TIME *l_time, String *str) |
Convert DATE value to String. More... | |
void | make_datetime (const Date_time_format *format, const MYSQL_TIME *l_time, String *str, uint dec) |
Convert DATETIME value to String. More... | |
bool | my_TIME_to_str (const MYSQL_TIME *ltime, String *str, uint dec) |
Convert TIME/DATE/DATETIME value to String. More... | |
bool | make_truncated_value_warning (THD *thd, Sql_condition::enum_severity_level level, const ErrConvString &val, enum_mysql_timestamp_type time_type, const char *field_name) |
Create and add a truncated value warning to the THD. More... | |
bool | date_add_interval_with_warn (THD *thd, MYSQL_TIME *ltime, interval_type int_type, Interval interval) |
Uses propagate_datetime_overflow() to handle and propagate any warnings from date_add_interval() to the THD. More... | |
void | propagate_datetime_overflow_helper (THD *thd, int *warnings) |
Propagates a DATETIME_OVERFLOW warning from warnings bitfield to DA in thd. More... | |
my_decimal * | my_decimal_from_datetime_packed (my_decimal *dec, enum enum_field_types type, longlong packed_value) |
Unpack packed numeric temporal value to date/time value and then convert to decimal representation. More... | |
ulonglong | gmt_time_to_local_time (ulonglong gmt_time) |
This function gets GMT time and adds value of time_zone to get the local time. More... | |
MYSQL_TIME | my_time_set (uint y, uint m, uint d, uint h, uint mi, uint s, unsigned long ms, bool negative, enum_mysql_timestamp_type type) |
In lieu of a proper constructor for the C struct MYSQL_TIME, this method initializes the struct. More... | |
uint | actual_decimals (const MYSQL_TIME *ts) |
Return the number of significant second fraction decimals in ts, e.g. More... | |
size_t | max_fraction (uint decimals) |
For a time fraction with a given number of decimals, return maximum fraction, if any, can be are present in a time value. More... | |
Variables | |
const LEX_CSTRING | interval_type_to_name [INTERVAL_LAST] |
Name description of interval names used in statements. More... | |
my_time_t | TIME_to_timestamp (const MYSQL_TIME *t, const Time_zone &tz, bool *not_exist) |
void | time_to_datetime (THD *thd, const MYSQL_TIME *tm, const Time_zone &tz, MYSQL_TIME *dt) |
template<class T > | |
T | propagate_datetime_overflow (THD *thd, int *warnings, T t) |
Wrapper function which will propagate any DATETIME_OVERFLOW warnings to the THD. More... | |
template<class CLOS > | |
auto | propagate_datetime_overflow (THD *thd, CLOS &&clos) |
Wrapper function which will propagate any DATETIME_OVERFLOW warnings to the THD. More... | |
bool | str_to_time (const String *str, MYSQL_TIME *ltime, my_time_flags_t flags, MYSQL_TIME_STATUS *status) |
Converts a time String value to MYSQL_TIME. More... | |
bool | str_to_datetime (const String *str, MYSQL_TIME *ltime, my_time_flags_t flags, MYSQL_TIME_STATUS *status) |
Converts a datetime String value to MYSQL_TIME. More... | |
enum_mysql_timestamp_type | field_type_to_timestamp_type (enum enum_field_types type) |
Return the timstamp value corresponding the field type passed as argument. More... | |
uint actual_decimals | ( | const MYSQL_TIME * | ts | ) |
Return the number of significant second fraction decimals in ts, e.g.
for ts->second_part == 120300, return 4.
ts | the time value for which we want the number of decmals |
bool date_add_interval_with_warn | ( | THD * | thd, |
MYSQL_TIME * | ltime, | ||
interval_type | int_type, | ||
Interval | interval | ||
) |
Uses propagate_datetime_overflow() to handle and propagate any warnings from date_add_interval() to the THD.
bool datetime_to_timeval | ( | const MYSQL_TIME * | ltime, |
const Time_zone & | tz, | ||
my_timeval * | tm, | ||
int * | warnings | ||
) |
Convert a datetime MYSQL_TIME representation to corresponding "struct timeval" value.
Things like '0000-01-01', '2000-00-01', '2000-01-00' (i.e. incomplete date) return error.
Things like '0000-00-00 10:30:30' or '0000-00-00 00:00:00.123456' (i.e. empty date with non-empty time) return error.
Zero datetime '0000-00-00 00:00:00.000000' is allowed and is mapper to {tv_sec=0, tv_usec=0}.
Note: In case of error, tm value is not initialized.
Note: "warnings" is not initialized to zero, so new warnings are added to the old ones. Caller must make sure to initialize "warnings".
[in] | ltime | datetime value |
[in] | tz | The time zone. |
[out] | tm | timeval value |
[out] | warnings | pointer to warnings vector |
bool datetime_with_no_zero_in_date_to_timeval | ( | const MYSQL_TIME * | ltime, |
const Time_zone & | tz, | ||
my_timeval * | tm, | ||
int * | warnings | ||
) |
Converts a datetime in MYSQL_TIME representation to corresponding struct timeval
value.
ltime
must be previously checked for TIME_NO_ZERO_IN_DATE
. Things like '0000-01-01', '2000-00-01', '2000-01-00' are not allowed and asserted.
Things like '0000-00-00 10:30:30' or '0000-00-00 00:00:00.123456' (i.e. empty date with non-empty time) return error.
Zero datetime '0000-00-00 00:00:00.000000' is allowed and is mapped to {tv_sec=0, tv_usec=0}.
warnings
is not initialized to zero, so new warnings are added to the old ones. The caller must make sure to initialize warnings
.[in] | ltime | Datetime value |
[in] | tz | Time zone to convert to. |
[out] | tm | Timeval value |
[out] | warnings | Pointer to warnings. |
my_time_flags_t DatetimeConversionFlags | ( | const THD * | thd | ) |
Generate flags to use when converting a string to a date or datetime value.
thd | Thread handle |
bool decimal_to_datetime | ( | const my_decimal * | decimal, |
MYSQL_TIME * | ltime, | ||
my_time_flags_t | flags | ||
) |
Convert decimal value to datetime.
decimal | The value to convert from. | |
[out] | ltime | The variable to convert to. |
flags | Conversion flags. |
bool decimal_to_time | ( | const my_decimal * | decimal, |
MYSQL_TIME * | ltime | ||
) |
Convert decimal number to TIME.
decimal | The number to convert from. | |
[out] | ltime | The variable to convert to. |
bool double_to_datetime | ( | double | nr, |
MYSQL_TIME * | ltime, | ||
my_time_flags_t | flags | ||
) |
Convert double value to datetime.
nr | The value to convert from. | |
[out] | ltime | The variable to convert to. |
flags | Conversion flags. |
bool double_to_time | ( | double | nr, |
MYSQL_TIME * | ltime | ||
) |
Convert double number to TIME.
nr | The number to convert from. | |
[out] | ltime | The variable to convert to. |
|
inline |
Return the timstamp value corresponding the field type passed as argument.
type | field type |
const char * get_date_time_format_str | ( | const Known_date_time_format * | format, |
enum_mysql_timestamp_type | type | ||
) |
Return format string according format name.
If name is unknown, result is NULL
NULL | if name is unknown. |
This function gets GMT time and adds value of time_zone to get the local time.
This function is used when server wants a timestamp value from dictionary system.
gmt_time | GMT time value. |
|
static |
Convert lldiv_t to datetime.
lld | The value to convert from. | |
[out] | ltime | The variable to convert to. |
flags | Conversion flags. | |
[in,out] | warnings | Warning flags. |
|
static |
Convert lldiv_t value to time with nanosecond rounding.
lld | The value to convert from. | |
[out] | ltime | The variable to convert to, |
[in,out] | warnings | Warning flags. |
void make_date | ( | const Date_time_format * | format, |
const MYSQL_TIME * | l_time, | ||
String * | str | ||
) |
Convert DATE value to String.
format | Format (unused, see comments above) | |
l_time | DATE value | |
[out] | str | String to convert to |
void make_datetime | ( | const Date_time_format * | format, |
const MYSQL_TIME * | l_time, | ||
String * | str, | ||
uint | dec | ||
) |
Convert DATETIME value to String.
format | Format (unused, see comments above) | |
l_time | DATE value | |
[out] | str | String to convert to |
dec | Number of fractional digits. |
void make_time | ( | const Date_time_format * | format, |
const MYSQL_TIME * | l_time, | ||
String * | str, | ||
uint | dec | ||
) |
Convert TIME value to String.
format | Format (unused, see comments above) | |
l_time | TIME value | |
[out] | str | String to convert to |
dec | Number of fractional digits. |
bool make_truncated_value_warning | ( | THD * | thd, |
Sql_condition::enum_severity_level | level, | ||
const ErrConvString & | val, | ||
enum_mysql_timestamp_type | time_type, | ||
const char * | field_name | ||
) |
Create and add a truncated value warning to the THD.
size_t max_fraction | ( | uint | decimals | ) |
For a time fraction with a given number of decimals, return maximum fraction, if any, can be are present in a time value.
For example, if 2 decimals are specified, return 990000. If none, 0.
decimals | the number of decimals |
my_decimal * my_decimal_from_datetime_packed | ( | my_decimal * | dec, |
enum enum_field_types | type, | ||
longlong | packed_value | ||
) |
Unpack packed numeric temporal value to date/time value and then convert to decimal representation.
[out] | dec | The variable to write to. |
type | MySQL field type. | |
packed_value | Packed numeric temporal representation. |
bool my_decimal_to_datetime_with_warn | ( | const my_decimal * | decimal, |
MYSQL_TIME * | ltime, | ||
my_time_flags_t | flags | ||
) |
Convert decimal value to datetime value with a warning.
decimal | The value to convert from. | |
[out] | ltime | The variable to convert to. |
flags | Conversion flags. |
bool my_decimal_to_time_with_warn | ( | const my_decimal * | decimal, |
MYSQL_TIME * | ltime | ||
) |
Convert decimal number to TIME.
decimal | The number to convert from. | |
[out] | ltime | The variable to convert to. |
bool my_double_to_datetime_with_warn | ( | double | nr, |
MYSQL_TIME * | ltime, | ||
my_time_flags_t | flags | ||
) |
Convert double value to datetime value with a warning.
nr | The value to convert from. | |
[out] | ltime | The variable to convert to. |
flags | Conversion flags. |
bool my_double_to_time_with_warn | ( | double | nr, |
MYSQL_TIME * | ltime | ||
) |
Convert double number to TIME.
nr | The number to convert from. | |
[out] | ltime | The variable to convert to. |
bool my_longlong_to_datetime_with_warn | ( | longlong | nr, |
MYSQL_TIME * | ltime, | ||
my_time_flags_t | flags | ||
) |
Convert longlong value to datetime value with a warning.
nr | The value to convert from. | |
[out] | ltime | The variable to convert to. |
flags | Conversion flags |
bool my_longlong_to_time_with_warn | ( | longlong | nr, |
MYSQL_TIME * | ltime | ||
) |
Convert longlong number to TIME.
nr | The number to convert from. | |
[out] | ltime | The variable to convert to. |
MYSQL_TIME my_time_set | ( | uint | y, |
uint | m, | ||
uint | d, | ||
uint | h, | ||
uint | mi, | ||
uint | s, | ||
unsigned long | ms, | ||
bool | negative, | ||
enum_mysql_timestamp_type | type | ||
) |
In lieu of a proper constructor for the C struct MYSQL_TIME, this method initializes the struct.
bool my_TIME_to_str | ( | const MYSQL_TIME * | ltime, |
String * | str, | ||
uint | dec | ||
) |
Convert TIME/DATE/DATETIME value to String.
ltime | DATE value | |
[out] | str | String to convert to |
dec | Number of fractional digits. |
|
inline |
Wrapper function which will propagate any DATETIME_OVERFLOW warnings to the THD.
Overload for the case when a warnings bitset must be created and inspected to call a mysys function. The mysys function must be invoked by the closure argument which invoked with a pointer to the warnings bitset as argument.
thd | Thread context |
clos | closure to call with empty warnings bitset |
|
inline |
Wrapper function which will propagate any DATETIME_OVERFLOW warnings to the THD.
Overload for the case where a warnings bitset already exists which can be inspected before the value of the mysys function is passed on.
thd | Thread context |
warnings | bitset used mysys function |
t | value mysys function which is passed on |
void propagate_datetime_overflow_helper | ( | THD * | thd, |
int * | warnings | ||
) |
Propagates a DATETIME_OVERFLOW warning from warnings bitfield to DA in thd.
thd | thread context | |
[in,out] | warnings | bitfield of warnings set |
bool str_to_datetime | ( | const CHARSET_INFO * | cs, |
const char * | str, | ||
size_t | length, | ||
MYSQL_TIME * | l_time, | ||
my_time_flags_t | flags, | ||
MYSQL_TIME_STATUS * | status | ||
) |
Character set-aware version of str_to_datetime().
|
inline |
Converts a datetime String value to MYSQL_TIME.
Forwards to the version taking an explicit charset, c-string and length.
bool str_to_datetime_with_warn | ( | String * | str, |
MYSQL_TIME * | l_time, | ||
my_time_flags_t | flags | ||
) |
Convert a timestamp string to a MYSQL_TIME value and produce a warning if string was truncated during conversion.
bool str_to_time | ( | const CHARSET_INFO * | cs, |
const char * | str, | ||
size_t | length, | ||
MYSQL_TIME * | l_time, | ||
my_time_flags_t | flags, | ||
MYSQL_TIME_STATUS * | status | ||
) |
Character set-aware version of str_to_time().
|
inline |
Converts a time String value to MYSQL_TIME.
Forwards to the version taking an explicit charset, c-string and length.
bool str_to_time_with_warn | ( | String * | str, |
MYSQL_TIME * | l_time | ||
) |
Convert a time string to a MYSQL_TIME struct and produce a warning if string was cut during conversion.
void time_to_datetime | ( | THD * | thd, |
const MYSQL_TIME * | ltime, | ||
MYSQL_TIME * | ltime2 | ||
) |
Convert time to datetime.
The time value is added to the current datetime value.
thd | Thread context | |
[in] | ltime | Time value to convert from. |
[out] | ltime2 | Datetime value to convert to. |
void time_to_datetime | ( | THD * | thd, |
const MYSQL_TIME * | tm, | ||
const Time_zone & | tz, | ||
MYSQL_TIME * | dt | ||
) |
my_time_t TIME_to_timestamp | ( | const MYSQL_TIME * | t, |
const Time_zone & | tz, | ||
bool * | not_exist | ||
) |
|
static |
Convert a string to 8-bit representation, for use in str_to_time/str_to_date/str_to_date.
In the future to_ascii() can be extended to convert non-ASCII digits to ASCII digits (for example, ARABIC-INDIC, DEVANAGARI, BENGALI, and so on) so DATE/TIME/DATETIME values understand digits in the respected scripts.
const LEX_CSTRING interval_type_to_name[INTERVAL_LAST] |
Name description of interval names used in statements.
'interval_type_to_name' is ordered and sorted on interval size and interval complexity. Order of elements in 'interval_type_to_name' should correspond to the order of elements in 'interval_type' enum