CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2005
    Posts
    21

    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) )??

  2. #2
    Join Date
    Jun 2005
    Posts
    1,255

    Smile 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

  3. #3
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    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

  4. #4
    Join Date
    Sep 2005
    Posts
    21

    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.

  5. #5
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,721

    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) << "'";

  6. #6
    Join Date
    Sep 2005
    Posts
    21

    Re: Variables not working

    Quote 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
  •  





Click Here to Expand Forum to Full Width

Featured