MCPcopy Create free account
hub / github.com/MariaDB/server / get_interval_value

Function get_interval_value

sql/item_timefunc.cc:1970–2142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1968*/
1969
1970bool get_interval_value(THD *thd, Item *args,
1971 interval_type int_type, INTERVAL *interval)
1972{
1973 ulonglong array[5];
1974 ulonglong UNINIT_VAR(value);
1975 const char *UNINIT_VAR(str);
1976 size_t UNINIT_VAR(length);
1977 CHARSET_INFO *UNINIT_VAR(cs);
1978 char buf[100];
1979 String str_value(buf, sizeof(buf), &my_charset_bin);
1980
1981 bzero((char*) interval,sizeof(*interval));
1982 if (int_type == INTERVAL_SECOND && args->decimals)
1983 {
1984 VDec val(args);
1985 if (val.is_null())
1986 return true;
1987 Sec6 d(val.ptr());
1988 interval->neg= d.neg();
1989 if (d.sec() >= LONGLONG_MAX)
1990 {
1991 ErrConvDecimal err(val.ptr());
1992 thd->push_warning_truncated_wrong_value("seconds", err.ptr());
1993 return true;
1994 }
1995 interval->second= d.sec();
1996 interval->second_part= d.usec();
1997 return false;
1998 }
1999 else if ((int) int_type <= INTERVAL_MICROSECOND)
2000 {
2001 /*
2002 Let's use Longlong_hybrid_null to handle correctly:
2003 - signed and unsigned values
2004 - the corner case with LONGLONG_MIN
2005 (avoid undefined behavior with its negation)
2006 */
2007 const Longlong_hybrid_null nr= args->to_longlong_hybrid_null();
2008 if (nr.is_null())
2009 return true;
2010 value= nr.abs();
2011 interval->neg= nr.neg() ? 1 : 0;
2012 }
2013 else
2014 {
2015 String *res;
2016 if (!(res= args->val_str_ascii(&str_value)))
2017 return (1);
2018
2019 /* record negative intervals in interval->neg */
2020 str=res->ptr();
2021 cs= res->charset();
2022 const char *end=str+res->length();
2023 while (str != end && my_isspace(cs,*str))
2024 str++;
2025 if (str != end && *str == '-')
2026 {
2027 interval->neg=1;

Callers 3

init_intervalMethod · 0.85
vers_set_intervalMethod · 0.85
addMethod · 0.85

Calls 13

get_interval_infoFunction · 0.85
is_nullMethod · 0.45
ptrMethod · 0.45
negMethod · 0.45
secMethod · 0.45
usecMethod · 0.45
absMethod · 0.45
val_str_asciiMethod · 0.45
charsetMethod · 0.45

Tested by

no test coverage detected