Jump to content
Rinor

[CO] Invalid Column Name Database Error

Recommended Posts

Hi, i went through gameserver logs on my test server (playing with CO src/files), i noticed something at util_db.txt file:

[02-28 18:42:35]SQL Error State:42S22, Native Error Code: CF, ODBC Error: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'con'.
[02-28 18:42:35][STMT:0x3238720][SQLERR]: [select cha_id, con from map_mask where id=2790]

So i first checked database and the column name was con
I tried to add con attribute ingame to check if it updates on database and it did
I went through source code to check database if the column was con and it was
Still it throws this error while other stuff as agi,sta etc.. are fine.

Could anyone give me any clue on this? thanks

Edited by Rinor

Share this post


Link to post
Share on other sites

Hello @Rinor,

 

Based on the text of the error, we are talking about the map_mask table, not character.


Share this post


Link to post
Share on other sites
On 3/1/2022 at 6:17 AM, V3ct0r said:

Hello @Rinor,

 

Based on the text of the error, we are talking about the map_mask table, not character.

Hi @V3ct0r,

map_mask table has only this kind of column's
https://imgur.com/a/ZGGc6YQ

It has same columns on a clean DB aswell, i can't find any con column related inside source code which asks for this column con inside map_mask, do you have any idea of this issue?

Share this post


Link to post
Share on other sites

@Rinor

 

Look for SQL-query in the GameServer source code:

select cha_id, con from map_mask where id=2790

 

Something like:

select cha_id, con from %s where id=%d

or

select cha_id, con from

 

Probably field con should be content1 ... content5.


Share this post


Link to post
Share on other sites
28 minutes ago, V3ct0r said:

@Rinor

 

Look for SQL-query in the GameServer source code:


select cha_id, con from map_mask where id=2790

 

Something like:


select cha_id, con from %s where id=%d

or


select cha_id, con from

 

Probably field con should be content1 ... content5.

It is content1...content5 already by default inside source codes of gameserver

	_snprintf_s(g_sql, sizeof(g_sql), _TRUNCATE, "select \
				id, cha_id, content1, content2, content3, content4, content5 \
				from %s \
				(nolock) where 1=2", \
				_get_table());

 

Share this post


Link to post
Share on other sites
7 hours ago, V3ct0r said:

Probably field con should be content1 ... content5.

he seems refactoring / copying _sprintf without reading how it works so buffer limited to < 3 > 
so mostly his issue inside

CTableMapMask::GetColNameByMapName

which is 

 

char* szColBase = "content";

so as he post i can see he use sprintf like this:
 

_snprintf_s(szColName, sizeof(szColName), _TRUNCATE, "%s%d", szColBase, chIndex);

which suppose to be
 

_snprintf_s(szColName, lColNameLen, _TRUNCATE, "%s%d", szColBase, chIndex);

still can use 
(long)strlen(szColBase)
but as it above will works just fine!

Edited by mkhzaleh

Share this post


Link to post
Share on other sites
8 hours ago, Rinor said:

 


	_snprintf_s(g_sql, sizeof(g_sql), _TRUNCATE, "select \
				id, cha_id, content1, content2, content3, content4, content5 \
				from %s \
				(nolock) where 1=2", \
				_get_table());

 

So sprintf cant be used like this but as you saying  below?:

1 hour ago, mkhzaleh said:

which suppose to be

_snprintf_s(szColName, lColNameLen, _TRUNCATE, "%s%d", szColBase, chIndex);

 

Share this post


Link to post
Share on other sites
19 hours ago, Rinor said:

It is content1...content5 already by default inside source codes of gameserver


	_snprintf_s(g_sql, sizeof(g_sql), _TRUNCATE, "select \
				id, cha_id, content1, content2, content3, content4, content5 \
				from %s \
				(nolock) where 1=2", \
				_get_table());

 

Are you sure that this is the SQL query that is being called by your code?

 

The _snprintf_s() function in the second parameter accepts the size of a buffer specified in the first parameter. The buffer must be larger than the resulting string after formatting, otherwise the string will be truncated to the size of the buffer.


Share this post


Link to post
Share on other sites
6 hours ago, V3ct0r said:

Are you sure that this is the SQL query that is being called by your code?

Hm, based on the error that i get it throws error about column “con” inside the map_mask table, while theres no such column, there is just content1…content5

and the only code inside source code about this are the one i sent above, the one that mkhzaleh sent could be the fix maybe? I haven’t tested it yet. You have any other clue? Theres no other map_mask code inside source that is related to content1…content5 expect “content” only which is this one:

char* szColBase = "content";


like mkhzaleh sent above.

 

Share this post


Link to post
Share on other sites

@Rinor,

 

do you can show the contents of CTableMapMask::GetColNameByMapName and CTableMapMask::ReadData methods?

 


Share this post


Link to post
Share on other sites
On 3/4/2022 at 7:15 AM, V3ct0r said:

@Rinor,

 

do you can show the contents of CTableMapMask::GetColNameByMapName and CTableMapMask::ReadData methods?

 

bool CTableMapMask::GetColNameByMapName(const char *szMapName, char *szColName, long lColNameLen)
{
	if (!szMapName || !szColName)
		return false;
	char	*szColBase = "content";
	if ((long)strlen(szColBase) + 1 >= lColNameLen)
		return false;

	char	chIndex = 0;
	if (!strcmp(szMapName, "garner"))
		chIndex = 1;
	else if (!strcmp(szMapName, "magicsea"))
		chIndex = 2;
	else if (!strcmp(szMapName, "darkblue"))
		chIndex = 3;
	else if (!strcmp(szMapName, "winterland"))	// Add by lark.li 20080812 
		chIndex = 4;
	//else if (!strcmp(szMapName, "eastgoaf"))
	//	chIndex = 4;
	//else if (!strcmp(szMapName, "lonetower"))
	//	chIndex = 5;
	else
		return false;

	_snprintf_s(szColName, sizeof(szColName), _TRUNCATE, "%s%d", szColBase, chIndex);
	return true;
}
bool CTableMapMask::ReadData(CPlayer *pCPly)
{
	if(!pCPly || !pCPly->IsValid())
	{
		//LG("enter_map", "读地图掩码数据库错误,角色不存在.\n");
		LG("enter_map", "Load map hideID database error,character is inexistence.\n");
		return false;
	}
	if (pCPly->GetMapMaskDBID() == 0)
	{
		long	lDBID;
		if (!Create(lDBID, pCPly->GetDBChaId()))
			return false;
		pCPly->SetMapMaskDBID(lDBID);
	}

	char szMaskColName[30];
	if (!GetColNameByMapName(pCPly->GetMaskMapName(), szMaskColName, 30))
	{
		//LG("enter_map", "选择地图掩码数据错误.\n");
		LG("enter_map", "choice map hideID data error.\n");
		return false;
	}

	int nIndex = 0;
	char param[80];
	_snprintf_s(param, sizeof(param), _TRUNCATE, "cha_id, %s", szMaskColName);
	char filter[80]; 
	_snprintf_s(filter, sizeof(filter), _TRUNCATE, "id=%d", pCPly->GetMapMaskDBID());
	int r = _get_row3(g_buf, g_cnCol, param, filter);
	int	r1 = get_affected_rows();
	if (DBOK(r) && r1 > 0)
	{
		DWORD	dwChaId = Str2Int(g_buf[nIndex++]);
		if (dwChaId != pCPly->GetDBChaId())
		{
			//LG("enter_map", "读地图掩码数据库错误,角色不匹配.\n");
			LG("enter_map", "Load map hideID database error,character is not matching.\n");
			return false;
		}
		pCPly->SetMapMaskBase64(g_buf[nIndex++].c_str());
		//if (strcmp(g_buf[nIndex-1].c_str(), "0"))
		//	LG("大地图长度", "地图 %s,长度 %u.\n", pCPly->GetMaskMapName(), strlen(g_buf[nIndex-1].c_str()));
	}
	else
	{
		//LG("enter_map", "读地图掩码数据库错误,_get_row()返回值:%d.%u\n", r);
		LG("enter_map", "Load map hideID database error,_get_row() return value:%d.%u\n", r);
		return false;
	}
	//LG("enter_map", "读大地图数据成功.\n");
	LG("enter_map", "Load big map data succeed.\n");
	return true;
}

 

Share this post


Link to post
Share on other sites
43 minutes ago, mkhzaleh said:

its just as i explained above ,bad refactor , 

 

Its used like that in top-recode so whats the difference? Still bad refactor? Lol

Share this post


Link to post
Share on other sites

@Rinor

 

Replace it:

_snprintf_s(szColName, sizeof(szColName), _TRUNCATE, "%s%d", szColBase, chIndex);

with:

_snprintf_s(szColName, lColNameLen, _TRUNCATE, "%s%d", szColBase, chIndex);

 

sizeof(szColName) is wrong. It will give 4 bytes (the size of pointer for char data type), but not the size of outter buffer szColName. As the result you see con (3 symbols + null terminator).

  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...