SQL代码崩溃了我的游戏:( [英] SQL Code crashing my game :(

查看:89
本文介绍了SQL代码崩溃了我的游戏:(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编码一个游戏. (MMORPG)专用服务器.
当我使用命令加载播放器的信息集市时(来自SQL)
它的作品非常完美.
但是,如果我输入了我的名字.那是在SQL上找不到的SQL.
它崩溃了我的游戏. (服务器端)
而且我只想让它说错误",就不会崩溃了..

对不起,我的英语不好..
这里是代码..

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 ..

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);
				}
			}
		}
	}
}



有什么主意吗?
(顺便说一句,游戏是:Mu Online:D)



Any idea ?
(Btw the game is: Mu Online :D )

推荐答案

您的代码应该简单地考虑所有可能的输入并加以处理.我看不懂这段代码,但是,如果您查看正在爆炸的行以及错误所在(例如,是否为空值),则可以编写代码以检查该值是否为null(再次,例如,您的帖子太含糊)并返回错误消息.
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.


如果您使用调试器,则在代码中会发现很多错误.还要使代码一致,首先检查SQL *函数的每个返回值是否成功.当您收到错误代码时,则必须使用SQLError函数检查更准确的信息.
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.


这篇关于SQL代码崩溃了我的游戏:(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆