From: Nikita Pettik <korablev@tarantool.org> To: tarantool-patches@dev.tarantool.org Cc: v.shpilevoy@tarantool.org Subject: [Tarantool-patches] [PATCH] sql: fix off-by-one error while setting bind names Date: Tue, 4 Feb 2020 20:12:14 +0300 [thread overview] Message-ID: <af6e434c04d2ee54278fd235705614531511155a.1580834040.git.korablev@tarantool.org> (raw) Names of bindings are stored in the array indexed from 1 (see struct Vdbe->pVList). So to get name of i-th values to be bound, one should call sqlVListNumToName(list, i+1) not sqlVListNumToName(list, i). For this reason, names of binding parameters returned in meta-information in response to :prepare() call are shifted by one. Let's fix it and calculate position of binding parameter taking into consideration 1-based indexing. Closes #4760 --- Branch: https://github.com/tarantool/tarantool/commits/np/gh-4760-off-by-one-bind Issue: https://github.com/tarantool/tarantool/issues/4760 src/box/sql/vdbeapi.c | 2 +- test/sql/prepared.result | 58 ++++++++++++++++++++++++++++++++++++++++++++++ test/sql/prepared.test.lua | 16 +++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 182f60aac..c984f9506 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -1128,7 +1128,7 @@ sql_bind_parameter_name(const struct sql_stmt *stmt, int i) struct Vdbe *p = (struct Vdbe *) stmt; if (p == NULL) return NULL; - return sqlVListNumToName(p->pVList, i); + return sqlVListNumToName(p->pVList, i+1); } /* diff --git a/test/sql/prepared.result b/test/sql/prepared.result index 71ab0bb57..5a16ea3b1 100644 --- a/test/sql/prepared.result +++ b/test/sql/prepared.result @@ -514,6 +514,64 @@ unprepare(s.stmt_id) | - null | ... +-- gh-4760: make sure that names of all bindings are parsed correctly. +-- +s = prepare("SELECT a FROM test WHERE id = :id AND b = :name") + | --- + | ... +s.params[1] + | --- + | - name: :id + | type: ANY + | ... +s.params[2] + | --- + | - name: :name + | type: ANY + | ... +unprepare(s.stmt_id) + | --- + | - null + | ... + +s = prepare("SELECT ?, :id, :name, ?, @name2, ?") + | --- + | ... +s.params[1] + | --- + | - name: '?' + | type: ANY + | ... +s.params[2] + | --- + | - name: :id + | type: ANY + | ... +s.params[3] + | --- + | - name: :name + | type: ANY + | ... +s.params[4] + | --- + | - name: '?' + | type: ANY + | ... +s.params[5] + | --- + | - name: '@name2' + | type: ANY + | ... +s.params[6] + | --- + | - name: '?' + | type: ANY + | ... +unprepare(s.stmt_id) + | --- + | - null + | ... + -- DML s = prepare("INSERT INTO test VALUES (?, ?, ?);") | --- diff --git a/test/sql/prepared.test.lua b/test/sql/prepared.test.lua index 1e3f02b09..85116aa47 100644 --- a/test/sql/prepared.test.lua +++ b/test/sql/prepared.test.lua @@ -189,6 +189,22 @@ execute(s.stmt_id, {'6'}) execute(s.stmt_id, {'9'}) unprepare(s.stmt_id) +-- gh-4760: make sure that names of all bindings are parsed correctly. +-- +s = prepare("SELECT a FROM test WHERE id = :id AND b = :name") +s.params[1] +s.params[2] +unprepare(s.stmt_id) + +s = prepare("SELECT ?, :id, :name, ?, @name2, ?") +s.params[1] +s.params[2] +s.params[3] +s.params[4] +s.params[5] +s.params[6] +unprepare(s.stmt_id) + -- DML s = prepare("INSERT INTO test VALUES (?, ?, ?);") execute(s.stmt_id, {5, 6, '7'}) -- 2.15.1
next reply other threads:[~2020-02-04 17:12 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-02-04 17:12 Nikita Pettik [this message] 2020-02-04 21:36 ` Vladislav Shpilevoy 2020-02-06 17:30 ` Nikita Pettik
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=af6e434c04d2ee54278fd235705614531511155a.1580834040.git.korablev@tarantool.org \ --to=korablev@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH] sql: fix off-by-one error while setting bind names' \ /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