[Tarantool-patches] [PATCH v1 7/8] sql: rework SUBSTR() function

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri Oct 29 01:13:05 MSK 2021


Thanks for the fixes!

> diff --git a/src/box/sql/func.c b/src/box/sql/func.c
> index 80b075dcf..65bf03250 100644
> --- a/src/box/sql/func.c
> +++ b/src/box/sql/func.c
> +
> +static void
> +func_substr_octets(struct sql_context *ctx, int argc, struct Mem *argv)
> +{
> +	assert(argc == 2 || argc == 3);
> +	if (mem_is_any_null(&argv[0], &argv[1]))
> +		return;
> +	assert(mem_is_bytes(&argv[0]) && mem_is_int(&argv[1]));
> +
> +	bool is_str = mem_is_str(&argv[0]);
> +	uint64_t size = argv[0].n;
> +
> +	if (argc == 2) {
> +		uint64_t start = mem_is_uint(&argv[1]) && argv[1].u.u > 1 ?
> +				 argv[1].u.u - 1 : 0;
> +		if (start >= size)
> +			return return_empty_str(ctx, is_str);
> +		char *s = &argv[0].z[start];
> +		uint64_t n = size - start;
> +		ctx->is_aborted = is_str ? mem_copy_str(ctx->pOut, s, n) != 0 :
> +				  mem_copy_bin(ctx->pOut, s, n) != 0;
> +		return;
> +	}
> +
> +	assert(argc == 3);
> +	if (mem_is_null(&argv[2]))
> +		return;
> +	assert(mem_is_int(&argv[2]));
> +	if (!mem_is_uint(&argv[2])) {
> +		diag_set(ClientError, ER_SQL_EXECUTE, "Length of the result "
> +			 "cannot be less than 0");
> +		ctx->is_aborted = true;
> +		return;
> +	}
> +	uint64_t start;
> +	uint64_t length;
> +	if (substr_normalize(argv[1].u.i, !mem_is_uint(&argv[1]), argv[2].u.u,
> +	    &start, &length) != 0) {

The second line of the call is misaligned.


More information about the Tarantool-patches mailing list