Ghmattimysql: My MySQL Implementation for FiveM [1.3.2]

https://github.com/GHMatti/FiveM-MySQL/blob/master/MySQLTest/cs/MySQLTest.cs

Should be indicative enough on how to do it. The exports are only the neat wrappers for lua.

There is a compiled library in the release section which you can reference. :smiley:

editted the mainpost to clarify.

1 Like

Thank you! Really helpful now. :smiley:

One more question for you, do functions automatically execute as async or is there a function I dont see for async? None of the functions related to GHMatti.Mysql.Mysql have anything that say async

Edit: I see that you are using a Task function in the example, is that what makes it async?

Using the task functions on different threads makes it async (not really in the truest sense but async for endusers). Just using the task function one the same thread would not make it async (as they are FIFO).

The async calls have the performance issue, due to the IOAwaiter from the CLR, which is in sync with the server thread (which forces it to sleep every call for 40-50ms) ā€“ so just awaiting one async call will create the possibility for it to lag. So to make it async in the simplest case, you put them on different threads, so that they execute independently from each other; so they are async for the server thread. Ideally though I will get them even async on their respective threads, but that requires the use of the Async functions which are due to CLR/FXServer slightly broken.

I can and will try to use the async functions at some point (again), but I fear that many of them are not usable due to them awaiting something where I do not have control over the awaiter; also I will very need to change the FIFO behaviour. The sync functions from the MySqlConnector are themselves just the async functions synchronized.

edit: Alternatively I can rewrite the async functions with my taskscheduler, which should work, but is definately not preferred. On a four core, on default settings it would look like this:

Thread 1|----Query 1----|-------Query 4-------|
Thread 2-|------Query 2------|-------Query 6-------|
Thread 3--|----Query 3----|-----Query 5-----|----Query 7----|
S Thread|---------------1-3--2--------------5-4----6--------7

If you merge that back to the super thread it is async, not perfectly, but as much async as I could get them to be with a very basic class. Also none of them are blocking the server thread, so you can go as crazy as you want.

1 Like

Thank you for this. I just finished putting it in dev, once it goes on the live servers, Iā€™ll be sure to comeback and provide more feedback. I was always noticing some frame lag on the server when we did data syncs using mysql-async

2 Likes

Great work, good release. Once mysql-async starts hanging/timing out at higher player counts they will be running to you :laughing:

3 Likes

Updated

Changes:

  • Updated MySqlConnector to 0.36.1
  • Changed the License to AGPL (if you change something and use it/distribute the end version, share it)
  • Added a Drag and Drop Replacer for mysql-async, which is not recommended to use. ReadMe
2 Likes

Seems OK, but could you create a wrapper for MySQL-Async API compatibility?
It would be much easier for people to start using it for an already existing code.
(I will do it first:D )

Hasnt he already?
20

1 Like

Indeed I have. As @Nick78111 said. Follow the readme. Unless you do some really odd stuff in your code. It replaces it seamlessly or you use the .insert function and do something with the Id returned.

Well, unfortunately, itā€™s impossible to use it as Git submodule, because you use one big repo for multiple projects.

we tend to git clone git@host:repo [category], but thatā€™s of course assuming thereā€™s a resource folder in the root of the output repo.

currently thereā€™s no way to automatically build projects requiring building in the server anyway, and Iā€™m not sure if this repo includes binaries at all (which would be against best practices)

1 Like
  • The main project compiles to the resource folder in the bin folder.
  • Then there is a C# Library, because the server freezes if you link to a BaseScript.dll.
  • A tiny testing example for both Lua and using the C# Library.
  • And the replacement resource.

There is a reason why I linked the releases in the first post on the forums, because that is what end users who do not want to manipulate the code should use in the first place.

The most I would do is to put them on seperate branches, and that requires me to maintain then 3 additional branches, where the C# Library and not the Lua implementation represents the master, logically.

And yes, there will never be binaries in there.

1 Like

Hi @zr0iq

I have a question about returned value. Iā€™m using your script ( and I have seen clearly the difference between yours and mysql-async) and I found something interesting. I have read your post but I didnā€™t find the answer. Iā€™m developing in Lua if youā€™re asking the question. When I use exports['GHMattiMySQL']:QueryScalar on a null value, I have a table with null value in return value. Is this normal ? ( I adapted my code to your implementation to avoid any problems and it works fine)

1 Like

Probably because of some oversight on my end. Time to squash a bug. I replicated that behaviour. Thanks a lot. Shouldnā€™t be longer than 4h needed for the fix to be online.

1 Like

Thanks for the quick answer. Here is a part of my code if someone wants to know :

local result = exports['GHMattiMySQL']:QueryScalar( -- Insert sql, and parameters here)

if (type(result) == "table" and next(result) == nil) then
-- Do something
else
-- Do something
end

Itā€™s an example. I did not code like that, I swear.

It is already fixed. Commiting to Github soon.

Thanks. I hope Iā€™ll find other bugs. Have a nice day.

Updated

Changes

  • Updated the C# Library and GHMattiMySQL resource to fix a bug discovered by @Scyar_Gameur where DBNull instead of null was returned when QueryScalar selected a null cell.

edit: Accidently saved the compiled release as a Draft, which is now fixed.
Update: Changes are bugged. It now crashes if you select nothing. Resource will be updated in the next hour.

Updated

Changes

  • Fixed a bug introduced in the last update/bug fix by forgetting that you cannot get a type of null, thanks @justcfx2u for reporting.

Maybe I shouldnā€™t update this resource when I am suffering from sleep deprivation and write C# like an idiot.