-
November 15th, 2005, 06:01 AM
#1
Variables not working
Why is my function not working correctly?
Code:
int AuthSocket::CountChar(uint8 account, uint8 realm)
{
std::stringstream query;
query << "SELECT count(*) AS `count` FROM `characters` WHERE `acct`='" << account << "' AND `realm`='" << realm << "'";
QueryResult *result = sDatabase.Query( query.str().c_str() );
if(result)
{
Field *fields = result->Fetch();
int numchars = fields[0].GetUInt8();
return numchars;
}
else
{
return 0;
}
}
instead of running sql query "SELECT count(*) AS `count` FROM `characters` WHERE `acct`='2' AND `realm`='3' ";
It runs the query with smilys instead of nummers (input CountChar(2,3) )??
-
November 15th, 2005, 06:28 AM
#2
Re: Variables not working
If you see smileys instead of numbers, that's because numbers should be converted to strings.
An SQL statement is a long string containing only Ascii characters, not binary numbers
-
November 15th, 2005, 06:59 AM
#3
Re: Variables not working
Code:
"SELECT count(*) AS `count` FROM `characters`
WHERE ` acct `= ' " << account << " ' AND `realm`= ' " << realm << " ' ";
As i understand why u r passing ur acct and realm values as char type remove single quote as highlight above as red and then try it.
Last edited by Naumaan; November 15th, 2005 at 07:03 AM.
A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.
NAUMAAN
-
November 15th, 2005, 07:21 AM
#4
Re: Variables not working
Using ' or no ' makes no difference.
I also tough the same thing about converting the int to char but i don't have a clue how to do that.
something like:
std::stringstream acc;
acc << account;
Last edited by CodeNeos; November 15th, 2005 at 07:39 AM.
-
November 15th, 2005, 07:50 AM
#5
Re: Variables not working
If I understand your problem correctly, you can cast the char
variables (unit8) to int variables ...
Code:
query << "SELECT count(*) AS `count` FROM `characters` WHERE `acct`='"
<< static_cast<int>(account) << "' AND `realm`='"
<< static_cast<int>(realm) << "'";
-
November 15th, 2005, 09:11 AM
#6
Re: Variables not working
Originally Posted by Philip Nicoletti
If I understand your problem correctly, you can cast the char
variables (unit8) to int variables ...
Code:
query << "SELECT count(*) AS `count` FROM `characters` WHERE `acct`='"
<< static_cast<int>(account) << "' AND `realm`='"
<< static_cast<int>(realm) << "'";
thanks it works correctly now. I will keep this in mind for the next time i ecounter such a problem.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|