From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: [tarantool-patches] Re: [PATCH v1 1/1] driver: fix numeric string binding
Date: Wed, 31 Jul 2019 01:22:30 +0300 [thread overview]
Message-ID: <20190730222229.7rc3mtuhabck2gxf@tkn_work_nb> (raw)
In-Reply-To: <efd86973e5b28f0ed15dadf28de195b44361650f.1564398868.git.kshcherbatov@tarantool.org>
Pushed to master, thanks!
WBR, Alexander Turenko.
On Mon, Jul 29, 2019 at 02:16:31PM +0300, Kirill Shcherbatov wrote:
> Driver code used to call lua_isnumber() to determine whether
> given binding argument is number. That is a mess, because
> some strings are also recognised by lua_isnumber() but connector
> mustn't perform any type casts.
> Changed lua_isnumber() test to lua_type(L, idx) == LUA_TNUMBER
> that is more appropriate.
>
> Closes #21
> ---
> https://github.com/tarantool/pg/compare/kshch/gh-21-numeric-string-binding?expand=1
> https://github.com/tarantool/pg/issues/21
>
> pg/driver.c | 2 +-
> test/pg.test.lua | 16 +++++++++++++++-
> 2 files changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/pg/driver.c b/pg/driver.c
> index 2fe6836..e79d7e7 100644
> --- a/pg/driver.c
> +++ b/pg/driver.c
> @@ -285,7 +285,7 @@ lua_parse_param(struct lua_State *L,
> return;
> }
>
> - if (lua_isnumber(L, idx)) {
> + if (lua_type(L, idx) == LUA_TNUMBER) {
> size_t len;
> *value = lua_tolstring(L, idx, &len);
> *length = len;
> diff --git a/test/pg.test.lua b/test/pg.test.lua
> index 6358ab9..144ceea 100755
> --- a/test/pg.test.lua
> +++ b/test/pg.test.lua
> @@ -20,7 +20,7 @@ local conn, msg = pg.connect({ host = host, port = port, user = user, pass = pas
> if conn == nil then error(msg) end
>
> function test_old_api(t, c)
> - t:plan(14)
> + t:plan(15)
> t:ok(c ~= nil, "connection")
> -- Add an extension to 'tap' module
> getmetatable(t).__index.q = function(test, stmt, result, ...)
> @@ -64,6 +64,20 @@ function test_old_api(t, c)
> c:execute("DROP TABLE _tx_test")
> end)
>
> + t:test("numeric string binding", function(t)
> + t:plan(1)
> + if not c:execute([[CREATE TABLE TEST1 ( TEST1_ID SERIAL PRIMARY KEY,
> + TEST1_REQUESTID VARCHAR(32)
> + NOT NULL DEFAULT '' );]]) then
> + return
> + end
> + c:execute('INSERT INTO TEST1 (TEST1_REQUESTID) VALUES ($1)', '12E30')
> + t:q('SELECT TEST1_REQUESTID FROM TEST1;',
> + {{ test1_requestid = '12E30'}})
> +
> + c:execute("DROP TABLE TEST1")
> + end)
> +
> local status, reason = pcall(c.execute, c, 'DROP TABLE unknown_table')
> t:like(reason, 'unknown_table', 'error')
> end
> --
> 2.22.0
>
prev parent reply other threads:[~2019-07-30 22:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-29 11:16 [tarantool-patches] " Kirill Shcherbatov
2019-07-30 22:22 ` Alexander Turenko [this message]
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=20190730222229.7rc3mtuhabck2gxf@tkn_work_nb \
--to=alexander.turenko@tarantool.org \
--cc=kshcherbatov@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='[tarantool-patches] Re: [PATCH v1 1/1] driver: fix numeric string binding' \
/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