• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

mysql error

strutZ

Australian OT Member {AKA Beastn}
Joined
Nov 16, 2014
Messages
1,392
Solutions
7
Reaction score
552
Hey guys,

Trying to do a source edit to make the report function inject into mySQL database. Heres my function

Code:
void Game::playerReportBug(uint32_t playerId, const std::string& message, const Position position, uint8_t category)
{
    Player* player = getPlayerByID(playerId);
    if (!player) {
         return;
    }

    Database* db = Database::getInstance();
    const Position& playerpos = player->getPosition();
    std::ostringstream query;
   query << "INSERT INTO `reports` (`player_id`, `mapposx`, `mapposy`, `mapposz`, `playerposx`, `playerposy`, `playerposz`, `comment`, `datelog`) VALUES (" << player->getGUID() << ", " << position.x << ", " << position.y << ", " << position.z << ", " << playerpos.x << ", " << playerpos.y << ", " << playerpos.z << ", " << db->escapeString(message.c_str()) << ", " CURDATE())";
    db->executeQuery(query.str());
}

I keep getting this error in console.
V7lXgEx.png
 
I'm not sure, but the first thing I would try would be this:

replace
<< player->getGUID() <<

with
<< guid <<

Can we use the -> operator at all inside a query?
If not, db->escapeString(message.c_str()) will have to be replaced too
 
Last edited:
I have just debugged and I found that C++ was casting the Z axis to a char instead of keeping it as a number. As a result, when you were trying to insert the 7 character (BEL) instead of the plain number 7.

A solution is to upcast 8-bit integers to 16-bit ones that don't get transformed to characters:
Code:
query << "INSERT INTO `reports` (`player_id`, `mapposx`, `mapposy`, `mapposz`, `playerposx`, `playerposy`, `playerposz`, `comment`, `datelog`) VALUES (" << player->getGUID() << ", " << position.x << ", " << position.y << ", " << static_cast<uint16_t>(position.z) << ", " << playerpos.x << ", " << playerpos.y << ", " << static_cast<uint16_t>(playerpos.z) << ", " << db->escapeString(message.c_str()) << ", " CURDATE())";

And as I said to you before, use NOW() instead of CURDATE() as the latter does not contain time information, only date.

I'm not sure, but the first thing I would try would be this:

replace
<< player->getGUID() <<

with
<< guid <<

Can we use the -> operator at all inside a query?
If not, db->escapeString(message.c_str()) will have to be replaced too
Do you even know what you are talking about? I bet no.
There's no variable named guid there, and this is absolutely nothing to do with ->.
 
@Lordfire It's all good, I don't know any C++ at all (can you tell? :P)

If it interests you though I arrived at my thoughts by checking if -> operators are used anywhere else in existing code inside a query (they're not, though I didn't spent much time looking)
To avoid using this in other sections of code the programmer has used a variable, like guid. I would have thought it would go without saying that if you were replacing something with a new variable that you need to define it first.

Anyway like I said, I don't know any C++
Glad you were around to help out =]
 

Similar threads

Back
Top