From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id DDDD7244CF for ; Mon, 29 Jul 2019 07:16:35 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pdvPsGfKo8g1 for ; Mon, 29 Jul 2019 07:16:35 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 9D443244B7 for ; Mon, 29 Jul 2019 07:16:35 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v1 1/1] driver: fix numeric string binding Date: Mon, 29 Jul 2019 14:16:31 +0300 Message-Id: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: alexander.turenko@tarantool.org, Kirill Shcherbatov 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