[tarantool-patches] Re: [PATCH] sql: LIKE/LENGTH process '\0'

n.pettik korablev at tarantool.org
Tue Jan 29 19:35:57 MSK 2019


> Fixes LIKE and LENGTH functions. '\0' now treated as
Nit: is treated.
> a usual symbol. Strings with '\0' are now processed
> entirely. Consider examples:
> 
> LENGTH(CHAR(65,00,65)) == 3
> LIKE(CHAR(65,00,65), CHAR(65,00,66)) == False
Also, I see that smth wrong with text in this mail again.
> 
> Closes #3542
Please, check other functions working with strings.
For instance, now I see that replace ignores \0 as well:

tarantool> box.sql.execute("select replace(CHAR(65,00,66), char(0), char(1))")
---
- - ["A\0B"]
...
> @@ -150,9 +150,13 @@ lengthFunc(sqlite3_context * context, int argc, sqlite3_value ** argv)
>  			const unsigned char *z = sqlite3_value_text(argv[0]);
>  			if (z == 0)
>  				return;
> +
Nit: don’t abuse empty lines.
>  			len = 0;
> -			while (*z) {
> +			size_t byte_len = sqlite3_value_bytes(argv[0]);
> +			const unsigned char *prev_z;
> +			for (size_t cnt = 0; cnt < byte_len; cnt += (z - prev_z)) {
Out of 80.
> diff --git a/test/sql-tap/gh-3542-like-len-null-term.test.lua b/test/sql-tap/gh-3542-like-len-null-term.test.lua
> new file mode 100755
> index 000000000..e9ea9ea30
> --- /dev/null
> +++ b/test/sql-tap/gh-3542-like-len-null-term.test.lua
> @@ -0,0 +1,97 @@
> +#!/usr/bin/env tarantool
> +test = require("sqltester")
> +test:plan(14)
> +
> +-- gh-3542 - LIKE/LENGTH do not scan if '\0' is encountered.
> +-- This test ensures that LIKE and LENGTH functions does NOT stop
> +-- string processing if '\0' is encountered.
I’d rather put these tests to sql-tap/func.test.lua





More information about the Tarantool-patches mailing list