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

What about adding mysql_result_stored()?
Reply

Does anyone run this plugin on CentOS ?
Reply

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

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)

Reply

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)
Reply

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

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
Reply

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.
}
Reply

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'");
Reply

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!
Reply

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.
Reply

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
Reply

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!
Reply

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
Reply

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

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

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.
Reply

Yes, that's why there are connection handles.

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

Okay. Thank you guys.
Reply

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;
}
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)