Fix. ODBC db backend should breaks loop only when callback returns number ~= 0
```Lua dbh:query(sql, function(row) -- return 0 -- should not break loop -- return true -- should not break loop return 1 -- should break loop end) ```
This commit is contained in:
@@ -77,6 +77,38 @@ local function new_database(backend)
|
|||||||
|
|
||||||
assert(db:connected())
|
assert(db:connected())
|
||||||
|
|
||||||
|
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, 1))
|
||||||
|
end
|
||||||
|
|
||||||
|
do local x = 0
|
||||||
|
db:query("select 1 as v union all select 2 as v", function(row)
|
||||||
|
x = x + 1
|
||||||
|
return 0
|
||||||
|
end)
|
||||||
|
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 true
|
||||||
|
end)
|
||||||
|
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 false
|
||||||
|
end)
|
||||||
|
assert(x == 2, ("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"))
|
||||||
@@ -99,6 +131,11 @@ local function new_database(backend)
|
|||||||
|
|
||||||
db:release()
|
db:release()
|
||||||
assert(not db:connected())
|
assert(not db:connected())
|
||||||
|
|
||||||
|
-- second close
|
||||||
|
db:release()
|
||||||
|
assert(not db:connected())
|
||||||
|
|
||||||
log.info('self_test Database - pass')
|
log.info('self_test Database - pass')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,10 @@ 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)
|
||||||
return fn(remove_null(row, odbc.NULL, ""))
|
local n = fn(remove_null(row, odbc.NULL, ""))
|
||||||
|
if type(n) == 'number' and n ~= 0 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
local ok, err = self._dbh:exec(sql)
|
local ok, err = self._dbh:exec(sql)
|
||||||
|
|||||||
@@ -39,7 +39,10 @@ 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)
|
||||||
return fn(remove_null(row, odbc.NULL, ""))
|
local n = fn(remove_null(row, odbc.NULL, ""))
|
||||||
|
if type(n) == 'number' and n ~= 0 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
if err and not ok then
|
if err and not ok then
|
||||||
log.errf("Can not execute sql: %s\n%s", tostring(err), sql)
|
log.errf("Can not execute sql: %s\n%s", tostring(err), sql)
|
||||||
|
|||||||
Reference in New Issue
Block a user