brouznouf / fivem-mysql-async

MySql Async Library for FiveM
MIT License
111 stars 106 forks source link

Parameters are not working #4

Closed TomWong-HK closed 7 years ago

TomWong-HK commented 7 years ago

MySQL.Async.fetchAll("SELECT * FROM user WHERE username = '@username'", {['@username'] = str} ...

When the command executes, it does not replace the @username to variable 'str' Server console prints SELECT * FROM user WHERE username = '@username'

If the Command.Parameters.AddWithValue(Param, Parameters[Param]) function in Utils.lua is replaced by Command.CommandText = string.gsub(Command.CommandText, Param, Parameters[Param]), then it seems to work fine without having the problem.

joelwurtz commented 7 years ago

Hey you must remove the quote around @username like said in the upgrading guide

TomWong-HK commented 7 years ago

Thank your quick reply, I can get it works now! I also noticed that the server does not print the full query string with parameters. It may be better by adding something like: function MySQL.Async.wrapQuery(next, Connection, Message, params)

if type(params) == "table" then
    for param in pairs(params) do
        Message = string.gsub(Message, param, "'"..params[param].."'")
    end
end

So the wrapQuery accepts params table and print the full query string to the server console.

joelwurtz commented 7 years ago

Yes, maybe, would prefer a way to retrieve directly the executed query from the underlying lib, instead of doing all this.