Commit 600452eb authored by Jonah's avatar Jonah

added query functions

parent 74474b68
......@@ -28,3 +28,77 @@ local admins = {
["admin"] = true,
["superadmin"] = true
}
local apiErrorCount = 0
local apiLastCheck = apiLastCheck or 0
local pbQueue = pbQueue or {}
pbTable = pbTable or {}
--DB functions
local function pbSQLQuery(sql, qTab)
local ply = qTab.ply
local steamid = qTab.steamid
local callback = qTab.cb
local aid = qTab.aid
local wait = qTab.wait
local result
local query = propban_database:query(sql)
if not query then
ServerLog("PropBan Query is empty\n")
if (propban_database:status() ~= mysqloo.DATABASE_CONNECTED) then
propban_database:connect()
ErrorNoHalt("PropBan Empty query, attempting reconnection")
return
else
error("PropBan empty query, already connected.\n")
end
end
query.onSuccess = function(_, data)
if not callback then
result = data
else
callback(data, qTab)
end
end
query.onError = function(_, err, sql)
ServerLog("PropBan ERROR "..err.."\n")
ServerLog("PropBan ERROR"..sql.."\n")
if ((propban_database:status() ~= mysqloo.DATABASE_CONNECTED) and callback) then
table.insert(pbQueue, {sql,qTab})
propban_database:connect()
return
else
propban_database:connect()
propban_database:wait()
end
if (propban_database:status() ~= mysqloo.DATABASE_CONNECTED) then
ErrorNoHalt("PropBan Reconnection to the db server failed. \n")
return
end
end
query:start()
if not callback then
if wait then query:wait() end
return result
end
end
propban_database.onConnected = function()
ServerLog("PropBan Mysql successfully connected \n")
pbSQLQuery("SET NAMES UTF8", {})
if pbQueue then
for k, v in pairs(pbQueue) do
pbSQLQuery(v[1], v[2])
end
pbQueue = {}
end
end
propban_database.onConnectionFailed = function (db, err)
ServerLog("PropBan Mysql failed to connect\n")
ServerLog("PropBan Mysql Error:"..tostring(err).."\n")
end
propban_database:connect()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment