pBlueG / SA-MP-MySQL

MySQL plugin for San Andreas Multiplayer
BSD 3-Clause "New" or "Revised" License
196 stars 80 forks source link

MySQL Format (?) prints its part to the chat #220

Closed samp-pinch closed 5 years ago

samp-pinch commented 5 years ago

I created some "macros" or better said "functions" so I can easly UPDATE data.

And when I do so, I get this in my chat: Image

Here is the code:

sql_update_player_string(playerid, const query[], const value[], q_len = sizeof(query), v_len = sizeof(query)) // This works, ignore it
{
    mysql_format(dbHandler, query, q_len + v_len + 64, "UPDATE `players` SET `%s` = '%s' WHERE id = '%i'", query, value, playerSqlID[playerid]);
    mysql_tquery(dbHandler, query);
}

sql_update_player_int(playerid, const query[], value, q_len = sizeof(query))
{
    mysql_format(dbHandler, query, q_len + 64, "UPDATE `players` SET `%s` = '%d' WHERE id = '%i'", query, value, playerSqlID[playerid]);
    mysql_tquery(dbHandler, query);
}

Here is the mysql.log because other logs are empty (good): https://pastebin.com/nteL2pAf

maddinat0r commented 5 years ago

This is definitely not a plugin issue. You're formatting into a const array, which you passed from somewhere, so you're probably writing into another array that's related to storing chat messages and then sending them.

samp-pinch commented 5 years ago

@maddinat0r problem is that I only got Auth module and I do not even have chat callback or anything like that, just sending messages like Info msg, Error msg...

EDIT: I acutally forgot to say, I edited this inside a_mysql.inc

native mysqltquery(MySQL:handle, query[], const callback[] = "", const format[] = "", {Float,}:...);

to

native mysqltquery(MySQL:handle, const query[], const callback[] = "", const format[] = "",{Float,}:...);

Because I got warning 214, but even without that edit I get msg

EDIT 2: I now hooked SendClientMessage and noticed next:

sql_update_player_int(playerid, "loggedIn", 1);

SendServerMessage(playerid, "You've been last seen at "SERVER"%s"WHITE".", playerLastLogin[playerid]); // Won't be sent
SendServerMessage(playerid, "Welcome back, "SERVER"%s"WHITE".", playerUsername[playerid]); // Will be sent
sql_update_player_int(playerid, "loggedIn", 1);

SendServerMessage(playerid, "Welcome back, "SERVER"%s"WHITE".", playerUsername[playerid]); // Won't be sent
SendServerMessage(playerid, "You've been last seen at "SERVER"%s"WHITE".", playerLastLogin[playerid]); // Will be sent

So anything after mysql query won't be sent?

EDIT 3: I pinpointed problem's "source", mysql_format is causing it, i removed mysql_tquery and I get that... P.S I forgot to say that "normal" query ( new dQuery[100] mysql_format(...), mysql_tquery(...); ) works

EDIT 4:

When I remove query, value, playerSqlID[playerid] from mysql_format, I do not get print but query isn't correct than

ProfessorJTJ commented 5 years ago

Just remove const from everywhere, revert your mysql.inc include changes and do the following to the function. const is a non editable variable, and on the other hand you're formatting an array / variable with a size that it doesn't own.

ex new string[5] = "HELLO WORLD I LOVE YOU"; [ that's what you're doing ]


sql_update_player_string(playerid, const query[], const value[]) // This works, ignore it
{
    new dbQuery[64 + 20 + 64]; // + maximum column name length + maximum value length
    mysql_format(dbHandler, dbQuery, sizeof dbQuery, "UPDATE `players` SET `%s` = '%s' WHERE id = '%i'", query, value, playerSqlID[playerid]);
    mysql_tquery(dbHandler, dbQuery);
}

sql_update_player_int(playerid, const query[], value, q_len = sizeof(query))
{
    new dbQuery[64 + 20 + 10]; // + maximum column name length + maximum value length
    mysql_format(dbHandler, dbQuery, sizeof dbQuery, "UPDATE `players` SET `%s` = '%d' WHERE id = '%i'", query, value, playerSqlID[playerid]);
    mysql_tquery(dbHandler, dbQuery);
}
samp-pinch commented 5 years ago

I. Love. You I thought same about const!