Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org, ImeevMA <imeevma@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v2 1/1] sql: COLLATE after LIMIT throws an error
Date: Mon, 21 May 2018 16:45:19 +0300	[thread overview]
Message-ID: <b1a0562f-8b08-6b50-89cd-5fdf2b72ff84@tarantool.org> (raw)
In-Reply-To: <7b33703aefcb498882fe8be652d129fcf5357e96.1526909105.git.imeevma@tarantool.org>

Hello. Thanks for the patch! See my 2 comments below.

On 21/05/2018 16:35, ImeevMA wrote:
> Originally, SQLite3 execute queries with COLLATE after LIMIT like
> "SELECT * FROM test LIMIT N COLLATE not_exist"
> and queries without COLLATE like
> "SELECT * FROM test LIMIT N"
> the same way.
> 
> Closes #3010
> ---
> Branch: https://github.com/tarantool/tarantool/tree/gh-3010-COLLATE-after-LIMIT-throws-an-error
> Issue: https://github.com/tarantool/tarantool/issues/3010
> 
>   src/box/sql/select.c            |  5 +++++
>   test/sql-tap/collation.test.lua | 44 ++++++++++++++++++++++++++++++++++++++++-
>   2 files changed, 48 insertions(+), 1 deletion(-)
> 
> diff --git a/src/box/sql/select.c b/src/box/sql/select.c
> index 29075d5..5e33256 100644
> --- a/src/box/sql/select.c
> +++ b/src/box/sql/select.c
> @@ -1993,6 +1993,11 @@ computeLimitRegisters(Parse * pParse, Select * p, int iBreak)
>   	sqlite3ExprCacheClear(pParse);
>   	assert(p->pOffset == 0 || p->pLimit != 0);
>   	if (p->pLimit) {
> +		if((p->pLimit->flags & EP_Collate) ||
> +					(p->pOffset && p->pOffset->flags & EP_Collate)) {

1. Please, use explicit != 0 to check, that an integer is not 0:
if ((p->pLimit->flags & EP_Collate) != 0 ...)

And fix alignment - the second line is very over indented.
> diff --git a/test/sql-tap/collation.test.lua b/test/sql-tap/collation.test.lua
> index 8a98de9..5c7255a 100755
> --- a/test/sql-tap/collation.test.lua
> +++ b/test/sql-tap/collation.test.lua
> @@ -1,6 +1,6 @@
>   #!/usr/bin/env tarantool
>   test = require("sqltester")
> -test:plan(173)
> +test:plan(177)
>   
>   local prefix = "collation-"
>   
> @@ -249,4 +249,46 @@ local like_testcases =
>   
>   test:do_catchsql_set_test(like_testcases, prefix)
>   
> +-- gh-3010: COLLATE after LIMIT should throw an error
> +
> +test:do_catchsql_test(
> +    "collate-after-limit-1.0",
> +    "SELECT 1 LIMIT 1 COLLATE BINARY;", {
> +        -- <collate-after-limit-1.0>
> +    1, "near \"COLLATE\": syntax error"
> +        -- <collate-after-limit-1.0>
> +});
> +
> +test:do_catchsql_test(
> +    "collate-after-limit-1.1",
> +    "SELECT 1 LIMIT 1 OFFSET 2 COLLATE BINARY;", {
> +        -- <collate-after-limit-1.1>
> +    1, "near \"COLLATE\": syntax error"
> +        -- <collate-after-limit-1.1>
> +});
> +
> +test:do_catchsql_test(
> +    "collate-after-limit-1.2",
> +    "SELECT 1 LIMIT 1 COLLATE BINARY, 2;", {
> +        -- <collate-after-limit-1.2>
> +    1, "near \"COLLATE\": syntax error"
> +        -- <collate-after-limit-1.2>
> +});
> +
> +
> +local net_box = require('net.box')
> +local test_run = require('test_run')
> +local inspector = test_run.new()

2. Hmm, it looks not to be a good idea to move netbox test there.
Lets better do this: create file sql/collation.test.lua, and move all
of gh-3010 tests into it. And please, add a test with OFFSET ... COLLATE.

> +
> +inspector:cmd("create server second with script='box/box.lua'\n")
> +inspector:cmd('start server second')
> +local uri = inspector:eval('second', 'box.cfg.listen')[1]
> +local conn = net_box.connect(uri)
> +
> +test:ok(not pcall(function() conn:execute("select 1 limit 1 collate not_exist") end),
> +        'attempt to use collate after limit')
> +
> +conn:close()
> +inspector:cmd('stop server second with cleanup=1')
> +
>   test:finish_test()
> 

  reply	other threads:[~2018-05-21 13:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-21 13:35 [tarantool-patches] " ImeevMA
2018-05-21 13:45 ` Vladislav Shpilevoy [this message]
2018-05-21 14:36 ImeevMA
2018-05-21 14:45 ` [tarantool-patches] " Vladislav Shpilevoy
2018-05-21 15:16   ` [tarantool-patches] " Мерген Имеев
2018-05-21 15:27     ` Vladislav Shpilevoy
2018-05-21 16:50       ` [tarantool-patches] " Мерген Имеев
2018-05-21 18:26         ` Vladislav Shpilevoy
2018-05-22  7:01           ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b1a0562f-8b08-6b50-89cd-5fdf2b72ff84@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v2 1/1] sql: COLLATE after LIMIT throws an error' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox