Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH v1 1/1] driver: fix numeric string binding
@ 2019-07-29 11:16 Kirill Shcherbatov
  2019-07-30 22:22 ` [tarantool-patches] " Alexander Turenko
  0 siblings, 1 reply; 2+ messages in thread
From: Kirill Shcherbatov @ 2019-07-29 11:16 UTC (permalink / raw)
  To: tarantool-patches; +Cc: alexander.turenko, 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-30 22:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-29 11:16 [tarantool-patches] [PATCH v1 1/1] driver: fix numeric string binding Kirill Shcherbatov
2019-07-30 22:22 ` [tarantool-patches] " Alexander Turenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox