27.01.2010, 19:14
Noticed this. It takes at least a second to log a player in with just password, name and cash.
Originally Posted by OnTop2K9
Noticed this. It takes at least a second to log a player in with just password, name and cash.
|
Originally Posted by OnTop2K9
Noticed this. It takes at least a second to log a player in with just password, name and cash.
|
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;
}
Originally Posted by OnTop2K9
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);
}
}
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(); }
Originally Posted by actiwe
Great, now we can compare G-Stylezz and this plug .
|
Originally Posted by StrickenKid
Updated to version 1.1!
See original post for details! |
// 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 } |
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:
|
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"); }
format(string, sizeof(string), "SELECT `user_pass` FROM `map_users` WHERE `user_nick`='%s'", PN(playerid));
format(string2, sizeof(string2), "%s", mysql_store_result());
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"); }