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

Quote:
Originally Posted by Vince
Посмотреть сообщение
How would I go about handling transactions? I have one instance where I need, or rather want to perform inserts in a loop. Do I simply execute Start->queries->Commit?
I think you can only do this with unthreaded queries because otherwise you can't make sure in which order the queries get executed.

I haven't tested it myself but following should be theoretically possible.
pawn Код:
Transaction()
{
    mysql_query(HWND, "START TRANSACTION;", false);
   
    for(new i = 0; i < SOMETHING; ++i)
    {
        mysql_query(HWND, "SOME UPDATE QUERY", false);
    }
   
    mysql_query(HWND, "COMMIT;", false);
}
But unless you don't need a feature like ROLLBACK or something you should stay with common threaded queries.
Reply

Quote:
Originally Posted by Vince
Посмотреть сообщение
How would I go about handling transactions? I have one instance where I need, or rather want to perform inserts in a loop. Do I simply execute Start->queries->Commit?
Yes, that's pretty much it.
Код:
mysql_tquery(SQL, "START TRANSACTION");
for(new i=0; i < 100; ++i)
    mysql_tquery(SQL, "INSERT INTO foobar (foo) VALUES ('bar')");
mysql_tquery(SQL, "COMMIT");
Quote:
Originally Posted by Mellnik
Посмотреть сообщение
I think you can only do this with unthreaded queries because otherwise you can't make sure in which order the queries get executed.
[...]
But unless you don't need a feature like ROLLBACK or something you should stay with common threaded queries.
You can use transactions with 'mysql_query' and 'mysql_tquery', but not with 'mysql_pquery'. Only 'mysql_pquery' can execute queries in a different order.

Transactions are also good for speed optimizations, because they skip some internal query operations within the MySQL server (table locking and re-indexing I think).
Reply

Should I declare the threaded function if I don't use it at all? For instance, I want to update a table and I use this query:
pawn Код:
format(E_STRING[szVehicleUpdateString], sizeof E_STRING[szVehicleUpdateString], "UPDATE vehicles SET pos_x=%f, pos_y=%f, pos_z=%f, pos_a=%f, color1=%d, color2=%d, owner='%s', mileage=%f, gas=%d, locked=%d, vworld=%d, interior=%d WHERE plate='%s'",
            E_VEHICLE[data_saveid][vPosition][0], E_VEHICLE[data_saveid][vPosition][1], E_VEHICLE[data_saveid][vPosition][2], E_VEHICLE[data_saveid][vPosition][3], E_VEHICLE[data_saveid][vColors][0], E_VEHICLE[data_saveid][vColors][1], E_VEHICLE[data_saveid][vOwner], E_VEHICLE[data_saveid][vMileage],
            E_VEHICLE[data_saveid][vGas], E_VEHICLE[data_saveid][vLocked], E_VEHICLE[data_saveid][vVirtualWorld], E_VEHICLE[data_saveid][vInterior], E_VEHICLE[data_saveid][vPlate]);
            mysql_tquery(dbHandle, E_STRING[szVehicleUpdateString], "OnVehicleDataSave", "");
Reply

Quote:
Originally Posted by fordawinzz
Посмотреть сообщение
Should I declare the threaded function if I don't use it at all? For instance, I want to update a table and I use this query:
pawn Код:
format(E_STRING[szVehicleUpdateString], sizeof E_STRING[szVehicleUpdateString], "UPDATE vehicles SET pos_x=%f, pos_y=%f, pos_z=%f, pos_a=%f, color1=%d, color2=%d, owner='%s', mileage=%f, gas=%d, locked=%d, vworld=%d, interior=%d WHERE plate='%s'",
            E_VEHICLE[data_saveid][vPosition][0], E_VEHICLE[data_saveid][vPosition][1], E_VEHICLE[data_saveid][vPosition][2], E_VEHICLE[data_saveid][vPosition][3], E_VEHICLE[data_saveid][vColors][0], E_VEHICLE[data_saveid][vColors][1], E_VEHICLE[data_saveid][vOwner], E_VEHICLE[data_saveid][vMileage],
            E_VEHICLE[data_saveid][vGas], E_VEHICLE[data_saveid][vLocked], E_VEHICLE[data_saveid][vVirtualWorld], E_VEHICLE[data_saveid][vInterior], E_VEHICLE[data_saveid][vPlate]);
            mysql_tquery(dbHandle, E_STRING[szVehicleUpdateString], "OnVehicleDataSave", "");
You can just use
Код:
mysql_tquery(dbHandle, E_STRING[szVehicleUpdateString]);
This will only send the UPDATE query and don't call any public function (since you don't specified one).
Reply

Thanks for your work on this plugin maddinat0r, I understand it much more clearly now and fully appreciate the hard work you've put in since you started to work on it. BlueG of course too.
Reply

Hi, can I use mysql_query and mysql_function_query at one script? I have some code what need to be done with mysql_query to dont mess, but 95% of gamemode I converted to threaded mysql_function_query. Is it gonna work? I remember when I use on R6 threaded+non-threaded in script on one time it crashed gamemode, is it fixed?
Reply

Quote:
Originally Posted by ToFFiK
Посмотреть сообщение
Hi, can I use mysql_query and mysql_function_query at one script? I have some code what need to be done with mysql_query to dont mess, but 95% of gamemode I converted to threaded mysql_function_query. Is it gonna work? I remember when I use on R6 threaded+non-threaded in script on one time it crashed gamemode, is it fixed?
Well, there is a difference between R6 and R38. Like, 2.5 years and 23 other versions (revisions). So it's very likely that it works fine now.
There is (technically) no mysql_function_query anymore, the equivalent is "mysql_tquery". You can also use unthreaded queries with "mysql_query". Take a look at the wiki for more information.
Reply

Hello, mysql plugins do not load it with the tutorial : https://sampforum.blast.hk/showthread.php?tid=485633 Do you know what the problem is?
Reply

https://sampforum.blast.hk/showthread.php?pid=2979564#pid2979564
Reply

Hello,

I have a big problem. My Mysql plugin is no load now.
I have BlueG R38 mysql plugin(this no load), crashdetect 4.13.1, streamer 2.7.1, Whirlpool and sscanf 2.8.1, and console say: "mysql plugin load filed'
What's problem?

Sorry for my bad english, I don't use translators.
Reply

Which operating system you use for your server?
Give us that message from the console.
Reply

Server is in my localhost, win7 64bit. and this is message:

"mysql plugin load:
failed"
Reply

Do you have "libmysql.dll" in your server folder?
Reply

Yes it is important.
Reply

Hey,

iґve got a problem with the plugin. Since yesterday, after i changed the root-server time and did some updating.
The static version got the error: Can't connect to local MySQL server through socket '/tmp/mysql.sock'
After i created a symbolic link via: ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock'
Mysql is working, but the gamemode changed to "unknown". Does anybody got a solution for this problem?

Greetings
Blue
Reply

I think it's because you have as host (in mysql_connect) "localhost". Change to "127.0.0.1".
Reply

For some reason this keeps happening:
pawn Код:
mysql_debug(1);
Код:
warning 206: redundant test: constant expression is non-zero
warning 215: expression has no effect
Reply

mysql_debug function was for older version and it had as parameter 0 (disable)/1 (enable).

To the latest version, the function mysql_log is used and that will work:
pawn Код:
mysql_log(LOG_ALL);
EDIT: You edited your post, you had: mysql_debug(LOG_ALL);

Anyways I forgot to mention that you didn't say the version you use.
Reply

Well, I don't know why, but I got a really huge cpu usage of 45% with samp03svr & mysqld. Anyone with the same problems?
Reply

solved.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)