[Plugin] [REL] MySQL Plugin (Now on github!)

Is it safe to use the R7 on a live server?
Reply

Try enabling cache and removing the store/free and use cache_get_data to get the number of rows/fields.
Reply

That's what I did last night. At one point I had ~5 queries using the caching method and all others weren't. I made all queries use caching (and looping through cached results is actually a lot faster than calling mysql_fetch_row in a loop), but the issue still persisted.

I saw xxmitsu having the issue a month ago. He solved it by not using floating point numbers, but from what I've seen around, that should not be an issue at all. Having "2" instead of "2.0" will just make the compiler generate a slightly bigger .amx with a call to a function which makes it into a floating point number (please do correct if I'm mistaken).

Currently I'm trying it out on Windows with this build. However since I can recall some differences between different VS builds, I'll be trying another version out soon and then will report back.
Reply

mysql_ping crashing the server at OnGameModeInit. I removed the function and worked fine:

Код:
[16:00:42] [debug] Server crashed while executing mode_r7.amx
[16:00:42] [debug] Backtrace (most recent call first):
[16:00:42] [debug] #0  native mysql_ping() from mysql.dll
[16:00:42] [debug] #1  public Server_DatabaseConnect()+0x210 at mode_r7.pwn:369
[16:00:42] [debug] #2  public zcmd_OnGameModeInit()+0xb8 at mode_r7.pwn:88 
[16:00:42] [debug] #3  native CallLocalFunction() from samp-server.exe
[16:00:42] [debug] #4  public Server_DatabaseConnect()+0x210 at mode_r7.pwn:369
[16:00:42] [debug] #5  public zcmd_OnGameModeInit()+0xb8 at mode_r7.pwn:88
pawn Код:
//printf("Conexгo com a database realizada com sucesso!\nPing: %d", mysql_ping(MYSQL_GAME_CONNECTION));
Reply

I'm having alot of troube on 'Heap Overflow's.

When the first player logs in, it's alright. But when the second comes in, all the shit begins to happen:


ALL public functions called get reported, by the crashdetect plugin.

As the bugs start to happen when someone logs in, Imma post my code:
pawn Код:
public OnPlayerConnect(playerid)
{
    SetPlayerCameraPos(playerid, -2321.0840, 1322.4452, 62.1136);
    SetPlayerCameraLookAt(playerid, -2322.0059, 1322.8374, 61.9684);

    Player_SetTextDraws(playerid);

    GetPlayerName(playerid, query, MAX_PLAYER_NAME);
    mysql_real_escape_string(query, gPlayerInfo[playerid][gPlayerName], MYSQL_GAME_CONNECTION);

    Player_SetStatusLabel(playerid, "Checando a Existencia da conta...");
    Player_CheckIfExists(playerid);

    GetPlayerIp(playerid, gPlayerInfo[playerid][gPlayerIP], 16);
    rdns(gPlayerInfo[playerid][gPlayerIP], playerid);

    TextDrawShowForPlayer(playerid, TD_SERVER_LOGO);

    Player_SetStatusLabel(playerid, "Checando a Existencia da conta...");
    Player_CheckIfExists(playerid);

    return 1;
}
pawn Код:
public Player_CheckIfExists(playerid)
{
    mysql_format(MYSQL_GAME_CONNECTION, query, "SELECT * FROM `game_player` WHERE `name`='%s'", gPlayerInfo[playerid][gPlayerName]);
    mysql_function_query(MYSQL_GAME_CONNECTION, query, true, "r@Player_CheckIfExists", "i", playerid);
    return 1;
}
public r@Player_CheckIfExists(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields);

    if(rows)
    {
        Player_SetStatusLabel(playerid, "Conta existente, digite a senha para prosseguir.");
        gPlayerInfo[playerid][gPlayerStat] = PLAYER_STAT_LOGGING;
        gPlayerInfo[playerid][gPlayerLoginTries] = 0;
        format(query, 128, "Bem-vindo de volta, %s!\n\nInsira sua senha no campo a seguir para logar em sua conta.", gPlayerInfo[playerid][gPlayerName]);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Bem-vindo ao " C_SERVERNAME, query, "Entrar", "Cancelar");

        return 1;
    }

    Player_SetStatusLabel(playerid, "Registro:");
    SendClientMessage(playerid, -1, "Prossiga com o registro para continuar:");

    return 1;
}
Reply

Quote:
Originally Posted by xxmitsu
Посмотреть сообщение
@[Diablo] you can still fetch the data in the PAWN thread with mysql_retrieve_row() and such(you will have to set the cache variable to false then).

But, there is still a backward compatibility define
pawn Код:
#define mysql_query(%1, %2, %3, %4) \
    mysql_function_query(%4, %1, false, "OnQueryFinish", "siii", %1, %2, %3, %4)
which should make your code work as before.

@Stewie` as Sergei said and as I said above, if you had used the threded model before, the above define should do the job.. unless you're using one of the removed functions like:
pawn Код:
mysql_fetch_int()
mysql_fetch_float()
then, you'll have to find some workaround(it shouldn't be a hard job).
The mysql_query define doesn't work for some reason.

I clearly see the define in the include.. but yet it keeps returning undefined. I even put it in my gm and that happened. I seriously have no idea why

pawn Код:
(7029) : error 017: undefined symbol "mysql_query"
on every mysql_query, YES THE INCLUDE FILE IS INCLUDED AND THE DEFINE IS THERE.

EDIT:

I just this this,

pawn Код:
#if defined mysql_query
    #error mysql_query is defined
#endif

Result:

15) : fatal error 111: user error: mysql_query is defined
something is weird..
Reply

I think you should delete the spaces in a_mysql.inc, like this:
Код:
#define mysql_query(%1,%2,%3,%4) \
	mysql_function_query(%4, %1, false, "OnQueryFinish", "siii", %1, %2, %3, %4)
Even then, it might expect you to actually give it 4 parameters. This is often ignored in code for previous plugin versions, since connectionHandle defaults to 1 since the beginning!

And to be completely honest, I don't think you should stick to the old method of having an OnQueryFinish callback. I find the cache method very convenient to use. Besides, you don't even need 4 parameters to be passed to the callback most of the time, but having the ability to pass more parameters using the 5th+ parameter is great.
Reply

@Stewie

I was experiencing this issue before (and god I hope it won't reappear), but it either magically fixed itself or me recompiling the plugin in VS10 had its effects. I also disabled optimization in the project compile settings to see if that will provide any more information in the logs (don't laugh, guys!).

If you are using Windows, try this build.

Edit
I'm sorry for the double posting! Woops!

Also, just wanted to mention, that I seriously hope that someone smart enough to deal with this issue will step in and give us information about the runtime error. I just somehow got rid of it.
Reply

DUDE. IT WORKED FINE. DAMN.

Well. That's good. Some guy's compilation I downloaded was really bugged. You kinda saved my life, dude. Now I have to delete all my debug notes.

I love you lol.

It turns out, when you convert the solution file from VC '08 to VC '10, probably the plugin fucks up the hooking method, calling public function, or whatever.
Reply

Quote:
Originally Posted by AndreT
Посмотреть сообщение
I think you should delete the spaces in a_mysql.inc, like this:
Код:
#define mysql_query(%1,%2,%3,%4) \
	mysql_function_query(%4, %1, false, "OnQueryFinish", "siii", %1, %2, %3, %4)
Even then, it might expect you to actually give it 4 parameters. This is often ignored in code for previous plugin versions, since connectionHandle defaults to 1 since the beginning!

And to be completely honest, I don't think you should stick to the old method of having an OnQueryFinish callback. I find the cache method very convenient to use. Besides, you don't even need 4 parameters to be passed to the callback most of the time, but having the ability to pass more parameters using the 5th+ parameter is great.
Thanks, it's fixed all I wanted was for the script to compile so I could find some errors !
Reply

I recently switched to threaded queries (only big like login or registration).

My server crashed 4 times today. It just freezes. I can see players and ping, but can't join.
I noticed that server losing the connection with database many times and only for threaded queries.

Someone had this problem? How to fix that?


I'm using R6-2 on CentOS 6 32bit.
Reply

Using threaded and unthreaded queries simultaneously is unstable! That might be either due to this in R6-2 or some deeper problem! For the record I battled these issues for over a month back in the day. My solution: thread all queries.
Reply

pawn Код:
[12/02/2012 18:23:00] [debug] [Sacnr.amx]: During execution of IRC_OnReceiveRaw():
[12/02/2012 18:23:00] [debug] [Sacnr.amx]: Run time error 8: "Heap underflow"
[12/02/2012 18:23:00] [debug] [Sacnr.amx]:   Heap index (HEA) is 0xBDE, heap bottom (HLW) is 0x2B5BB0
[12/02/2012 18:23:00] [debug] [Sacnr.amx]: Call stack (most recent call first):
[12/02/2012 18:23:00] [debug] The server has crashed executing 'Sacnr.amx'
[12/02/2012 18:23:00] [debug] [Sacnr.amx]: Call stack (most recent call first):
NVM, just read, @AndreT thanks for the dll.
Reply

Anyone can help me,
How can I transform this query to R7 query?
pawn Код:
mysql_query("SELECT MAX(buSQLID) FROM Buildings");
    mysql_store_result();
    new SQL[20];
    mysql_fetch_row_format(SQL, "|");
        new sqlid = strval(SQL);
Reply

Quote:
Originally Posted by Stewie`
Посмотреть сообщение
Try this build: http://sf-se.net/dev/mysql_r7_win.dll

Credits to AndreT.
server crashes on mysql_fetch_field_row after a few of them..
Reply

Is R7 stable for using?
Reply

Quote:
Originally Posted by BrandyPenguin
Посмотреть сообщение
Is R7 stable for using?
HERE ISNT.
Reply

Quote:
Originally Posted by Kar
Посмотреть сообщение
server crashes on mysql_fetch_field_row after a few of them..
You should consider rewriting your code. In my opinion, mysql_fetch_field_row is a terrible way to fetch data. Better of fetching the whole row and using sscanf to assign the values to the appropriate variables.
Reply

Quote:
Originally Posted by AndreT
Посмотреть сообщение
Simply setting the cache to true in mysql_function_query won't do the trick, you need to use the cache functions in the returning callback as well.

cache_get_data returns stores the amount of rows and fields in the given parameters. This is useful for checking validity of what a SELECT query outputs and looping through the results as well.
cache_get_row stores the field data in the destination string. It is as simple as that:
pawn Код:
// Example query: SELECT name,kills FROM players WHERE id = %d LIMIT 0,1
new rows, fields;
cache_get_data(rows, fields);
if(rows)
{
    new PlayerName[MAX_PLAYER_NAME], kills, storage[12];
    cache_get_row(0, 0, PlayerName);
    cache_get_row(0, 1, storage), kills = strval(storage);
    printf("Player %s has %d kills!", PlayerName, kills);
}
I haven't tested cache_get_field, but according to the source, it is supposed to return the name of the given field.
There's also cache_get_field_content which will get the data by the field's name, for example:
pawn Код:
cache_get_field_content(0, "name", PlayerName);
cache_get_field_content(0, "kills", storage), kills = strval(storage);
I have avoided using this function for the same reason people avoid mysql_fetch_field_row. It loops through the cached array of field names and compares the strings, but in case of cached results, the difference won't of course be as bad as for mysql_fetch_row_format and mysql_fetch_field_row (although the functions are not designed to do the same thing, one is just faster to use when it comes to a large number of fields).

I have a house loading/parsing function which runs on startup only. When using the regular method (store the result, put mysql_fetch_row_format in a loop, etc), it took around 2.5 seconds to execute. I converted that function to use the cache method and the differences are slightly astonishing!

For the sake of it, I searched them out in my outbox (sent to xxmitsu previously), and for the old method, all mysql_fetch_row calls took ~3000ms, sscanf parsing took ~30ms and other parts of code in the loop ~130ms. After converting, the whole execution time is ~300ms, cache functions take around 160ms of it. I didn't run very many tests, but when starting the server up on Windows, I can clearly tell that the gain in startup is literally seconds!
That's some nice experience.

Anyway, is anyone using the latest version in a LIVE server?
Reply

hi,

What's the difference between threaded and unthreaded (query)? I don't understand this word (bad english)

thx.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)