Don't fail when query_row() is called with an empty SELECT.

This commit is contained in:
Alexey Kopytov
2018-03-23 19:13:52 +03:00
parent ce5a14b50a
commit 7b383cc537
4 changed files with 17 additions and 2 deletions

View File

@ -299,7 +299,7 @@ end
function connection_methods.query_row(self, query)
local rs = self:query(query)
if rs == nil then
if rs == nil or rs.nrows == 0 then
return nil
end

View File

@ -210,13 +210,26 @@ sysbench $SB_ARGS run
########################################################################
cat >$CRAMTMP/api_sql.lua <<EOF
c = sysbench.sql.driver():connect()
c:query("CREATE TABLE IF NOT EXISTS t1(a INT)")
c:query("CREATE TABLE t1(a INT)")
c:bulk_insert_init("INSERT INTO t1 VALUES")
c:bulk_insert_next("(1)")
c:bulk_insert_done()
e,m = pcall(function () c:bulk_insert_next("(2)") end)
print(m)
c:bulk_insert_done()
c:query("DROP TABLE t1")
EOF
sysbench $SB_ARGS
########################################################################
# query_row() with an empty result set
########################################################################
cat >$CRAMTMP/api_sql.lua <<EOF
c = sysbench.sql.driver():connect()
c:query("CREATE TABLE t1(a INT)")
print(c:query_row("SELECT * FROM t1"))
c:query("DROP TABLE t1")
EOF
sysbench $SB_ARGS

View File

@ -114,3 +114,4 @@ SQL Lua API + MySQL tests
10
ALERT: attempt to call bulk_insert_next() before bulk_insert_init()
*/api_sql.lua:*: db_bulk_insert_next() failed (glob)
nil

View File

@ -120,3 +120,4 @@ SQL Lua API + PostgreSQL tests
10
ALERT: attempt to call bulk_insert_next() before bulk_insert_init()
*/api_sql.lua:*: db_bulk_insert_next() failed (glob)
nil