[tarantool-patches] Re: [PATCH v1 1/1] driver: fix numeric string binding
Alexander Turenko
alexander.turenko at tarantool.org
Wed Jul 31 01:22:30 MSK 2019
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
>
More information about the Tarantool-patches
mailing list