Tarantool development patches archive
 help / color / mirror / Atom feed
From: ImeevMA <imeevma@tarantool.org>
To: tarantool-patches@freelists.org
Cc: ImeevMA <imeevma@tarantool.org>
Subject: [tarantool-patches] [PATCH v2 1/1] sql: COLLATE after LIMIT throws an error
Date: Mon, 21 May 2018 17:27:55 +0300	[thread overview]
Message-ID: <f69a66181ad292a80e5d9cf32b1853d971dfaba8.1526912769.git.imeevma@tarantool.org> (raw)

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/collation.result   | 41 +++++++++++++++++++++++++++++++++++++++++
 test/sql/collation.test.lua | 19 +++++++++++++++++++
 3 files changed, 65 insertions(+)
 create mode 100644 test/sql/collation.result
 create mode 100644 test/sql/collation.test.lua

diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 29075d5..b11e688 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) != 0 ||
+					(p->pOffset && (p->pOffset->flags & EP_Collate) != 0)) {
+			sqlite3ErrorMsg(pParse, "near \"COLLATE\": syntax error");
+			return;
+		}
 		p->iLimit = iLimit = ++pParse->nMem;
 		v = sqlite3GetVdbe(pParse);
 		assert(v != 0);
diff --git a/test/sql/collation.result b/test/sql/collation.result
new file mode 100644
index 0000000..3a4f81f
--- /dev/null
+++ b/test/sql/collation.result
@@ -0,0 +1,41 @@
+remote = require('net.box')
+---
+...
+-- gh-3010: COLLATE after LIMIT should throw an error
+-- All of these tests should throw error "near "COLLATE": syntax error"
+box.sql.execute("SELECT 1 LIMIT 1 COLLATE BINARY;")
+---
+- error: 'near "COLLATE": syntax error'
+...
+box.sql.execute("SELECT 1 LIMIT 1 COLLATE BINARY OFFSET 1;")
+---
+- error: 'near "COLLATE": syntax error'
+...
+box.sql.execute("SELECT 1 LIMIT 1 OFFSET 1 COLLATE BINARY;")
+---
+- error: 'near "COLLATE": syntax error'
+...
+box.sql.execute("SELECT 1 LIMIT 1, 1 COLLATE BINARY;")
+---
+- error: 'near "COLLATE": syntax error'
+...
+box.sql.execute("SELECT 1 LIMIT 1 COLLATE BINARY, 1;")
+---
+- error: 'near "COLLATE": syntax error'
+...
+box.schema.user.grant('guest','read,write,execute', 'universe')
+---
+...
+cn = remote.connect(box.cfg.listen)
+---
+...
+cn:execute('select 1 limit ? collate not_exist', {1})
+---
+- error: 'Failed to execute SQL statement: near "COLLATE": syntax error'
+...
+cn:close()
+---
+...
+box.schema.user.revoke('guest', 'read,write,execute', 'universe')
+---
+...
diff --git a/test/sql/collation.test.lua b/test/sql/collation.test.lua
new file mode 100644
index 0000000..fe8c1ba
--- /dev/null
+++ b/test/sql/collation.test.lua
@@ -0,0 +1,19 @@
+remote = require('net.box')
+
+-- gh-3010: COLLATE after LIMIT should throw an error
+
+-- All of these tests should throw error "near "COLLATE": syntax error"
+box.sql.execute("SELECT 1 LIMIT 1 COLLATE BINARY;")
+box.sql.execute("SELECT 1 LIMIT 1 COLLATE BINARY OFFSET 1;")
+box.sql.execute("SELECT 1 LIMIT 1 OFFSET 1 COLLATE BINARY;")
+box.sql.execute("SELECT 1 LIMIT 1, 1 COLLATE BINARY;")
+box.sql.execute("SELECT 1 LIMIT 1 COLLATE BINARY, 1;")
+
+
+box.schema.user.grant('guest','read,write,execute', 'universe')
+cn = remote.connect(box.cfg.listen)
+
+cn:execute('select 1 limit ? collate not_exist', {1})
+
+cn:close()
+box.schema.user.revoke('guest', 'read,write,execute', 'universe')
-- 
2.7.4

             reply	other threads:[~2018-05-21 14:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-21 14:27 ImeevMA [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-05-21 14:36 ImeevMA
2018-05-21 13:35 ImeevMA

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=f69a66181ad292a80e5d9cf32b1853d971dfaba8.1526912769.git.imeevma@tarantool.org \
    --to=imeevma@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [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