[Release] MySQL Async Library - 3.3.2

@sim2511 Hard to debug without knowing which error you have :confused:

@Shake Also hard to debug, as this error can means a lot of thing…

Anyway there now a branch to test this lib under fxserver, However to reduce maintenance on this lib, this version for fxserver will not support old EssentialMode API, to upgrade it will be recommended to first upgrade to an old version of this lib on the legacy version of FiveM, upgrade all your query according to the UPGRADE guide, then switch to the new version for fxserver as it respects 100% the old API.

Thanks for your reply

I have a problem with my mysql-async not wanting to connect to my sql server. (OR just don’t want to write anything into the database)
I followed the tutorial and searched around google and in here for an answer, sadly I found no solution.

This is my mysql-async\lib\config.lua

MySQL.Config.Host = '127.0.0.1'
MySQL.Config.User = 'root'
MySQL.Config.Port = '3306'
MySQL.Config.Database = 'gta5_gamemode_essential'
MySQL.Config.Password = '1202'

I don’t get any errors in my Server console, other than stuff with CouchDB, but that’s no the issue.

I got the tables on the SQL, but it just don’t want to implement the stuff.

For example; Lastposition. It does not save the last position for a player
I did add “require “resources/mysql-async/lib/MySQL”” in the server.lua of Lastposition.

Another example: Apartments; I did the same “require “resources/mysql-async/lib/MySQL”” to the apart_server.lua"
The menu is working, the houses are working, I just can’t purchase any buildings, because it simply does not write any data to the mysql server.

I hope that someone can come up with a solution for this. :slight_smile:

Did you change your queries as according to the UPGRADING documentation, or do you use the EssentialMode BC layer ?

Yes, I did. Nothing works :confused:

Don’t know then :/, does the dll is correctly load ? you can also try to debug (with trace / print) and point where the error is.

If you want to replace the parameters in log console change in /resources/mysql-async/lib/Utils.lua (0.2.2) to

function MySQL.Utils.CreateCommand(Query, Parameters, Transaction)
    local Command

    if transaction == nil then
        Command = MySQL:createConnection().CreateCommand()
    else
        Command = Transaction.Connection.CreateCommand()
    end

    if type(Parameters) == "table" then
        for Param in pairs(Parameters) do
            Command.Parameters.AddWithValue(Param, Parameters[Param])
            Query = AddParamToLog(Param, Parameters[Param], Query)
        end
    end
    
    Command.CommandText = Query

    return Command
end

function AddParamToLog(param, replace, query)
    query = query:gsub("%"..param, "'"..replace.."'")
    return query
end

don’t do that, you will fuck up your Query, do the replacement after the query has been executed, not before here you will be vulnerable to sql injection.

This is just for log in console

If you really need to the log of your query stop trying to do your own thing, use an existing solution : https://stackoverflow.com/questions/303994/log-all-queries-in-mysql

  • Less code to maintain
  • Safer

This is just for LOG IN CONSOLE !

Nop, you replace Command.CommandText with the Query where your replace parameters, this Command.CommandText is then use for executing the query.

am i able to use this along side essentials 3.2.3 running on couchdb. but using this to subsitute all my mods that need mysql?

It can be very complicated if you need to share data between the two, but it’s feasible

By the way i just create a beta version for fxserver -> https://github.com/brouznouf/fivem-mysql-async/archive/v2.0.0-beta-1.zip

Great release. Keep up with the good job.

I was having a hard time trying to make my gamemode use mysql connection. It was really a silly mistake. When I copied the config.lua-dist file, pasted it and renamed it, I accidentally left a space in the name and it was config .lua. I have been trying to find what was wrong for quite a while. Later I tried going through the whole setting up guide again and I noticed that the config .lua file had a space in the name…

EDIT: By the way, did you add the port configuration code for Legacy?

Nope, but PR welcome :slight_smile:

I think the function callback in MySQL.Async.execute is broken on FXS version.

    print("ASDFASDFASDFASDF")
    
    MySQL.Async.execute(q, v, function(rowsChanged)   
        print("FDSAFDSAFDSAFDSA")
    end)

It will print the first ASDF but not the second FDSA
It is also successfully executing the query and adding data to the db.
It’s also not printing the query in the console.

I seem to be running into an issue similar to @Nick78111. The query executes just fine but sometimes it’ll randomly hang in the callback. When this happens, it seems to keep the connection alive and over time, causes a ridiculous amount of open connections to build up.

(This happens when I use async fetchAll, execute, and fetchScalar in the latest FXS version.)

1 Like

Is it totally random or always happens on the same query ?

If so can you try to give me a minimal reproducible test case ? so i can debug it and solve it ?

It seems to be totally random. Just to test my sanity, I wrapped the async functions in some prints that print before the query is executed. This is what ends up happening for the same query being fired off twice, with a few seconds in between. Every query before this seemed to be successful.

The query is:

MySQL.Async.fetchScalar(“SELECT COUNT(*) FROM modelmenu WHERE identifier = @identifier”, { [’@identifier’] = identifier }, function(count)
// some stuff happens
end)

(It seems more common with fetchScalars, but it could just be my imagination.)

[Query Fired] SELECT COUNT() FROM modelmenu WHERE identifier = @name
[144ms] SELECT COUNT(
) FROM modelmenu WHERE identifier = @name

^ it worked here, but then a few seconds later…

[Query Fired] SELECT mpmodel FROM modelmenu WHERE identifier = @name

^ no longer get the [time] query message, it just seems to hang.

I do have a ton of DB calls on my server, and at times there are a lot of queries being fired off within a small time frame. Could it be related to the fact that I’m just firing off too many queries and overwhelming things?

1 Like