Hi, I want to create a function to execute async SQL queries. However, I have a problem with getting the return values of dbPoll().
Code snippet for better understanding:
function db_query(...)
if (db_settings.db_connection) then
dbQuery(function(query_handle)
local result, num_affected_rows, last_insert_id = dbPoll(query_handle, 0)
return result, num_affected_rows, last_insert_id
end, db_settings.db_connection, ...)
end
end
For example, I want to use this function somewhere else in the script, but of course it will not return the value, because it executes faster than the values are retrieved from the database.
addCommandHandler("reg", function(player, command, ...)
local args = {...}
local result, num_affected_rows, last_insert_id = exports.database_connection:db_query("SELECT * FROM `players`")
outputDebugString(tostring(num_affected_rows))
end)
I tried to use triggerEvent for this, but I don't quite understand how I'm supposed to use it later to get the return values the way I mentioned above. Any help?