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

TFS 1.X+ DBInsert storageQuery Error

Sigoles

Discord: @sigoles
Joined
Nov 20, 2015
Messages
1,200
Solutions
2
Reaction score
149
I'm trying make on query in iologindata.cpp

C++:
DBInsert storageQuery("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (" << player->getGUID() << ", '606163', '0');");

but got an error:
Code:
/home/Otserver/src/iologindata.cpp: In static member function ‘static bool IOLoginData::loadPlayer(Player*, DBResult_ptr)’:
/home/Otserver/src/iologindata.cpp:724:116: error: invalid operands of types ‘const char [68]’ and ‘uint32_t {aka unsigned int}’ to binary ‘operator<<’
     DBInsert storageQuery("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (" << player->getGUID() << ", '606163', '0');");
                                                                                                                    ^
/home/Otserver/src/iologindata.cpp: In static member function ‘static bool IOLoginData::savePlayer(Player*, bool)’:
/home/Otserver/src/iologindata.cpp:1054:115: error: invalid operands of types ‘const char [68]’ and ‘uint32_t {aka unsigned int}’ to binary ‘operator<<’
    DBInsert storageQuery("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (" << player->getGUID() << ", '606163', '1');");
                                                                                                                   ^

                ^
 
I know is not what you asked, but why not setting storage on creaturescripts login?

because I don't have one function in lua, so I need use all in c++ (or make that function in lua) :S

anyone here know fix this error?
 
you're trying to use stringstream operators on a raw char*, which doesn't work (you're technically using binary left shift)
use + instead of << to concatenate the value
+ player->getGUID() +
 
you're trying to use stringstream operators on a raw char*, which doesn't work (you're technically using binary left shift)
use + instead of << to concatenate the value
+ player->getGUID() +
hi, thanks!
C++:
DBInsert storageQuery("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (" + player->getGUID() + ", '606163', '0');");
I was tried it too, look error>

Code:
/home/Otserver/src/iologindata.cpp: In static member function ‘static bool IOLoginData::loadPlayer(Player*, DBResult_ptr)’:
/home/Otserver/src/iologindata.cpp:724:119: error: invalid operands of types ‘const char*’ and ‘const char [18]’ to binary ‘operator+’
     DBInsert storageQuery("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (" + player->getGUID() + ", '606163', '0');");
                                                                                                                       ^
/home/Otserver/src/iologindata.cpp: In static member function ‘static bool IOLoginData::savePlayer(Player*, bool)’:
/home/Otserver/src/iologindata.cpp:1053:118: error: invalid operands of types ‘const char*’ and ‘const char [18]’ to binary ‘operator+’
    DBInsert storageQuery("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (" + player->getGUID() + ", '606163', '1');");
                                                                                                                      ^
 
std::to_string(player->getGUID())

thanks again, the error is gone, but the query does not working (not adding to database), why?

I make prints there and all is ok
C++:
DBInsert storageQuery("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (" + std::to_string(player->getGUID()) + ", '606163', '1');");   
std::cout << "Added to DB" << std::endl;

printing "Added to DB" but not adding
 
Code:
std::ostringstream query;
query << "INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (" << player->getGUID() << ", '606163', '1')";
db->executeQuery(query.str());

if db is not declared add this
Code:
Database* db = Database::getInstance();
above the code
 
Code:
std::ostringstream query;
query << "INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (" << player->getGUID() << ", '606163', '1')";
db->executeQuery(query.str());

if db is not declared add this
Code:
Database* db = Database::getInstance();
above the code

thanks nekiro, but not adding yet :eek:

tested codes:
C++:
std::ostringstream query;
query << "INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (" << player->getGUID() << ", '606163', '1')";
db->executeQuery(query.str());

C++:
query.str(std::string());
query << "INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (" << player->getGUID() << ", '606163', '1')";
db->executeQuery(query.str());

C++:
DBInsert storageQuery("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (" + std::to_string(player->getGUID()) + ", '606163', '1');");
 

Similar threads

Back
Top