fix: dont use builtin error function that cause leak unclosed file
This commit is contained in:
@@ -57,17 +57,20 @@ function BaseController:removeSession(key)
|
||||
end
|
||||
function BaseController:index(...)
|
||||
self:error("#index: subclasses responsibility")
|
||||
return false
|
||||
end
|
||||
|
||||
-- not found action
|
||||
function BaseController:actionnotfound(...)
|
||||
local args = {...}
|
||||
self:error("#action "..args[1].." is not found in controller "..self.class)
|
||||
return false
|
||||
end
|
||||
-- not found model
|
||||
function BaseController:modelnotfound(...)
|
||||
local args = {...}
|
||||
self:error("Model "..firstToUpper(args[1]).."Model is not found in controller "..self.class)
|
||||
return false
|
||||
end
|
||||
-- The not found controller
|
||||
|
||||
|
||||
@@ -32,6 +32,5 @@ function BaseObject:error(msg,...)
|
||||
local emsg = string.format(msg or "ERROR",...)
|
||||
echo(emsg)
|
||||
self:log(Logger.ERROR, msg,...)
|
||||
error(emsg)
|
||||
return false
|
||||
end
|
||||
@@ -96,7 +96,7 @@ function loadscript(file, args)
|
||||
tmp = tmp:sub(y + 1)
|
||||
b, f = tmp:find("<%?=")
|
||||
else
|
||||
error("Syntax error near line " .. i)
|
||||
return nil ,"Syntax error near line " .. i
|
||||
end
|
||||
end
|
||||
pro = pro .. "\"" .. utils.escape(tmp, true) .. "\")\n"
|
||||
|
||||
@@ -110,12 +110,12 @@ end
|
||||
function SQLQueryGenerator:error(msg, ...)
|
||||
local emsg = string.format(msg or "ERROR", ...)
|
||||
LOG_ERROR(msg, ...)
|
||||
error(emsg)
|
||||
end
|
||||
|
||||
function SQLQueryGenerator:infer_field(k)
|
||||
if not self.table_name then
|
||||
self:error("Unknown input table (specified by `table_name` field)")
|
||||
return nil
|
||||
end
|
||||
if not self.joins then
|
||||
return k
|
||||
@@ -135,6 +135,7 @@ function SQLQueryGenerator:sql_joins()
|
||||
local arr = explode(v, ".")
|
||||
if not arr[2] then
|
||||
self:error("SQL JOIN: Other table name parsing error: " .. v)
|
||||
return nil
|
||||
end
|
||||
table.insert(joins, string.format("INNER JOIN %s ON %s = %s", arr[1], self:infer_field(k), v))
|
||||
end
|
||||
@@ -159,6 +160,7 @@ function SQLQueryGenerator:sql_order()
|
||||
local arr = explode(v, "$")
|
||||
if #arr ~= 2 then
|
||||
self:error("Invalid field order format %s", v)
|
||||
return nil
|
||||
end
|
||||
if arr[2] == "asc" then
|
||||
table.insert(tb, self:infer_field(arr[1]) .. " ASC")
|
||||
@@ -166,6 +168,7 @@ function SQLQueryGenerator:sql_order()
|
||||
table.insert(tb, self:infer_field(arr[1]) .. " DESC")
|
||||
else
|
||||
self:error("Unknown order %s", arr[2])
|
||||
return nil
|
||||
end
|
||||
end
|
||||
return table.concat(tb, ",")
|
||||
@@ -174,6 +177,7 @@ end
|
||||
function SQLQueryGenerator:sql_where(cond, obj)
|
||||
if not obj then
|
||||
self:error("%s condition is nil", cond)
|
||||
return nil
|
||||
end
|
||||
local conds = {}
|
||||
local op = " AND "
|
||||
@@ -182,6 +186,7 @@ function SQLQueryGenerator:sql_where(cond, obj)
|
||||
end
|
||||
if type(obj) ~= 'table' then
|
||||
self:error("Invalid input data for operator " .. cond)
|
||||
return nil
|
||||
end
|
||||
for k, v in pairs(obj) do
|
||||
if k == "$and" or k == "$or" then
|
||||
@@ -203,6 +208,7 @@ end
|
||||
function SQLQueryGenerator:parse_value(v, types)
|
||||
if not types[type(v)] then
|
||||
self:error("Type error: unexpected type %s", type(v))
|
||||
return nil
|
||||
end
|
||||
if type(v) == "number" then
|
||||
return tostring(v)
|
||||
@@ -215,6 +221,7 @@ function SQLQueryGenerator:binary(k, v)
|
||||
local arr = explode(k, "$");
|
||||
if #arr > 2 then
|
||||
self:error("Invalid left hand side format: %s", k)
|
||||
return nil
|
||||
end
|
||||
if #arr == 2 then
|
||||
if arr[2] == "gt" then
|
||||
@@ -272,6 +279,7 @@ function SQLQueryGenerator:binary(k, v)
|
||||
}))
|
||||
else
|
||||
self:error("Unsupported operator `%s`", arr[2])
|
||||
return nil
|
||||
end
|
||||
else
|
||||
return string.format("(%s=%s)", self:infer_field(arr[1]), self:parse_value(v, {
|
||||
@@ -419,7 +427,8 @@ function DBModel:delete(name, cond)
|
||||
local generator = SQLQueryGenerator:new(filter)
|
||||
local r,sql = generator:sql_delete()
|
||||
if not r then
|
||||
return error(sql)
|
||||
LOG_ERROR("Error generating delete query: %s", sql)
|
||||
return false
|
||||
end
|
||||
LOG_DEBUG("Execute query: %s", sql);
|
||||
return self:exec(sql)
|
||||
|
||||
Reference in New Issue
Block a user