[Release] MySQL Async Library - 3.3.2

Can we return a value getted from Async ? (FXServer)

Ex :

function getPlayerMoney(player)
  MySQL.Async.fetchAll("SELECT money FROM users WHERE identifier = @identifier", { ['@identifier'] = player }, function(result)
    return result[1].money
  end)
end

Can we escape from the async callback and keep the value ?

Async on FxServer make my server crash randomly :
https://pastebin.com/Zib2hdwr
look at :
SELECT banned FROM user_ipblacklist WHERE ip = @ip AND banned = 17fd3e11b4000-7fd3e23b5000 rwxp 00000000 00:00 0
Can you fix this bug please ? :confused:
Thanx

You need to use callbacks.

function gotMoneyExample()
  getPlayerMoney(player, function(result)
     local moneyFromDB = result
     -- Do whatever else you need with the result here, or send the result to a global variable instead.
  end)
end
function getPlayerMoney(player, callback)
  MySQL.Async.fetchAll("SELECT money FROM users WHERE identifier = @identifier", { ['@identifier'] = player }, function(result)
    callback(result[1].money)
  end)
end
1 Like

Okok perfect, i just wait the async fix now, thank you very much :slight_smile:

HELP ME PLEASE I installed the EssentialMode base The server is hosted not on localhost
.
But now I have other problems
When I put /admin gives me an error: https://gyazo.com/aedcbd5380292b7897169415bcdf170e

And I have installed an EMS MOD that works with Essential Mode and Skin customization.
But when I boot the server I get error: https://gyazo.com/820fe64d6e1123f29b4752284d12feff

And I do not know which route to put, I have tried quite a few and none of them work.
(require “resources/essentialmode/lib/MySQL”) https://gyazo.com/745ff03d9467f35abbdfe562dde86446

1 Like

Hello @Brouznouf,

Can you or how can we implement custom port configurations into this?
Thanks

Simply add it the the mysql connection string ?

I have done some tests, the more you have of “SELECT” queries executed, the more your server risk of crash, if you put a request “SELECT” to check if the person is banned when it connect, That your crash server frequently.
(I Have the last version and is same on the old version)

Which test ? We have select for the ban thing, and we got 48h uptime without crash easily. Please stop staying thing without proof / evidence / reproduction scenario, with this i just can say : Mokay ? But cannot done anything neither helping you, if this is really a failure.

Sorry I do not want to look nasty but it’s true, my server is full everytime 32/32, i can make tests properly, without checking ban, the server crash two three times a day, with the script for checking ban, the server crash two three times per hour !
This is my script for checking ban : https://pastebin.com/3briTQAg I don’t see something wrong in my script …

Sure but maybe it’s :

  • os.time
  • Serialization process between mysql and your lib (exports)
  • Memory leaking for using mono dll
  • Global loop of the server
  • Race condition in your code
  • …

There is a ton of possibility…

Development is a science, use science reasonment to make a fact, not guess based on intution which is often wrong.

Hmmm… Yeah but no, If I get ALL bans at the server start with “onMySQLReady” and put them in table (https://pastebin.com/b2GLVyM2 if someone want), the server don’t crash, he crash everytime only when I use SELECT for every connection to the server.

Can someone help me? I am getting this error

Error running system event handling function for resource banscript: citizen:/scripting/lua/scheduler.lua:39: Failed to
execute thread: sv_ban.lua:13: attempt to call a nil value (field 'getUserRankQuery')
stack traceback:
        sv_ban.lua:13: in function 'getPlayerRank'
        sv_ban.lua:7: in upvalue 'handler'
        citizen:/scripting/lua/scheduler.lua:124: in function <citizen:/scripting/lua/scheduler.lua:123>
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/scheduler.lua:39: in field 'CreateThreadNow'
        citizen:/scripting/lua/scheduler.lua:123: in function <citizen:/scripting/lua/scheduler.lua:92>

with this code

local db = {}

AddEventHandler("chatMessage", function(source, name, message)
	local cm = stringsplit(message, " " , " ")

	if cm[1] == "/test" then
		getPlayerRank(source)
	end
end)

--[[ Main Functions ]]--
function getPlayerRank(id)
	db.getUserRankQuery(id, function(result)
		print(#result)
	end)
end
--]]


--[[ MySQL Callbacks ]]--
AddEventHandler("onMySQLReady", function()

db.getUserRankQuery = function(id, callback)
	local ident = GetPlayerIdentifiers(id)[1]
	MySQL.Async.fetchAll("SELECT * FROM admins WHERE identifer = @ident", {['@ident']=ident}, function(result)
		callback(result)
	end)
end

db.getUserBanQuery = function(id, callback)
	local ident = GetPlayerIdentifiers(id)[1]
	MySQL.Async.fetchAll("SELECT * FROM bans WHERE identifier = @ident", {['@ident']=ident}, function(result)
		callback(result[1])
	end)
end

end)

I apologize if I did something wrong I just have never used mysql-async before.

Hi
When launching my server, to try the example.lua script in the mysql-async folder, I get this error

Started resource fivem-map-skater
Started map fivem-map-skater
Loaded MySqlConnector, Version=0.24.0.0, Culture=neutral, PublicKeyToken=null into ScriptDomain_848326817
Loaded System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 into ScriptDomain_848326817
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT @parameters {@parameters=1}": Unable to connect to any of the specified MySQL hosts.

[ERROR] [mysql-async] An error happens on MySQL for query "SELECT @parameters {@parameters=string}": Unable to connect to any of the specified MySQL hosts.

[ERROR] [mysql-async] An error happens on MySQL for query "SELECT "hello1" as world {=}": Unable to connect to any of the specified MySQL hosts.
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT SLEEP(4) {=}": Unable to connect to any of the specified MySQL hosts.
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT SLEEP(1) {=}": Unable to connect to any of the specified MySQL hosts.
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT SLEEP(2) {=}": Unable to connect to any of the specified MySQL hosts.
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT SLEEP(5) {=}": Unable to connect to any of the specified MySQL hosts.
Error running system event handling function for resource mysql-async: citizen:/scripting/lua/scheduler.lua:39: Failed to execute thread: example.lua:59: attempt to index a nil value
stack traceback:
        example.lua:59: in upvalue 'handler'
        citizen:/scripting/lua/scheduler.lua:124: in function <citizen:/scripting/lua/scheduler.lua:123>
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/scheduler.lua:39: in field 'CreateThreadNow'
        citizen:/scripting/lua/scheduler.lua:123: in function <citizen:/scripting/lua/scheduler.lua:92>
        [C]: in function 'coroutine.resume'
        citizen:/scripting/lua/scheduler.lua:33: in field 'CreateThreadNow'
        citizen:/scripting/lua/scheduler.lua:123: in function <citizen:/scripting/lua/scheduler.lua:92>
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT NOW() as world {=}": Unable to connect to any of the specified MySQL hosts.
[ERROR] [mysql-async] An error happens on MySQL for query "SELECT SLEEP(3) {=}": Unable to connect to any of the specified MySQL hosts.
hitch warning: frame time of 4701 milliseconds

Anyidea why ?
Thanks !

I have this error someone have the solution ?

Anyone answer you or did you figure it out? I’m in the same boat here

@xander1998 There was a bug in old versions of mysql async it should be resolved on master will do a version in some hours / minutes

@Quentins The error tell it all, connection is impossible : check the host / username / password that you entered in the mysql_connect_string setting

@mandra Not related to mysql, it just say that a Native don’t work :confused:

2.0.0 released read the changelog in the top post

1 Like

great thanks you very much

Hi since we need to use “MySQL.ready”, scripts in this function doesn’t execute anymore :confused:
EDIT : I have found the problem: Citizen.CreateThread Doesn't work serverside