17.05.2011, 18:24
What about adding mysql_result_stored()?
[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) |
A function to convert from the MySQL datetime format to unix time would be cool.
|
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.
}
mysql_query("SELECT *, UNIX_TIMESTAMP(unban) AS intunban FROM bans WHERE ip = '90.180.124.10'");
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 Код:
pawn Код:
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. |
Failed (libmysqlclient_r.so.15: cannot open shared object file: No such file or directory)
#include "mysql_include/mysql.h"
#include <mysql/mysql.h>
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; }
mysql_query_ex("SELECT cmd, COUNT( cmd ) FROM commands GROUP BY cmd ORDER BY COUNT( cmd ) DESC LIMIT 25", THREAD_QUERY_TOPCMDS, playerid);
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;
}