Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- *************************************************
- * Developer: Jusonex
- * Date: 08.01.2012
- *************************************************
- --]]
- _dbPoll = dbPoll
- function dbPoll(connection, timeout)
- local result, numrows, errormsg = _dbPoll(connection, timeout)
- if result == nil then
- outputConsole( "dbPoll result not ready yet" )
- return
- end
- if result == false then
- outputConsole( "dbPoll failed. Error code: "..tostring(numrows).." Error message: "..tostring(errmsg))
- return
- end
- return result, numrows
- end
- function mysql_query(...)
- return dbQuery(...)
- end
- function mysql_num_rows(result)
- assert(result, "Bad argument @ mysql_num_rows")
- local _, numrows = dbPoll(result, -1)
- return numrows
- end
- local results = {}
- function mysql_fetch_assoc(handle)
- assert(handle, "Bad argument @ mysql_fetch_assoc")
- if not results[handle] then
- results[handle] = 0
- end
- results[handle] = results[handle] + 1
- return dbPoll(handle, -1)[results[handle]]
- end
- local function convertToIntegerTable(t)
- assert(t, "Bad argument @ convertToIntegerTable")
- local tempTable = {}
- for row, res in ipairs(t) do
- tempTable[row] = {}
- for _, value in pairs(res) do
- table.insert(tempTable[row], value)
- end
- end
- return tempTable
- end
- function mysql_fetch_row(result)
- assert(result, "Bad argument @ mysql_fetch_row")
- if not results[result] then
- results[result] = 0
- end
- intResult = convertToIntegerTable(dbPoll(result, -1))
- results[result] = results[result] + 1
- return intResult[results[result]]
- end
- function mysql_rows_assoc(result)
- assert(result, "Bad argument @ mysql_rows_assoc")
- return ipairs(dbPoll(result, -1))
- end
- function mysql_rows(result)
- assert(result, "Bad argument @ mysql_rows")
- return ipairs(convertToIntegerTable(dbPoll(result, -1)))
- end
- function mysql_free_result(result)
- assert(result, "Bad argument @ mysql_free_result")
- results[result] = nil
- --notice: http://wiki.multitheftauto.com/wiki/DbFree
- return dbFree(result)
- end
- function mysql_escape_string(_, str)
- return str --automatically by dbQuery
- end
- function mysql_ping()
- return true
- end
- function mysql_insert_id(connection)
- assert(connection, "Bad argument @ mysql_insert_id")
- return dbPoll(dbQuery(connection, "SELECT LAST_INSERT_ID()"), -1)[1][1]
- end
Advertisement
Add Comment
Please, Sign In to add comment