[Tarantool-patches] [PATCH v4 46/53] sql: introduce mem_implicit_cast()
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Tue Mar 30 02:08:09 MSK 2021
Thanks for the patch!
> diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
> index 559bf6121..1baf4c482 100644
> --- a/src/box/sql/mem.c
> +++ b/src/box/sql/mem.c
> @@ -1071,6 +1093,140 @@ mem_explicit_cast(struct Mem *mem, enum field_type type)
<...>
> +
> +int
> +mem_implicit_cast_old(struct Mem *mem, enum field_type type)
What is this?
> +{
> + if (mem_is_null(mem))
> + return 0;
> + switch (type) {
> + case FIELD_TYPE_UNSIGNED:
> + if ((mem->flags & MEM_UInt) != 0)
> + return 0;
> + if ((mem->flags & MEM_Real) != 0)
> + return mem_convert_double_to_unsigned_lossless(mem);
> + if ((mem->flags & MEM_Str) != 0)
> + return mem_convert_varstring_to_unsigned(mem);
> + return -1;
> + case FIELD_TYPE_STRING:
> + if ((mem->flags & (MEM_Str | MEM_Blob)) != 0)
> + return 0;
> + if ((mem->flags & (MEM_Int | MEM_UInt)) != 0)
> + return mem_convert_integer_to_string(mem);
> + if ((mem->flags & MEM_Real) != 0)
> + return mem_convert_double_to_string(mem);
> + return -1;
> + case FIELD_TYPE_DOUBLE:
> + if ((mem->flags & MEM_Real) != 0)
> + return 0;
> + if ((mem->flags & (MEM_Int | MEM_UInt)) != 0)
> + return mem_convert_integer_to_double(mem);
> + if ((mem->flags & MEM_Str) != 0)
> + return mem_convert_varstring_to_double(mem);
> + return -1;
> + case FIELD_TYPE_INTEGER:
> + if ((mem->flags & (MEM_Int | MEM_UInt)) != 0)
> + return 0;
> + if ((mem->flags & MEM_Str) != 0)
> + return mem_convert_varstring_to_integer(mem);
> + if (mem_is_double(mem))
> + return mem_convert_double_to_integer_lossless(mem);
> + return -1;
> + case FIELD_TYPE_BOOLEAN:
> + if ((mem->flags & MEM_Bool) != 0)
> + return 0;
> + return -1;
> + case FIELD_TYPE_VARBINARY:
> + if ((mem->flags & MEM_Blob) != 0)
> + return 0;
> + return -1;
> + case FIELD_TYPE_NUMBER:
> + if ((mem->flags & (MEM_Int | MEM_UInt | MEM_Real)) != 0)
> + return 0;
> + if ((mem->flags & MEM_Str) != 0)
> + return mem_convert_to_number(mem);
> + return -1;
> + case FIELD_TYPE_MAP:
> + if (mem_is_map(mem))
> + return 0;
> + return -1;
> + case FIELD_TYPE_ARRAY:
> + if (mem_is_array(mem))
> + return 0;
> + return -1;
> + case FIELD_TYPE_SCALAR:
> + if ((mem->flags & MEM_Blob) != 0 &&
> + (mem->flags & MEM_Subtype) != 0)
> + return -1;
> + return 0;
> + default:
> + break;
> + }
> + return -1;
> +}
More information about the Tarantool-patches
mailing list