Re: [REL] SA:MP MySQL Plugin 1.0.2 -
On_Top_Non_Stop - 27.01.2010
Noticed this. It takes at least a second to log a player in with just password, name and cash.
Re: [REL] SA:MP MySQL Plugin 1.0.2 -
V_FoR_VendettA - 27.01.2010
Great job strickenkid, this was exactly what i was looking for ^^
Re: [REL] SA:MP MySQL Plugin 1.0.2 -
MenaceX^ - 27.01.2010
Quote:
Originally Posted by OnTop2K9
Noticed this. It takes at least a second to log a player in with just password, name and cash.
|
I'll try with many values.
Re: [REL] SA:MP MySQL Plugin 1.0.2 -
StrickenKid - 28.01.2010
Quote:
Originally Posted by OnTop2K9
Noticed this. It takes at least a second to log a player in with just password, name and cash.
|
What method are you using? Post your login code.
Re: [REL] SA:MP MySQL Plugin 1.0.2 -
On_Top_Non_Stop - 28.01.2010
pawn Код:
stock LoadPlayer(playerid)
{
format(string,sizeof(string),"SELECT * FROM players WHERE playerid=%d",pInfo[playerid][pSQLId]);
query(string);
mysql_store_result();
if(mysql_num_rows()>0)
{
new field[5][80], data[256];
if (mysql_fetch_row(data, "|"))
{
split(data, field, '|');
pInfo[playerid][pCash] = strval(field[3]);
}
GivePlayerMoney(playerid,pInfo[playerid][pCash]);
}
mysql_free_result();
return 1;
}
Re: [REL] SA:MP MySQL Plugin 1.0.2 -
MenaceX^ - 28.01.2010
Quote:
Originally Posted by OnTop2K9
pawn Код:
stock LoadPlayer(playerid) { format(string,sizeof(string),"SELECT * FROM players WHERE playerid=%d",pInfo[playerid][pSQLId]); query(string); mysql_store_result(); if(mysql_num_rows()>0) { new field[5][80], data[256]; if (mysql_fetch_row(data, "|")) { split(data, field, '|'); pInfo[playerid][pCash] = strval(field[3]); } GivePlayerMoney(playerid,pInfo[playerid][pCash]); } mysql_free_result(); return 1; }
|
The real code is working with sscanf, does it have the same speed with sscanf?
Re: [REL] SA:MP MySQL Plugin 1.0.2 -
StrickenKid - 28.01.2010
post your query() function as it may be that.
Re: [REL] SA:MP MySQL Plugin 1.0.2 -
MenaceX^ - 29.01.2010
It's my function
pawn Код:
stock query(query[])
{
if(mysql_ping()!=0)
{
if(mysql_connect(SQL_HOST,SQL_USER,SQL_DB,SQL_PASS))
{
print("MySQL has successfully reconnected due to ping time out.");
mysql_query(query);
printf(query);
}
else
print("MySQL has failed to reconnect (due to time out).");
}
else
{
mysql_query(query);
printf(query);
}
}
But now I reailised that there's no need to use this query because if you set the auto_login in mysql_connect to 1, it'll just reconnect as it loses the connection.
Re: [REL] SA:MP MySQL Plugin 1.0.2 -
Cr0ssFir3 - 29.01.2010
Using the new update (1.0.2) no errors until now, all just working fine.
Re: [REL] SA:MP MySQL Plugin 1.0.2 -
Eazy_Efolife - 30.01.2010
Код:
stock SaveGroups()
{
new groupid;
mysql_real_escape_string(GroupInfo[groupid][gName], GroupInfo[groupid][gName]);
mysql_real_escape_string(GroupInfo[groupid][gOwner], GroupInfo[groupid][gOwner]);
mysql_query("SELECT * FROM `Groups`");
mysql_store_result();
if(mysql_num_rows() > 0)
{
while(mysql_fetch_row(array, "|"))
{
format(string, sizeof(string), "UPDATE `Groups` SET gMembers=%d, gPrivate=%d", GroupInfo[groupid][gMembers], GroupInfo[groupid][gPrivate]);
mysql_query(string);
strmid(GroupInfo[groupid][gName], GroupInfo[groupid][gName], 0, strlen(GroupInfo[groupid][gName]), 255);
strmid(GroupInfo[groupid][gOwner], GroupInfo[groupid][gOwner], 0, strlen(GroupInfo[groupid][gOwner]), 255);
strmid(GroupInfo[groupid][gPassword], GroupInfo[groupid][gPassword], 0, strlen(GroupInfo[groupid][gPassword]), 255);
}
}
mysql_free_result();
}
Everytime I run this function I get this:
[23:29:47] MySQL Error: 'mysql_fetch_row' called when no result stored. But I stored the result =/
Re: [REL] SA:MP MySQL Plugin 1.1 -
StrickenKid - 01.02.2010
Updated to version 1.1!
See original post for details!
Re: [REL] SA:MP MySQL Plugin 1.1 -
MenaceX^ - 01.02.2010
Awesome update!
Re: [REL] SA:MP MySQL Plugin 1.1 -
actiwe - 01.02.2010
Great, now we can compare G-Stylezz and this plug .
Re: [REL] SA:MP MySQL Plugin 1.1 -
MenaceX^ - 01.02.2010
Quote:
Originally Posted by actiwe
Great, now we can compare G-Stylezz and this plug .
|
There's no need to compare. Use what you prefer.
I myself prefer this.
Re: [REL] SA:MP MySQL Plugin 1.1 -
Mike - 01.02.2010
Quote:
Originally Posted by StrickenKid
Updated to version 1.1!
See original post for details!
|
You can't call back to the amx from the external thread, it'll crash randomly.
There's an 'on tick' callback (i'm not sure of the exact naming, etc. - have a search around) that you can use in the main thread, to check for new query results and run the callback.
Re: [REL] SA:MP MySQL Plugin 1.1 -
Misiek - 01.02.2010
Hi there again, Ethan

Simply a great update, it's a huge progress from 1.0.x. Nice to see you using C++'s operators now, but I still could find a few mistakes
There's one thing I mentioned after G-Stylezz's R3 release. You both decided to return a constant number in mysql_query. Your version at least returns 1 instead of 0.
I've modified this function. First of all, you still didn't make it free the allocated *query after an error from mysql_real_query(). I also allowed myself to adjust returned values a little. I hope you're okay with that

I don't like going through all 20 possible mysql connections (even in a separate thread), while most of plugin's uses won't require more than just one connetion open at a time. I actually think you could reduce it to just three - if anyone needs a bigger one, they can simply modify and recompile the plugin. You didn't choose std::vector to store them - was it because of it's overhead?
And there's also the thing Mike has already mentioned - use ProcessTick() and another queue to call OnMysqlQuery().
Quote:
// native mysql_query(const query[]);
PLUGIN_FUNCTION
n_mysql_query( AMX* amx, cell* params )
{
int
h = MY_HANDLE(3);
if (!PARAM_COUNT(3))
{
GenerateError(h, "'mysql_query' called with incorrect param count", P_ERROR_INCPARAMCNT);
return 0;
}
if (!my[h].connected)
{
GenerateError(h, "'mysql_reload' called when not connected to any database", P_ERROR_DBNOCONN);
return 0;
}
if (my[h].result)
{
mysql_free_result(my[h].result);
my[h].result = NULL;
}
if (params[2] != -1)
{
queryInfo
mysqlQueue;
mysqlQueue.query = GetParam(amx, params[1]);
mysqlQueue.resultId = params[2];
my[h].queueInfo.push(mysqlQueue);
return -1;
}
else
{
const char
*query = GetParam(amx, params[1]);
my[h].state = mysql_real_query(my[h].mysql, query, strlen(query)+1);
if (my[h].state != NULL)
{
GenerateError(h, "Could not execute query", mysql_errno(my[h].mysql));
delete query;
return 0;
}
if (my[h].logging == LOG_ALL)
mysql_log("'mysql_query' executed: \"%s\" with result: \"%d\".", query, my[h].state);
delete query;
return 1;
}
//no constant return here
}
|
Re: [REL] SA:MP MySQL Plugin 1.1 -
StrickenKid - 01.02.2010
Quote:
Originally Posted by Wicko
Hi there again, Ethan 
Simply a great update, it's a huge progress from 1.0.x. Nice to see you using C++'s operators now, but I still could find a few mistakes
There's one thing I mentioned after G-Stylezz's R3 release. You both decided to return a constant number in mysql_query. Your version at least returns 1 instead of 0.
I've modified this function. First of all, you still didn't make it free the allocated *query after an error from mysql_real_query(). I also allowed myself to adjust returned values a little. I hope you're okay with that 
I don't like going through all 20 possible mysql connections (even in a separate thread), while most of plugin's uses won't require more than just one connetion open at a time. I actually think you could reduce it to just three - if anyone needs a bigger one, they can simply modify and recompile the plugin. You didn't choose std::vector to store them - was it because of it's overhead?
And there's also the thing Mike has already mentioned - use PricessTick() and another queue to call OnMysqlQuery().
Quote:
// native mysql_query(const query[]);
PLUGIN_FUNCTION
n_mysql_query( AMX* amx, cell* params )
{
int
h = MY_HANDLE(3);
if (!PARAM_COUNT(3))
{
GenerateError(h, "'mysql_query' called with incorrect param count", P_ERROR_INCPARAMCNT);
return 0;
}
if (!my[h].connected)
{
GenerateError(h, "'mysql_reload' called when not connected to any database", P_ERROR_DBNOCONN);
return 0;
}
if (my[h].result)
{
mysql_free_result(my[h].result);
my[h].result = NULL;
}
if (params[2] != -1)
{
queryInfo
mysqlQueue;
mysqlQueue.query = GetParam(amx, params[1]);
mysqlQueue.resultId = params[2];
my[h].queueInfo.push(mysqlQueue);
return -1;
}
else
{
const char
*query = GetParam(amx, params[1]);
my[h].state = mysql_real_query(my[h].mysql, query, strlen(query)+1);
if (my[h].state != NULL)
{
GenerateError(h, "Could not execute query", mysql_errno(my[h].mysql));
delete query;
return 0;
}
if (my[h].logging == LOG_ALL)
mysql_log("'mysql_query' executed: \"%s\" with result: \"%d\".", query, my[h].state);
delete query;
return 1;
}
//no constant return here
}
|
|
Thanks allot
I never knew about the ProcessTick() callback and I'll use that, Thanks for the other heads up, I will work on it in a little while. Just got home from school and I'm going to get some lunch.
EDIT: Oh, also, it doesn't loop through all 20 connections, it will loop until it hits a null'd mysql variable, so if theirs only one connection, it will stop the loop at the next check because it will be null. But I could also lower it to maybe 5.
Re: [REL] SA:MP MySQL Plugin 1.1 -
Maniek - 02.02.2010
What I do wrong?
Code:
mysql_log(1);
mysql_connect("", "", "", "", 0);
new string[256], data[256];
format(string, sizeof(string), "SELECT `user_pass` FROM `map_users` WHERE `user_nick`=%s", PN(playerid));
mysql_query(string);
mysql_store_result();
if(mysql_fetch_field("user_pass", data))
{
new string2[64];
format(string2, sizeof(string2), "%s", mysql_store_result());
SendClientMessage(playerid, ZOLTY, string2);
}
else
{
SendClientMessage(playerid, ZOLTY, "B");
}
Re: [REL] SA:MP MySQL Plugin 1.1 -
Misiek - 02.02.2010
What does the log say?
I assume it's because you don't enclose the nickname in the query.
Code:
format(string, sizeof(string), "SELECT `user_pass` FROM `map_users` WHERE `user_nick`='%s'", PN(playerid));
Is what you're looking for.
Re: [REL] SA:MP MySQL Plugin 1.1 -
StrickenKid - 02.02.2010
Code:
format(string2, sizeof(string2), "%s", mysql_store_result());
What Wicko posted and that ^ is the problem. You're trying to get a string from mysql_store_result ?
Try this:
Code:
mysql_log(1);
mysql_connect("", "", "", "", 0);
new string[256], data[256];
format(string, sizeof(string), "SELECT `user_pass` FROM `map_users` WHERE `user_nick`='%s'", PN(playerid));
mysql_query(string);
mysql_store_result();
if(mysql_fetch_field("user_pass", data))
{
SendClientMessage(playerid, ZOLTY, data);
}
else
{
SendClientMessage(playerid, ZOLTY, "B");
}