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

Function ConvertType

storage/connect/value.cpp:296–332  ·  view source on GitHub ↗

/ ConvertType: what this function does is to determine the type to */ which should be converted a value so no precision would be lost. */ This can be a numeric type if num is true or non numeric if false. */ Note: this is an ultra simplified version of this function that */ should become more and more complex as new types are added. */ Not evaluated types (TYPE_VOID or TYPE_UNDEF) re

Source from the content-addressed store, hash-verified

294/* IsType... functions so match does not prevent correct setting. */
295/***********************************************************************/
296int ConvertType(int target, int type, CONV kind, bool match)
297{
298 switch (kind) {
299 case CNV_CHAR:
300 if (match && (!IsTypeChar(target) || !IsTypeChar(type)))
301 return TYPE_ERROR;
302
303 return TYPE_STRING;
304 case CNV_NUM:
305 if (match && (!IsTypeNum(target) || !IsTypeNum(type)))
306 return TYPE_ERROR;
307
308 return (target == TYPE_DOUBLE || type == TYPE_DOUBLE) ? TYPE_DOUBLE
309 : (target == TYPE_DATE || type == TYPE_DATE) ? TYPE_DATE
310 : (target == TYPE_BIGINT || type == TYPE_BIGINT) ? TYPE_BIGINT
311 : (target == TYPE_INT || type == TYPE_INT) ? TYPE_INT
312 : (target == TYPE_SHORT || type == TYPE_SHORT) ? TYPE_SHORT
313 : TYPE_TINY;
314 default:
315 if (target == TYPE_ERROR || target == type)
316 return type;
317
318 if (match && ((IsTypeChar(target) && !IsTypeChar(type)) ||
319 (IsTypeNum(target) && !IsTypeNum(type))))
320 return TYPE_ERROR;
321
322 return (target == TYPE_DOUBLE || type == TYPE_DOUBLE) ? TYPE_DOUBLE
323 : (target == TYPE_DATE || type == TYPE_DATE) ? TYPE_DATE
324 : (target == TYPE_BIGINT || type == TYPE_BIGINT) ? TYPE_BIGINT
325 : (target == TYPE_INT || type == TYPE_INT) ? TYPE_INT
326 : (target == TYPE_SHORT || type == TYPE_SHORT) ? TYPE_SHORT
327 : (target == TYPE_STRING || type == TYPE_STRING) ? TYPE_STRING
328 : (target == TYPE_TINY || type == TYPE_TINY) ? TYPE_TINY
329 : TYPE_ERROR;
330 } // endswitch kind
331
332} // end of ConvertType
333
334/***********************************************************************/
335/* AllocateConstant: allocates a constant Value. */

Callers 1

ConvertMethod · 0.85

Calls 2

IsTypeCharFunction · 0.85
IsTypeNumFunction · 0.70

Tested by

no test coverage detected