PDA

View Full Version : Problem MYSQL R7


HitnKill
19/07/2013, 10:54 PM
Hi, i want to upgrade my mysql plugin R6 to R7, i want to do it gradually. I want to use cache but not directly for try my query.

Exemply why this query don't work? I read to this post http://forum.sa-mp.com/showthread.php?t=56564 mysql_num_rows it's okay on R7.

GetUserCreate(playerid)
{
new query[130];
format(query,sizeof(query),"SELECT PlayerID FROM `comptes` WHERE Pseudo = '%s' LIMIT 1",GetPlayerNameEx(playerid));
mysql_function_query(ConnexionBDD, query, false, "", "");
mysql_store_result();
if(mysql_num_rows() > 0)
{
return 1;
}
mysql_free_result();
return 0;
}

The log

[20:41:00] Passing query SELECT PlayerID FROM `comptes` WHERE Pseudo = 'Soze' LIMIT 1 |
[20:41:00] ProcessQueryThread() - Query was successful. (SELECT PlayerID FROM `dm_comptes` WHERE Pseudo = 'Soze' LIMIT 1)
[20:41:00] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()

My GetUserCreate return 0 all times but with R6 version it's okay.

arakuta
20/07/2013, 12:21 AM
R7 doesn't need to store or free the result.

You get the result in a response callback.

mysql_function_query(handle,query,cacheing??,"responsecallback","arguments",Mixed{...)

Example:

mysql_function_query(MySQL_Handle,"SELECT * FROM `users` WHERE ip="127.0.0.1",true,"r@MySQL_IPs","ds",playerid,"127.0.0.1");

public r@MySQL_IPs(playerid,ip[])
{
new rows,fields,pip[16],text[24];
cache_get_data(rows,fields,handle);
if(rows)
{
SendClientMessage(playerid,-1,"Players with IP '127.0.0.1':");
for(new f; f = fields; ++f)
{
cache_get_field_content(0,"name",pip,handle);
format(text,sizeof text,"%s",pip);
SendClientMessage(playerid,-1,text);
}
}
else
return SendClientMessage(playerid,-1,"No player with this IP.");
return 1;
}

HitnKill
20/07/2013, 12:30 AM
Ok thanks, on R7 we are forced to use cache_get_data and other... we can't use the old script?

arakuta
20/07/2013, 12:36 AM
Ok thanks, on R7 we are forced to use cache_get_data and other... we can't use the old script?

You can manually convert.

This can help you

http://forum.sa-mp.com/showthread.php?t=337810

HitnKill
20/07/2013, 04:53 PM
I have an idea for don't change all my script with this vR7 MYSQL.

Example my old function


R6

if(IPBanned(plrip) > 0)
{
// code....
}

IPBanned(ip[])
{
new query[100],ipexist;
format(query,sizeof(query),"SELECT IP FROM `dm_bans` WHERE IP = '%s' LIMIT 1",ip);
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
if(rows > 0) ipexist = 1;
else ipexist = 0;
mysql_free_result();
return ipexist;
}


R7

if(IPBanned(plrip,0) > 0)
{
// code...
}

forward IPBanned(ip[],ID);
public IPBanned(ip[],ID)
{
if(ID == 0)
{
new query[100];
format(query,sizeof(query),"SELECT IP FROM `dm_bans` WHERE IP = '%s' LIMIT 1",ip);
mysql_function_query(ConnexionBDD, query, true, "IPBanned", "si",ip,1);
}
else
{
new rows,fields,ipexist;
cache_get_data(rows, fields);
if(rows > 0) ipexist = 1;
else ipexist = 0;
return ipexist;
}
return 1;
}

Don't problem with this codes on R7 if i call a same function?