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

Here is a compiled mysql plugin in Visual C++ 2010
http://dl.dropbox.com/u/36207417/SA-MP/mysql.dll

Anybody know how to send query from mysql_format in R7?
Reply

The 'forward declarations' are missing on a_mysql.inc.

And there are no documentation about the cache and the mutex?
Reply

Dont release so faster BlueG... if you release, release from complete.
Reply

Server: CentOS 5.5 64 Bit
Problem: MySQL Plugin not loading correctly, when used my GameMode goes to Blank and I get some strange error in the log: [18:46:29] Script[gamemodes/GAMEMODE.amx]: Run time error 19: "File or function is not found"
Reply

R7 compiled package (Windows), VS11DP
www.lpupak.com/dl/get/mysql-r7-compiled.zip

Can anyone compile it for Linux?
Reply

Compiled on Ubuntu:

http://dl.dropbox.com/u/32577795/MYS...ormal/mysql.so

and here with Static Librarys

http://dl.dropbox.com/u/32577795/MYS...icLib/mysql.so


It's untested because I will update my GM later..
Reply

First of all, thanks for the update!

I could get it to compile on CentOS, but not without making any changes to the code. I don't know if my changes broke anything or I'm just very stupid, but it definitely compiles now. I was experiencing an error like error: expected primary-expression before ā{ā token. I just prepended pthread_mutex_t to line 14 in source/CMutex.cpp.

And I say again, I'm not an expert of any sort or even anything close to it when it comes to C++, but it did get the code to compile in my environment. And apparently, it works too.

The compiled plugin can be found here: http://sf-se.net/dev/mysql_r7_centos.so (and for anyone who cannot be bothered to read what's above, try this out if you're using linux).

I also tested out some of the code. I have no idea about the cache functions but the function mysql_function_query(connectionHandle, query[], bool:cache, callback[], format[], {Float,_}:...) does have a cache parameter, so go figure what it could do!
What I love the most about the updates, and what I think you guys will love as well is the ability to pass custom parameters to your callback!

pawn Код:
stock some_func()
{
    mysql_function_query(1, "SELECT * FROM players WHERE reg_id = 1", false, "OnPlayerDataReceived", "si", "Hello there!", 9977);
    return 1;
}

forward OnPlayerDataReceived(string[], number);
public OnPlayerDataReceived(string[], number)
{
    printf("OnPlayerDataReceived(%s, %d)", string, number);
    mysql_store_result();
    new row[256];
    mysql_fetch_row(row);
    printf("Result: %s", row);
    return true;
}
This is very nice. If anyone could come up with some usage/help for the cache functions it would be just awesome!
Reply

Compiled on CentOS 6: http://solidfiles.com/d/d141ed71c6/
Reply

Nice!
Reply

Can someone explain me what's the 'format' parameter on mysql_query_function? What does that exactly mean?

I noticed xxmitsu used to deal with threads, but I believe it has to do with even more stuff.

And a question: What does actually define the thread? The callback or the thread ID?
Reply

Stewie, check my post on page 201. It shows a good example on how to use it.

Thanks for the explanations xxmitsu, I'll start using the new plugin version really soon, glad to hear it is stable as well. However what would you list as the benefits from using the cache method?
Reply

Quote:
Originally Posted by AndreT
Посмотреть сообщение
Stewie, check my post on page 201. It shows a good example on how to use it.

Thanks for the explanations xxmitsu, I'll start using the new plugin version really soon, glad to hear it is stable as well. However what would you list as the benefits from using the cache method?
Oh. I think I missed it :P

Thanks. It's is pretty clear now.

Just summing it up, I don't have to mysql_store_result and mysql_free_result any more in any way?
Reply

@andreT

It's a completely threaded plugin, there is no chance you can run a query without threading it.

IF you set the cache parameter to 'true', then anything will be done in the thread: Store result -> fetch row -> free result without needing to call them for yourself.

@stewie : from main post, mysql_format is a native function added in version 6-2

Код:
mysql_format( connectionHandle, output[], format[], {Float,_}:... )
Supported formats: (precisions such as %2.f/%10.s are not supported yet)
- %e (escapes data directly without the need to call mysql_escape_string() before)
- %s (string)
- %d / %i (integer)
- %f (float)

new szDestination[100];
mysql_format(connectionHandle, szDestination, "SELECT * FROM `%s` WHERE `bar` = '%e' AND `foobar` = '%f' LIMIT %d", "foobar", "escape'me\"please", 1.2345, 1337);
// the variable 'szDestination' contains now the formatted query (including the escaped string)
Reply

And how about mutex and catching MySQL Errors?
Reply

Does anyone have a speed test without cache and with cache? :P
Reply

Код:
Please note; R7 works only for threaded scripts!
[/QUOTE]

So, I'm just wondering..

so will this break existing scripts? like

pawn Код:
format(Group_MOTD_str, sizeof(Group_MOTD_str), "SELECT `Name` FROM `Groups` WHERE `id` = %d LIMIT 0,1", index);
    mysql_query(Group_MOTD_str);
    mysql_store_result();
    Group_MOTD_str = "\0";
    mysql_retrieve_row();
    mysql_get_field("GroupName", Group_MOTD_str);
    mysql_free_result();
or

pawn Код:
format(GlobalQuery, sizeof(GlobalQuery), "SELECT `Week` FROM `ServerInfo` LIMIT 0,1");
    mysql_query(GlobalQuery);
    mysql_store_result();
    if(mysql_retrieve_row())
    {
        new data[16];
        mysql_fetch_field_row(data, "Week");
        T_WEEKS = strval(data);
        T_WEEKS = 1;
        printf("[System] - Weeks: %d", T_WEEKS);
    }
    mysql_free_result();
etc
Reply

Uhm, how can I convert my code to use cache?
Код:
[...]

            new
                string[125];

            if (mysql_fetch_row_format(string, "|", connectionHandle))
            {
                new
                    sex[3],
                    integers[10],
                    Float:floats[4];

                sscanf(string, "p<|>{d}ddfddddfffdd{dd}dds[3]",
                integers[0], integers[1], floats[0], integers[2], integers[3],
                integers[4], integers[5], floats[1], floats[2], floats[3],
                integers[6], integers[7], integers[8], integers[9], sex);

                /* Getting data to PVars */
                SetPVarInt(extraid, "mid", integers[0]);
                SetPVarInt(extraid, "aj", integers[1]);
                SetPVarFloat(extraid, "hp", floats[0]);
                SetPVarInt(extraid, "money", integers[2]);
                SetPVarInt(extraid, "bank", integers[3]);
                SetPVarInt(extraid, "score", integers[4]);
                SetPVarInt(extraid, "wanted", integers[5]);
                SetPVarFloat(extraid, "last_x", floats[1]);
                SetPVarFloat(extraid, "last_y", floats[2]);
                SetPVarFloat(extraid, "last_z", floats[3]);
                SetPVarInt(extraid, "last_int", integers[6]);
                SetPVarInt(extraid, "last_vw", integers[7]);
                SetPVarInt(extraid, "skin", integers[8]);
                SetPVarInt(extraid, "last_skin", integers[9]);
                SetPVarInt(extraid, "sex", strval(sex));

[...]
Reply

Quote:
Originally Posted by Kar
Посмотреть сообщение
Код:
Please note; R7 works only for threaded scripts!
So, I'm just wondering..

so will this break existing scripts? like

pawn Код:
format(Group_MOTD_str, sizeof(Group_MOTD_str), "SELECT `Name` FROM `Groups` WHERE `id` = %d LIMIT 0,1", index);
    mysql_query(Group_MOTD_str);
    mysql_store_result();
    Group_MOTD_str = "\0";
    mysql_retrieve_row();
    mysql_get_field("GroupName", Group_MOTD_str);
    mysql_free_result();
or

pawn Код:
format(GlobalQuery, sizeof(GlobalQuery), "SELECT `Week` FROM `ServerInfo` LIMIT 0,1");
    mysql_query(GlobalQuery);
    mysql_store_result();
    if(mysql_retrieve_row())
    {
        new data[16];
        mysql_fetch_field_row(data, "Week");
        T_WEEKS = strval(data);
        T_WEEKS = 1;
        printf("[System] - Weeks: %d", T_WEEKS);
    }
    mysql_free_result();
etc[/QUOTE]

Absolutely, sadly.
Reply

Seriously? Beacause I got errors in every single query in my GM.
Reply

@[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).
Reply


Forum Jump:


Users browsing this thread: 8 Guest(s)