Fix. FreeSWITCH also breaks loop if return string value which contain number.

```Lua
dbh:query(sql, function()
  return "1" -- breaks loop
end)
This commit is contained in:
Alexey Melnichuk 2016-02-26 14:17:28 +03:00
parent ebfcdc38be
commit 7e1481b747
4 changed files with 14 additions and 5 deletions

View File

@ -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"))

View File

@ -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

View File

@ -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)

View File

@ -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)