Ghmattimysql: My MySQL Implementation for FiveM [1.3.2]

Just a heads up, I have a copy of the C# dlls that can be used in reference and have been using them a lot with no issues.

Firstly congratulations on the development of this feature. I implemented ghmattimysql on my VRP base.
Updated all VRP code to this format:

db = exports.ghmattimysql

local vRP_get_banned = "SELECT banned FROM vrp_users WHERE id = @user_id"
function vRP.isBanned(user_id, cbr)
	local task = Task(cbr, {false})
	
	db:execute(vRP_get_banned, {user_id = user_id}, function(rows, affected)
		if #rows > 0 then
			task({rows[1].banned})
			else
			task()
		end
	end)
end

All queries with ghmattimysql work without errors. However, randomly ghmattimysql stops querying. No console errors and no errors in the ghmattimysql logs.

I use the latest version of artificial: 1552
OS: Ubuntu 14.04
Mysql: 5.7
ghmattimysql version: 1.2.1

Are there any known errors that stop communication with mysql?

Anyone who has used this in C# asynchronously, would you be able to share your method? I’ve gotten a working version running, but there’s a race condition between the handling of the returned data in the callback and the processing of said data.

I have a problem, I am using vRP Dunko 6.7, and I used GHMattiMySQL C# and it’s a problem with last inserted id ! how can I fix this please help me, I have tried to fix this for days…

I am using vrp too, how did you fix the error when connecting the player ? the insert last id error ? please if you fixed it please help me I am desperate

Correção:

  1. I changed my create user statement, first create users, then ids, then verify id got the identifier entered
INSERT INTO vrp_users(whitelisted,banned) VALUES(false,false); INSERT INTO vrp_user_ids(identifier,user_id) VALUES(@identifier,LAST_INSERT_ID())
  1. I modified this function to bring back the sql return executed above
function vRP.getUserIdByIdentifiers(ids, cbr)
  local task = Task(cbr)

  if ids ~= nil and #ids then
    local i = 0

    -- search identifiers
    local function search()
      i = i+1
      if i <= #ids then
        db:QueryResultAsync(vRP_userid_byidentifier, {identifier = ids[i]}, function(rows, affected)
		  if #rows > 0 then 
            task({rows[1].user_id})
			
          else -- not found
            search()
          end
        end)
      else -- no ids found, create user
	      for l,w in pairs(ids) do
			  if string.find(w, "license") then  -- ignore ip identifier
                identifier_n = w
              end
          end
  
		    db:QueryResultAsync(vRP_create_user, {identifier = identifier_n}, function(rows)
			db:QueryScalarAsync("SELECT user_id FROM vrp_user_ids WHERE identifier = @identifier", {identifier = identifier_n}, function(rows, affected)
				if rows then
					local user_id = rows
					-- add identifiers
					task({user_id})
					--print(user_id)
				else
					task()
				end
			end)
		  end)
      end
    end

    search()
  else
    task()
  end
end

Sometimes the server is laggy. Database functions have a delay when you want to open them. As soon as I restart ghmattiymsql it’s instant gone. Is there perhaps a solution to this?

Hello,

The Ghmattimysql is suported to linux server ? I search for .so archives and i don’t find this files for linux.

Updated to 1.2.2

  • Added a warning for mysql8.
  • Fixed slow queries not displaying properly.
  • Added timestamps to file output
  • Updated dependencies.

Updated to 1.2.3

  • Fix transactions responding with the correct true or false value.
  • Fix transactions blocking the pool.
  • Added the command mysql:debug to toggle debug printing.

Added Documentation with Examples:

https://ghmatti.github.io/ghmattimysql/#

Can I run this together with mysql-async? Or do I have to change my 50+ resources for this?

It uses the same code under the hood, apart from for query transformations.

You shouldn’t run both. While the events are seperate, as ghmattimysql is i think resource-name agnostic, the commands triggered by both implementations are the same.

All queries except selects work for me. it always returns null, both in the result variable and in hud mysql. I am using C #.

thats cuz its async and does not w8 for the result

im not familiar with c# yet, but thats how it worked in my case

        private async void DoesCharacterExist(Player player, int id)
        {
            var query = $"SELECT * FROM characters WHERE id = @id";
            IDictionary<string, int> parameters = new Dictionary<string, int>();
            parameters.Add("id", id);
            Exports["GHMattiMySQL"].QueryResultAsync(query, parameters, new Action<dynamic>(res =>
            {
               /*
               res - is the result of the query
               */
            }));

        }

Updated to 1.3.0

Breaking Changes

  • mysql_debug now takes File , FileAndConsole , Console , and None as parameters.
  • mysql_debug_output ceases to exist.

Features

  • Added the store export to reduce data traffic when calling a lot of queries.

Other

  • Big Refactor and move to Typescript.
  • Logger now should be more descriptive and useful in its descriptions.
  • Logger is more colorful.
  • Blobs are now forced to be returned as an array, as MessagePack has issues with the used ArrayBuffers. Fixes #29
  • Added a testing resource to ensure all functions behave like they should.
1 Like

I am getting this error, I have localhost server with no password, I dont know how to fix this. https://i.imgur.com/KCb1Lh2.png

check ur password on the config file inside the ghmattimysql folder / config.json

Waiting for the next update :smiley: