SA-MP Forums Archive
[Plugin] [REL] MySQL Plugin (Now on github!) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Plugin Development (https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: [Plugin] [REL] MySQL Plugin (Now on github!) (/showthread.php?tid=56564)



Re: [REL] MySQL Plugin R5 (04/09/10) - kacperoo - 17.05.2011

What about adding mysql_result_stored()?


Re: [REL] MySQL Plugin R5 (04/09/10) - dud - 18.05.2011

Does anyone run this plugin on CentOS ?


Re: [REL] MySQL Plugin R5 (04/09/10) - __ - 18.05.2011

Yes, I run it on CentOS and it works fine.


Re: [REL] MySQL Plugin R5 (04/09/10) - dud - 18.05.2011

how did you solve this error

Quote:

[21:56:37] Loading plugin: mysql.so
[21:56:37] Failed (libmysqlclient_r.so.15: cannot open shared object file: No such file or directory)




Re: [REL] MySQL Plugin R5 (04/09/10) - dud - 19.05.2011

I think new version got bug

i am using centos and
i start mysql R4 plugin success

but with R5 i still get this error
Quote:
[21:56:37] Loading plugin: mysql.so
[21:56:37] Failed (libmysqlclient_r.so.15: cannot open shared object file: No such file or directory)


Re: [REL] MySQL Plugin R5 (04/09/10) - Miguel - 26.05.2011

A function to convert from the MySQL datetime format to unix time would be cool.


Re: [REL] MySQL Plugin R5 (04/09/10) - Sergei - 26.05.2011

Quote:
Originally Posted by Miguel
Посмотреть сообщение
A function to convert from the MySQL datetime format to unix time would be cool.
http://dev.mysql.com/doc/refman/5.5/...functions.html


Re: [REL] MySQL Plugin R5 (04/09/10) - Miguel - 26.05.2011

Quote:
Originally Posted by Sergei
Посмотреть сообщение
Could you show me an example of the usage of those functions after loading all the fields on a query? Oh wait, you can't, you would have to make a second query...

I want to do something like this:
pawn Код:
mysql_query("SELECT * FROM bans WHERE ip = '90.180.124.10'");
mysql_store_result();
if(mysql_retrieve_row())
{
    ...
    mysql_get_field("field", place_to_store); // Example field.
    ...
    mysql_get_field("unban", unban_date); // 0000-00-00 00:00:00 format.
    unix_integer = ToUnix(unban_date); // From string to integer.
}



Re: [REL] MySQL Plugin R5 (04/09/10) - Sergei - 27.05.2011

I wish people realized that you need to learn SQL language separately. If you know pawn, you know nothing about SQL.

Код:
mysql_query("SELECT *, UNIX_TIMESTAMP(unban) AS intunban FROM bans WHERE ip = '90.180.124.10'");



Re: [REL] MySQL Plugin R5 (04/09/10) - Miguel - 28.05.2011

Quote:
Originally Posted by Sergei
Посмотреть сообщение
I wish people realized that you need to learn SQL language separately. If you know pawn, you know nothing about SQL.

Код:
mysql_query("SELECT *, UNIX_TIMESTAMP(unban) AS intunban FROM bans WHERE ip = '90.180.124.10'");
That's it, thanks!


Re: [REL] MySQL Plugin R5 (04/09/10) - Calgon - 30.05.2011

A more dumbed down explanation of query threading:

Quote:
Originally Posted by Calgon
If you think about the SA-MP dialog system, when you use ShowPlayerDialog() and a player actions the dialog, the callback OnDialogResponse is called with the data that the user entered or selected (via listitem or inputtext).

With MySQL query threading, it's pretty simple - you have two callbacks (OnQueryFinish and OnQueryError) which is called when one of your queries completes, when you create a query with G-StyleZzZ's plugin, you are given the following parameters for executing a query with the mysql_query function:

pawn Код:
mysql_query(query[], resultid, extraid, connectionHandle)
The resultid is what the thread will send back to OnQueryFinish or OnQueryError, every time you execute a query, one of those callbacks are executed. Here's an example of how you'd track a query via its thread:

pawn Код:
#define THREAD_ACCOUNTS 1 // Define 'THREAD_ACCOUNTS' as 1, but you can just use 1, but this way you remember what your query thread IDs are so you don't lose track and declare multiple queries as the same ID

public OnQueryFinish(query[], resultid, extraid, connectionHandle) {
    switch(resultid) { // Personal preference: switch > if, no advantages in PAWN IIRC
        case THREAD_ACCOUNTS: {
            mysql_store_result(); // Store our result so we can access mysql_num_rows()
           
            new
                szMessage[26]; // Create a string so we can format a message
               
            format(szMessage, sizeof(szMessage), "There are %d accounts.", mysql_num_rows());
                    // mysql_num_rows is used to count how many rows the query picks up based on the criteria of your query
            SendClientMessage(extraid, 0, szMessage); // Forward a message to the client
           
            mysql_free_result(); // Free the result from memory because we no longer need it
        }
    }
}

CMD:allaccounts(playerid, params[]) {
        // Remember, syntax: mysql_query(query[], resultid, extraid, connectionHandle)
    mysql_query("SELECT * FROM `accounts`", THREAD_ACCOUNTS, playerid);
    return 1;
}
If you see in the command, I execute the query to retrieve data from every row for `accounts`, with the 'resultid' (thread) of THREAD_ACCOUNTS, then in the OnQueryFinish callback, I use 'extraid' (when I wrote the query line, I included 'playerid' for the 'extraid' parameter so we know what the playerid that should relate to that query, then in the OnQueryFinish callback, I check to see if 'resultid' matches THREAD_ACCOUNTS (1), and if it does then it finishes the job of the command.

Multi-threading is useful because SA-MP is single-threaded, while the MySQL plugin isn't - if you send multiple queries to multiple threads, SA-MP will continue processing and MySQL will process the queries on the other threads, so hence why people claim that multi-threading is more efficient. This is inexplicably useful if you're sending multiple queries to your MySQL server that may be slightly intensive. (like a really long query).

Sorry, I wrote more than I expected.



Re: [REL] MySQL Plugin R5 (04/09/10) - matucha123 - 03.06.2011

I have proble with setting up plugin on CentOS. I get this error:
Код:
 Failed (libmysqlclient_r.so.15: cannot open shared object file: No such file or directory)
I have this file in server catalog but not working... Can someone help?

I saw this tutorial, but i am not allowed

Thanks


Re: [REL] MySQL Plugin R5 (04/09/10) - Burridge - 03.06.2011

matucha123: Your link doesn't work for me, says it doesn't exist. The main post has a link which should fix your issue. Click me!


AW: [REL] MySQL Plugin R5 (04/09/10) - Blowfish - 22.06.2011

Hi,

I just tried to solve my problems on my own and was successful.
(this is the thread where I described them:
http://forum.sa-mp.com/showpost.php?...postcount=1567)

I was not able to compile a fully working version of the plugin because
of the MySQL headers shipped with the source code. Using the ones
shipped with my operating system works perfectly. So I simply changed
line 46 in main.h from
Код:
#include "mysql_include/mysql.h"
to
Код:
#include <mysql/mysql.h>
To make the plugin support fetching multiline strings from the database i needed
to alter CMySQLHandler::FetchField a little bit. My version of it, which, in my opinion
is simpler, more elegant and faster than the original:
Код:
bool CMySQLHandler::FetchField(string column)
{
        if(!m_bIsConnected) {
                NativeFunctions::MySQL_Log("CMySQLHandler::FetchField(%s) - You cannot call this function now. (Reason: Connection is dead)",$
                return 0;
        }
        if(m_stField == NULL || m_stRow == NULL) {
                NativeFunctions::MySQL_Log("CMySQLHandler::FetchField(%s) - You cannot call this function now. (Reason: Fields/Rows are empty$
                return 0;
        }

        for(string::size_type i = 0;i < m_dwFields;i++) {
                if(column.compare(m_stField[i].name) == 0) {
                        m_szResult = (m_stRow[i] ? m_stRow[i] : "NULL");
                        break;
                }
        }

        NativeFunctions::MySQL_Log("CMySQLHandler::FetchField(\"%s\") - %s",column.c_str(),m_szResult.c_str());
        return 1;
}
(this function can be found in source/CMySQLHandler.cpp, line 52 ff)

I hope that I can help someone with this.

Thanks,
Blowfish


Re: [REL] MySQL Plugin R5 (04/09/10) - Steve M. - 26.06.2011

Can I have for example 2 connections? One for one database and another for another database.


Re: [REL] MySQL Plugin R5 (04/09/10) - [NoV]LaZ - 26.06.2011

Quote:
Originally Posted by Steve M.
Посмотреть сообщение
Can I have for example 2 connections? One for one database and another for another database.
Yes.


Re: [REL] MySQL Plugin R5 (04/09/10) - steki. - 26.06.2011

Yes.

mysql_connect returns a connection id and all others funcions uses this id is default to 0.

If you

mysql_query(query, 1), you'll be query'ing the second connection.


Re: [REL] MySQL Plugin R5 (04/09/10) - Calgon - 26.06.2011

Yes, that's why there are connection handles.

EDIT: Crap, didn't see the other posts.


Re: [REL] MySQL Plugin R5 (04/09/10) - Steve M. - 26.06.2011

Okay. Thank you guys.


Re: [REL] MySQL Plugin R5 (04/09/10) - kurta999 - 30.06.2011

The OnQueryFinish for me not work good on Linux.
This freeze my server: ( Not crash, "lagg" )

My Query:
pawn Код:
mysql_query_ex("SELECT cmd, COUNT( cmd ) FROM commands GROUP BY cmd ORDER BY COUNT( cmd ) DESC LIMIT 25", THREAD_QUERY_TOPCMDS, playerid);
OnQueryFinish:

pawn Код:
public OnQueryFinish(sql_query[], resultid, extraid, connectionHandle)
{
    if(extraid != -1)
    {
        switch(resultid)
        {
            case THREAD_QUERY_TOPCMDS:
            {
                new
                    count;
                mysql_store_result();
                while(mysql_fetch_row(line))
                {
                    sscanf(line, "p<|>s[24]d", name, vID);

                    if(!count)
                    {
                        if(strlen(name) < 10)
                        {
                            format(dline, sizeof(dline), "%d. %s: \t\t\t%d", (count +1), name, vID);
                        }
                        else if(strlen(name) >= 10)
                        {
                            format(dline, sizeof(dline), "%d. %s: \t\t%d", (count +1), name, vID);
                        }
                        else if(strlen(name) > 14)
                        {
                            format(dline, sizeof(dline), "%d. %s: \t%d", (count +1), name, vID);
                        }
                        else if(strlen(name) > 20)
                        {
                            format(dline, sizeof(dline), "%d. %s: \t%d", (count +1), name, vID);
                        }
                        else
                        {
                            format(dline, sizeof(dline), "%d. %s: \t%d", (count +1), name, vID);
                        }

                        count++;
                    }
                    else
                    {
                        if(strlen(name) < 10)
                        {
                            format(dline, sizeof(dline), "%s\r\n%d. %s: \t\t\t%d", dline, (count +1), name, vID);
                        }
                        else if(strlen(name) >= 10)
                        {
                            format(dline, sizeof(dline), "%s\r\n%d. %s: \t\t%d", dline, (count +1), name, vID);
                        }
                        else if(strlen(name) > 14)
                        {
                            format(dline, sizeof(dline), "%s\r\n%d. %s: \t%d", dline, (count +1), name, vID);
                        }
                        else if(strlen(name) > 20)
                        {
                            format(dline, sizeof(dline), "%s\r\n%d. %s: %d", dline, (count +1), name, vID);
                        }
                        else
                        {
                            format(dline, sizeof(dline), "%s\r\n%d. %s: \t%d", dline, (count +1), name, vID);
                        }

                        count++;
                    }
                }
                mysql_free_result();

                ShowPlayerDialog(extraid, 5550, DIALOG_STYLE_MSGBOX, "Legtцbbet hasznбlt parancsok..", dline, "Ok", "Mйgse");
            }
        }
    }
    return 1;
}