[Plugin] [REL] SA:MP MySQL Plugin 2.1.1 - Released (1/25/2011

hello,

My script stops working when I use this function:

split(data, field, '|');
Reply

Can we get the whole snippet of code used? Just saying that this one function is causing the script to stop working doesn't help!
Reply

I have a little problem, and i hope one of you can help me with it. I defined the MYSQL_CHECKFORACCOUNT as 1, so i can use a switch to process the query result in the OnMysqlQueryArray callback.

I get the error listed below on the line which contains the mysql_query_array. Why is this? What do i need to change?

Код:
#define MYSQL_CHECKFORACCOUNT 1
Код:
CheckForAccount(playerid)
{
	// ---------------------------------------------------------------------------------
	// New SQL style account checker!
	// ---------------------------------------------------------------------------------
	
	new query[128], pname[MAX_PLAYER_NAME];
	GetPlayerName(playerid, pname, sizeof(pname));
	format(query, sizeof(query), "SELECT * FROM `users` WHERE `username`='%s'", pname);
	
	mysql_query_array(query, MYSQL_CHECKFORACCOUNT, {playerid}, server);
	
	
}
Код:
tcrpg3.pwn(317) : error 008: must be a constant expression; assumed zero
EDIT: After some investigation, i discovered that the error is in {playerid}, but i seem unable to leave it out. I can't leave it out either, because i need the playerid to handle the request properly!
Reply

If you are only passing one variable to the callback, you can use mysql_query, mysql_query_array is only used when passing multiple parameters to the callback.

mysql_query prototype:
Код:
mysql_query(const query[], resultid = (-1), spareid = (-1), MySQL:handle = (MySQL:0));
The spareid would be the playerid you want to pass like so:
Код:
mysql_query(query, MYSQL_CHECKFORACCOUNT, playerid, server);
OR, if you really want to use mysql_query_array, you can just do:
Код:
mysql_query_array(query, MYSQL_CHECKFORACCOUNT, {playerid, 0}, server);
and not use the second index.
Reply

Thanks! It's working nicely, thanks for pushing me in the right direction!

EDIT: Even though the fix you suggested worked fine, i now run into problems when i DO have more than one variable i want to pass.

Код:
public Dialog_Login(playerid, inputtext[])
{
	// ---------------------------------------------------------------------------------
	// New SQL style login!
	// ---------------------------------------------------------------------------------
	
	new query[128], pname[MAX_PLAYER_NAME];
	GetPlayerName(playerid, pname, sizeof(pname));
	format(query, sizeof(query), "SELECT * FROM `users` WHERE `username`='%s'", pname);
	
	mysql_query_array(query, MYSQL_LOGIN, {playerid, inputtext}, server);
As you can see, i want to pass 'inputtext' to the query_array callback. However, this is now giving me the same error as before, but i'm convinced it's in the proper syntax.

Код:
tcrpg3.pwn(745) : error 008: must be a constant expression; assumed zero
I'm more than willing to learn from your helpful advice and great plugin! Thanks already!
Reply

I lose my nerves for a week and I can not fix: <. This is the code:

Код:
        new query[100],output[160],id_sql, count=0;
	format(query, sizeof(query), "SELECT * FROM `dm_vehicle` WHERE `owner` = '%d' AND `otype` = '2'",PlayerUID[playerid]);
	mysql_query(query);
	mysql_store_result();
	while(mysql_fetch_row(output, "|"))
	{
 		sscanf(output, "p<|>d",id_sql);
		sscanf(output, "p<|>ds[20]ddddfffdd",Veh[id_sql][UID],Item[id_sql][Name],Veh[id_sql][iModel],Veh[id_sql][iObject],Veh[id_sql][iOwn],Veh[id_sql][iOwntype],Veh[id_sql][iPo][0],Veh[id_sql][iPo][1],Veh[id_sql][iPo][2],Veh[id_sql][iInt],Veh[id_sql][iVW]);
		count++;
	}
    mysql_free_result();
	return count;
The problem is that loads the UID 1, 2, 3, 4, 5, and when it comes to break (the next record is UID 30) is suspended. But when the records one after another and there is no interruption to work. Please help, please!
Reply

i have this problems Failed (libmysqlclient_r.so.16: cannot open shared object file: No such file or directory)
Reply

Me too:
[14:38:16] Failed (libmysqlclient_r.so.16: cannot open shared object file: No such file or directory)

Using it on Linux.
Downloaded: 2.1.1 - Build 165
• Linux (compiled on Debian 5)
----Linux Distributions

What do I have to do?

EDIT:

I found our how to fix it:
Just download: • Static Linux Distributions (Use on Hosted Servers e.g. ServerFFS)

Good job! Great plugin.
Reply

Quote:
Originally Posted by lolumadd_
Посмотреть сообщение
Код:
Error (0): Failed to connect. Access denied for user 'root'@'localhost' (using password: YES).
I use the same login info before with the G-Stylez plugin. It won't let me connect now!
Im getting this same thing. I positive that it's in the correct order. Could there be a problem with assigning the localhost?
Reply

^ I had the problem, I thought it was mysql_connect(host, user, database, pass) because of the include flashing that little hint bar with the paramters for PAWN.

Turns out, after looking again it's mysql_connect(host, user, pass, database).
Reply

For people who are having troubles connecting to a mysql server, make sure your params are in the correct order! This mysql plugin doesn't use the same param order as some others!

Another note: the wiki for this plugin is a bit out dated, and the information most likely is not correct. The params for mysql_connect are as follows:
Код:
native mysql_connect(const host[], const user[], const pass[], const db[], MySQL:handle = (MySQL:0), auto_reconnect = 0);
I apologize for not giving much support for this plugin lately as I've devoted all of my free time to another project. I will continue updating this plugin once I get my other project solid and off the ground.

Thank you guys for staying patient!
Reply

Everytime i use mysql_ping it returns 0. But the connection is alive, why?
Reply

Quote:
Originally Posted by Cole_Phelps
Посмотреть сообщение
Everytime i use mysql_ping it returns 0. But the connection is alive, why?
That is the intended behavior! It'll return something else if the connection is not well and alive.
pawn Код:
if(mysql_ping() != 0)
{
    // dead
}
Reply

Okay, it works, thanks.
Next Problem. In OnGameModeInit I load my Cars.

mysql_query("SELECT * FROM `autos`");
mysql_store_result();
new query[256];
new RID, ID, mid,col1,col2,schild[20]; new Float,Float:y,Float:z,Float:angle,sp;
new vehicleid = 0;
new str[256];
while(mysql_fetch_row(str, "|"))
{
sscanf(str, "p<|>iiiiis[256]{i}{i}ffff{i}{i}iiiiiiiiiiiiiii",RID,ID,mid,col1,c ol2,schild,x,y,z,angle,sp,Tuning[vehicleid][Hood],Tuning[vehicleid][Roof],Tuning[vehicleid][Sideskirt],Tuning[vehicleid][Lamps],Tuning[vehicleid][Nitro],Tuning[vehicleid][Exhaust],Tuning[vehicleid][Wheels],Tuning[vehicleid][Stereo],Tuning[vehicleid][Hydraulics],Tuning[vehicleid][FrontBumper],Tuning[vehicleid][RearBumper],Tuning[vehicleid][VentRight],Tuning[vehicleid][VentLeft],Tuning[vehicleid][Paintjob]);
ID = CreateVehicle(mid,x,y,z,angle,col1,col2,0);
//blubb

In this loop i dont use mysql_store_result, only one time before.
But then, when the first vehicle is loaded, i become an error:
[15:03:20] [MySQL] Error (0): Function: mysql_store_result called when no result stored.
The loop breaks and the next things load (Houses etc.)
Reply

hey guys,
ive got a problem. i want to check banned users in a mysql table. a timer should update the bantime every minute.

code is:

new data[256];
mysql_query("SELECT * FROM accounts");
mysql_store_result();

while(mysql_fetch_row(data))
{
name[52], time[52];
mysql_fetch_field("name", name);
mysql_fetch_field("ban", time);
if(strval(time) > 0)
{
new query[128];
format(query, 128, "UPDATE accounts SET ban = '%d' WHERE name = '%s'", strval(time) - 1, name);
mysql_query(query);
}
}
mysql_free_result();

the problem: the code updates the bantime of the first valid player with bantime > 0. But after this, when the next valid player with bantime > 0 is detectet samp prints in server.log:
[01:37:41] [MySQL] Error (0): Function: mysql_store_result called when no result stored.
Can anyone help?
Reply

Quote:
Originally Posted by ddldl
Посмотреть сообщение
hey guys,
ive got a problem. i want to check banned users in a mysql table. a timer should update the bantime every minute.

code is:

new data[256];
mysql_query("SELECT * FROM accounts");
mysql_store_result();

while(mysql_fetch_row(data))
{
name[52], time[52];
mysql_fetch_field("name", name);
mysql_fetch_field("ban", time);
if(strval(time) > 0)
{
new query[128];
format(query, 128, "UPDATE accounts SET ban = '%d' WHERE name = '%s'", strval(time) - 1, name);
mysql_query(query);
}
}
mysql_free_result();

the problem: the code updates the bantime of the first valid player with bantime > 0. But after this, when the next valid player with bantime > 0 is detectet samp prints in server.log:
[01:37:41] [MySQL] Error (0): Function: mysql_store_result called when no result stored.
Can anyone help?
u dont need a timer ^^ you just must check it on connect.
you can do it easy with timestamp ^^ i can help you pm me ^^
Reply

How can I read two tables at the same time (two loops)?

It's easy to solve in PHP, but not in Pawn. Here is an example in PHP:
Код:
$data1 = mysql_query("SELECT * FROM table1");
while ($row1 = mysql_fetch_assoc($data))
{
	$data2 = mysql_query("SELECT * FROM table2 WHERE column1 = '" . $row1["column1"] . "'");
	while ($row2 = mysql_fetch_assoc($data2))
	{
		echo $row2["column2"];
	}
}
How can I do that in Pawn?
Reply

Quote:
Originally Posted by Programie
Посмотреть сообщение
How can I read two tables at the same time (two loops)?
Use sql JOIN clause.
Reply

Quote:
Originally Posted by Blantas
Посмотреть сообщение
Use sql JOIN clause.
Ok, that works. First I tried it with INNER JOIN but it didn't work. But now it works.
Reply

Should sending 2 or 3 threaded queries at the same time work just fine? It's not, for me.. I keep getting "[MySQL] Error (0): Could not execute query. Commands out of sync; you can't run this command now.". :/

Edit: The problem was NULL values messing with my server.
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)