Help with a mysql code
#1

Код:
funcion getGroupColor(id)
{
	new color = -256;
	mysql_format(idConexion, consulta, sizeof(consulta), "SELECT Color FROM Clanes WHERE Id=%d", id);
	new Cache:result = mysql_query(idConexion, consulta);
	if(cache_get_row_count(idConexion) > 0)
	{
		color = cache_get_row_int(0, 0, idConexion);
	}
	cache_delete(result, idConexion);
	return color;
}


funcion setGroupColor(id, color)
{
	mysql_format(idConexion, consulta, sizeof(consulta), "UPDATE Clanes SET Color=%d WHERE Id=%d", color, id);
	mysql_query(idConexion, consulta, false);
}
But I can not create a new clan and in the logs this appears:

Quote:

[22:54:47] [DEBUG] mysql_format - connection: 1, len: 144, format: "INSERT INTO Clanes(Nombre) VALUES('%e');"
[22:54:47] [DEBUG] mysql_query - connection: 1, query: "INSERT INTO Clanes(Nombre) VALUES('SAPD');", use_cache: true
[22:54:47] [DEBUG] CMySQLQuery::Execute - starting query execution
[22:54:47] [ERROR] CMySQLQuery::Execute - (error #1364) Field 'Color' doesn't have a default value
[22:54:47] [DEBUG] mysql_errno - connection: 1
[22:54:47] [DEBUG] cache_delete - cache_id: 0, connection: 1
[22:54:47] [WARNING] CMySQLHandle:eleteSavedResult - invalid result id ('0')

Also I can not put as default Color "0" Because then I Can't change the color......
Reply
#2

What is funcion?

Is using
Код:
forward getGroupColor(id);
public getGroupColor(id)
too hard for you?

Also, use threaded queries. You should never have to use normal queries anywhere else other than OnGameModeInit realistically.
Reply
#3

Quote:
Originally Posted by Blackaslan
Посмотреть сообщение
Код:
funcion getGroupColor(id)
{
	new color = -256;
	mysql_format(idConexion, consulta, sizeof(consulta), "SELECT Color FROM Clanes WHERE Id=%d", id);
	new Cache:result = mysql_query(idConexion, consulta);
	if(cache_get_row_count(idConexion) > 0)
	{
		color = cache_get_row_int(0, 0, idConexion);
	}
	cache_delete(result, idConexion);
	return color;
}


funcion setGroupColor(id, color)
{
	mysql_format(idConexion, consulta, sizeof(consulta), "UPDATE Clanes SET Color=%d WHERE Id=%d", color, id);
	mysql_query(idConexion, consulta, false);
}
But I can not create a new clan and in the logs this appears:



Also I can not put as default Color "0" Because then I Can't change the color......
First off:
I really suggest you not to use getGroupColor every time, you should save it onto a variable and edit it as it goes, rather than loading it every time using mysql_query as it freezes the whole script while waiting for the query to execute.

Secondly,
you are inserting a new row in the table `Clanes` but you have not specified the `Color` value, and you didn't define a default value in the table structure so that is why it is firing an error, as the mysql server does not know which value to input,

This is how you should structure that column:
pawn Код:
`Color` int(11) NOT NULL DEFAULT '-256'
Reply
#4

Quote:
Originally Posted by MafiaOink
Посмотреть сообщение
First off:
I really suggest you not to use getGroupColor every time, you should save it onto a variable and edit it as it goes, rather than loading it every time using mysql_query as it freezes the whole script while waiting for the query to execute.

Secondly,
you are inserting a new row in the table `Clanes` but you have not specified the `Color` value, and you didn't define a default value in the table structure so that is why it is firing an error, as the mysql server does not know which value to input,

This is how you should structure that column:
pawn Код:
`Color` int(11) NOT NULL DEFAULT '-256'
Yay! Thanks you very much already fixed with
Код:
ALTER TABLE Clanes ADD `Color` int(11) NOT NULL DEFAULT '-256'
Repped +2.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)