Click here to Skip to main content
15,891,880 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm coding a game. (MMORPG) private server.
and when I load with command the infomartion of the player (From SQL)
Its works perfect.
But if I typing worng name. that's the SQL not found at the SQL.
Its crashing my game. (The server side)
And I just want its say "Error" and wor'nt crsash it ..

Sorry for my bad english ..
and here the code ..

C++
std::string CQuery::CheckName(int aIndex, char *Name)
{
	char String[256];
	char Query[150];
	SQLCHAR Str[5][64];
	SQLINTEGER Indicator[5];
	SQLSMALLINT Col;
	SQLRETURN Retcode;
	Clear();
	wsprintf(Query, "SELECT Name FROM Character WHERE Name = '%s'", Name);
	Retcode = SQLExecDirect(hStmt, (SQLCHAR*)Query, SQL_NTS);
	SQLTables(hStmt, NULL, 0, NULL, 0, NULL, 0, (SQLCHAR*)"TABLE", SQL_NTS);
	SQLNumResultCols(hStmt, &Col);

	for(int i = 0; i < Col; i++)
	{
		SQLBindCol(hStmt, i + 1, SQL_C_CHAR, Str[i], sizeof(Str[i]), &Indicator[i]);
	}
	while(SQL_SUCCEEDED(SQLFetch(hStmt)))
	{
		for(int i = 0; i < Col; i++)
		{
			if(Indicator[i] != SQL_NULL_DATA)
			{
				wsprintf(String, "%s", Str[i]);
				if(strcmpi(String, Name) == 0)
				{
					return String;
				}
				else
				{
					GCServerMsgStringSend("ERROR", aIndex, 1);
				}
			}
		}
	}
}


Any idea ?
(Btw the game is: Mu Online :D )
Posted
Comments
bbirajdar 29-Jul-12 15:49pm    
Is this the SQL code ?

Your code should simply consider every possible input and deal with it. I can't read this code, but, if you look at the line that's blowing up, and what the error is ( is it a null value for example ), then you can write code to check if the value is null ( again, for example, your post is so vague ) and return an error message.
 
Share this answer
 
Comments
Ido Hadar 29-Jul-12 16:45pm    
The 'String' just return a NULL ?
I'll test it. thanks.
Christian Graus 29-Jul-12 16:49pm    
Do you know how to use a debugger ? If you hit F9, you set what's called a breakpoint. This means if you hit F5, the program runs and stops at that point. You can use F10 to execute one line at a time and mouse hover or use the windows below to view the values of variables, etc. Then you can work out exactly what is wrong and write code to fix it.
Ido Hadar 29-Jul-12 16:56pm    
Omg working perfect :D
Ty you so much :)
Christian Graus 29-Jul-12 17:03pm    
Terrific, glad to help.
Ido Hadar 29-Jul-12 16:56pm    
Christian Graus - This code form my DLL.
If you use a debugger, then you will find lots of errors in the code. Also make consistent code, first of all check each return value of SQL* function for success. When you get an error code, then you have to use SQLError function to check more exact information.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900