MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / get_datetime_value

Function get_datetime_value

sql/item_cmpfunc.cc:241–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

239
240
241longlong
242get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
243 Item *warn_item, bool *is_null)
244{
245 longlong value= 0;
246 String buf, *str= 0;
247 Item *item= **item_arg;
248
249 if (item->is_temporal())
250 {
251// value= item->val_date_temporal();
252 *is_null= item->null_value;
253 }
254 else
255 {
256 str= item->val_str(&buf);
257 *is_null= item->null_value;
258 }
259 if (*is_null)
260 return ~(ulonglong) 0;
261 /*
262 Convert strings to the integer DATE/DATETIME representation.
263 Even if both dates provided in strings we can't compare them directly as
264 strings as there is no warranty that they are correct and do not miss
265 some insignificant zeros.
266 */
267 if (str)
268 {
269 bool error;
270 enum_field_types f_type= warn_item->field_type();
271 timestamp_type t_type= f_type ==
272 MYSQL_TYPE_DATE ? MYSQL_TIMESTAMP_DATE : MYSQL_TIMESTAMP_DATETIME;
273 value= (longlong) get_date_from_str(thd, str, t_type, warn_item->item_name.ptr(), &error);
274 /*
275 If str did not contain a valid date according to the current
276 SQL_MODE, get_date_from_str() has already thrown a warning,
277 and we don't want to throw NULL on invalid date (see 5.2.6
278 "SQL modes" in the manual), so we're done here.
279 */
280 }
281 return value;
282}
283
284
285/*

Callers 1

cmpMethod · 0.85

Calls 5

get_date_from_strFunction · 0.85
is_temporalMethod · 0.80
val_strMethod · 0.45
field_typeMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected