IRCCMD:setofflevel(botid, channel[], user[], host[], params[]) {
if(IRC_IsOp(botid, channel, user)) {
new lvl;
if(sscanf(params, "s[24]i", params, lvl)) return IRC_GroupSay(groupID, IRC_CHANNEL, "4[Error] Use: !setofflevel <username> <level>");
if(lvl > 6) return IRC_GroupSay(groupID, IRC_CHANNEL, "4[Error] Invalid level.");
if(isuseronline(params))
return IRC_GroupSay(groupID, IRC_CHANNEL, "4[Error] This user is currently online.");
new Cache:result;
Query("SELECT `nick` FROM `users` WHERE `nick`='%e' ORDER BY `id`", params);
result = mysql_query(mysql, query);
if(!cache_get_row_count()) {
IRC_GroupSay(groupID, IRC_CHANNEL, "4[Error] The account with this username doesn't exist.");
cache_delete(result);
return 1;
}
new tmplvl = cache_get_field_content_int(0, "level");
if(lvl == tmplvl) {
IRC_GroupSay(groupID, IRC_CHANNEL, "4[Error] This user already has that level.");
cache_delete(result);
return 1;
}
if(lvl > tmplvl || lvl < tmplvl)
{
new id = cache_get_field_content_int(0, "id"), string[100];
Query("UPDATE `users` SET `level`='%i' WHERE `id`='%i'", lvl, id);
mysql_tquery(mysql, query, "QueryExecute", "i", result_none);
format:string("3[Info] You have set %s's admin level to %i", params, lvl);
IRC_GroupSay(groupID, IRC_CHANNEL, string);
}
cache_delete(result);
}
return 1;
}
Why would you cache it? Do you really want to use it all in one single command without multi-threading your queries? If that's really necessary for you, then use y_inline library from YSF or just create a public for SELECT queries. If you need to understand threaded queries, then ****** it and find out everything you need. It is recommended to DO NOT do it your way.
|
It's highly recommended to thread all your queries (even INSERT & UPDATE). Use cache_delete() if you don't need the query's result anymore or you will experience memory leaks. |