diff --git a/resources/install/scripts/resources/functions/database.lua b/resources/install/scripts/resources/functions/database.lua index 91bb5f5390..478dbdb55b 100644 --- a/resources/install/scripts/resources/functions/database.lua +++ b/resources/install/scripts/resources/functions/database.lua @@ -117,6 +117,14 @@ local function new_database(backend) assert(x == 2, ("Got %d expected %d"):format(x, 2)) end + do local x = 0 + db:query("select 1 as v union all select 2 as v", function(row) + x = x + 1 + return "1" + end) + assert(x == 1, ("Got %d expected %d"):format(x, 2)) + end + assert("1" == db:first_value("select 1 as v union all select 2 as v")) local t = assert(db:first_row("select '1' as v union all select '2' as v")) diff --git a/resources/install/scripts/resources/functions/database/luasql.lua b/resources/install/scripts/resources/functions/database/luasql.lua index 010481d0db..feedc32c2c 100644 --- a/resources/install/scripts/resources/functions/database/luasql.lua +++ b/resources/install/scripts/resources/functions/database/luasql.lua @@ -54,7 +54,8 @@ function LuaSQLDatabase:query(sql, fn) local row, err = cur:fetch({}, "a") if not row then break end local ok, ret = pcall(fn, apply_names(row, colnames, "")) - if (not ok) or (type(ret) == 'number' and ret ~= 0) then + ret = tonumber(ret) + if (not ok) or (ret and ret ~= 0) then break end end diff --git a/resources/install/scripts/resources/functions/database/odbc.lua b/resources/install/scripts/resources/functions/database/odbc.lua index e88460b336..0e1bf9fac5 100644 --- a/resources/install/scripts/resources/functions/database/odbc.lua +++ b/resources/install/scripts/resources/functions/database/odbc.lua @@ -38,8 +38,8 @@ function OdbcDatabase:query(sql, fn) self._rows_affected = nil if fn then return self._dbh:neach(sql, function(row) - local n = fn(remove_null(row, odbc.NULL, "")) - if type(n) == 'number' and n ~= 0 then + local n = tonumber((fn(remove_null(row, odbc.NULL, "")))) + if n and n ~= 0 then return true end end) diff --git a/resources/install/scripts/resources/functions/database/odbcpool.lua b/resources/install/scripts/resources/functions/database/odbcpool.lua index 6ee1532915..9f46635696 100644 --- a/resources/install/scripts/resources/functions/database/odbcpool.lua +++ b/resources/install/scripts/resources/functions/database/odbcpool.lua @@ -39,8 +39,8 @@ function OdbcPoolDatabase:query(sql, fn) if fn then ok, err = cli:acquire(self._timeout, function(dbh) local ok, err = dbh:neach(sql, function(row) - local n = fn(remove_null(row, odbc.NULL, "")) - if type(n) == 'number' and n ~= 0 then + local n = tonumber((fn(remove_null(row, odbc.NULL, "")))) + if n and n ~= 0 then return true end end)