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 02A5F25BA7 for ; Tue, 30 Jul 2019 18:22:46 -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 6sYKPuzKAHAu for ; Tue, 30 Jul 2019 18:22:45 -0400 (EDT) Received: from smtp44.i.mail.ru (smtp44.i.mail.ru [94.100.177.104]) (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 5123E25B9F for ; Tue, 30 Jul 2019 18:22:45 -0400 (EDT) Date: Wed, 31 Jul 2019 01:22:30 +0300 From: Alexander Turenko Subject: [tarantool-patches] Re: [PATCH v1 1/1] driver: fix numeric string binding Message-ID: <20190730222229.7rc3mtuhabck2gxf@tkn_work_nb> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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: Kirill Shcherbatov Cc: tarantool-patches@freelists.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 >