SA-MP Forums Archive
SQL not saving - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SQL not saving (/showthread.php?tid=637189)



SQL not saving - Antenastyle - 10.07.2017

Hi, I have this three functions to save different values, the SaveSQLInt works perfect, but the problem is with the SaveSQLFloat and SaveSQLString, those aren't saving the values...

Код:
Servidor:SaveSQLInt(sqlid, table[], row[], value)
{
	new query[128];
	mysql_format(sqlConnection, query, sizeof(query), "UPDATE %e SET %e = %i WHERE id = %i", table, row, value, sqlid);
	mysql_pquery(sqlConnection, query);
	return true;
}

Servidor:SaveSQLFloat(sqlid, table[], row[], Float:value)
{
	new query[128];
	mysql_format(sqlConnection, query, sizeof(query), "UPDATE %e SET %e = %f WHERE id = %i", table, row, value, sqlid);
	mysql_pquery(sqlConnection, query);
	return true;
}

Servidor:SaveSQLString(sqlid, table[], row[], value[])
{
	new query[128];
	mysql_format(sqlConnection, query, sizeof(query), "UPDATE %e SET %e = %s WHERE id = %i", table, row, value, sqlid);
	mysql_pquery(sqlConnection, query);
	return true;
}



Re: SQL not saving - Kaperstone - 10.07.2017

Have you looked at the way you use these functions ?
Tried to use the functions directly ?
pawn Код:
SaveSQLFloat(0,"accounts","Antenastyle",2.00);
SaveSQLString(0, "table","Antenastyle", "String");
Maybe the issue isn't in the functions at all.

Try to print whether mysql_pquery returns 1 (for successful) or 0


Re: SQL not saving - Antenastyle - 10.07.2017

Okay, the floats saves right, but the string isn't saving, I'm doing this...

Код:
else if(strmatch(section, "name"))
		{
			if(sscanf(params, "s[10]s[40]", section, extra)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: {FFFFFF}/edithouse name [Name]");
			{
				if(strlen(extra) < 3 || strlen(extra) > 39) return SendClientMessage(playerid, COLOR_ERROR, "ERROR: Name must be between  3 and 39 characters.");
				
				HouseData[houseid][HouseName] = extra;
				
				Delete3DTextLabel(HouseData[houseid][HouseLabel]);
				if(HouseData[houseid][HouseOwnerSQL] != 0)
				{
					format(string2, sizeof(string2), "{FFCC00}%s\nID: {FFFFFF}%i", HouseData[houseid][HouseName], HouseData[houseid][HouseSQLId]);
				}
				else
				{
					format(string2, sizeof(string2), "{FFCC00}%s\nPrice: {FFFFFF}%i$\n{FFCC00}ID: {FFFFFF}%i", HouseData[houseid][HouseName], HouseData[houseid][HousePrice], HouseData[houseid][HouseSQLId]);
				}
				HouseData[houseid][HouseLabel] = Create3DTextLabel(string2, 0xFFFFFFFF, HouseData[houseid][HouseExterior][0], HouseData[houseid][HouseExterior][1], HouseData[houseid][HouseExterior][2], 10.0, 0, 1);
				
				SaveSQLString(HouseData[houseid][HouseSQLId], "houses", "Name", HouseData[houseid][HouseName]);
				
				SendClientMessage(playerid, COLOR_YELLOW, "INFO: Name edited:");
				SendClientMessage(playerid, COLOR_WHITE, HouseData[houseid][HouseName]);
			}
		}
HouseData[houseid][HouseName] changes, but it is not being saved into the db


Re: SQL not saving - Kaperstone - 10.07.2017

Then it could be the type of the column that is doing the mess.

Check if the column type is set to varchar(40) (or TEXT, but varchar(40) is prefered)


Re: SQL not saving - Antenastyle - 11.07.2017

The column is set to varchar(40)


Re: SQL not saving - Kaperstone - 11.07.2017

pawn Код:
UPDATE %e SET %e = %s WHERE id = %i
You didn't do ''
pawn Код:
UPDATE %e SET %e = '%s' WHERE id = %i
That's why.


Re: SQL not saving - Meller - 11.07.2017

Tell me why u r escaping the table and row but not value?

mysql_format(sqlConnection, query, sizeof(query), "UPDATE %e SET %e = %s WHERE id = %i", table, row, value, sqlid);


Re: SQL not saving - Antenastyle - 11.07.2017

Quote:
Originally Posted by Kaperstone
Посмотреть сообщение
pawn Код:
UPDATE %e SET %e = %s WHERE id = %i
You didn't do ''
pawn Код:
UPDATE %e SET %e = '%s' WHERE id = %i
That's why.
Thank you, that was the problem, now works perfect!

Quote:
Originally Posted by Meller
Посмотреть сообщение
Tell me why u r escaping the table and row but not value?

mysql_format(sqlConnection, query, sizeof(query), "UPDATE %e SET %e = %s WHERE id = %i", table, row, value, sqlid);
What do you mean?


Re: SQL not saving - Meller - 11.07.2017

Quote:
Originally Posted by Antenastyle
Посмотреть сообщение
What do you mean?
You're securing the table and row by using %e, but then you let the value go unsecured as a normal string, do this:
PHP код:
mysql_format(sqlConnectionquerysizeof(query), "UPDATE %e SET %e = '%e' WHERE id = %i"tablerowvaluesqlid); 
instead of
PHP код:
mysql_format(sqlConnectionquerysizeof(query), "UPDATE %e SET %e = %s WHERE id = %i"tablerowvaluesqlid); 



Re: SQL not saving - Antenastyle - 11.07.2017

Quote:
Originally Posted by Meller
Посмотреть сообщение
You're securing the table and row by using %e, but then you let the value go unsecured as a normal string, do this:
PHP код:
mysql_format(sqlConnectionquerysizeof(query), "UPDATE %e SET %e = '%e' WHERE id = %i"tablerowvaluesqlid); 
instead of
PHP код:
mysql_format(sqlConnectionquerysizeof(query), "UPDATE %e SET %e = %s WHERE id = %i"tablerowvaluesqlid); 
Yeah, I've changed it, thank you