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:
@@ -117,6 +117,14 @@ local function new_database(backend)
|
|||||||
assert(x == 2, ("Got %d expected %d"):format(x, 2))
|
assert(x == 2, ("Got %d expected %d"):format(x, 2))
|
||||||
end
|
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"))
|
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"))
|
local t = assert(db:first_row("select '1' as v union all select '2' as v"))
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ function LuaSQLDatabase:query(sql, fn)
|
|||||||
local row, err = cur:fetch({}, "a")
|
local row, err = cur:fetch({}, "a")
|
||||||
if not row then break end
|
if not row then break end
|
||||||
local ok, ret = pcall(fn, apply_names(row, colnames, ""))
|
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
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ function OdbcDatabase:query(sql, fn)
|
|||||||
self._rows_affected = nil
|
self._rows_affected = nil
|
||||||
if fn then
|
if fn then
|
||||||
return self._dbh:neach(sql, function(row)
|
return self._dbh:neach(sql, function(row)
|
||||||
local n = fn(remove_null(row, odbc.NULL, ""))
|
local n = tonumber((fn(remove_null(row, odbc.NULL, ""))))
|
||||||
if type(n) == 'number' and n ~= 0 then
|
if n and n ~= 0 then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ function OdbcPoolDatabase:query(sql, fn)
|
|||||||
if fn then
|
if fn then
|
||||||
ok, err = cli:acquire(self._timeout, function(dbh)
|
ok, err = cli:acquire(self._timeout, function(dbh)
|
||||||
local ok, err = dbh:neach(sql, function(row)
|
local ok, err = dbh:neach(sql, function(row)
|
||||||
local n = fn(remove_null(row, odbc.NULL, ""))
|
local n = tonumber((fn(remove_null(row, odbc.NULL, ""))))
|
||||||
if type(n) == 'number' and n ~= 0 then
|
if n and n ~= 0 then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user