Search code examples
c++mysqlconnector

MySQL C++ Connector UPDATE


I am having trouble with the MySQL C++ Connector... My problem is I have a query : UPDATE characters SET name = 'myNameIs' WHERE characregistra = 'MyguidIs' characters is the table, name a column, characregistra too. I try to put the myNameIs value into name when I found in the column characregistra the value "MyguisIs". It works, but without try{]catch{], it crashes. I tried to get the error with a sql::SQLException, but no way, nothing in printed... Thanks in advance.

EDIT : forgot to put the code :

void renameCharac(std::string guid, std::string pseudo)
{
    try{
        sql::Statement *declaration;
        declaration = connection->createStatement(); // Connection is declared
        declaration->executeQuery("UPDATE characters SET name = '" + pseudo + "' WHERE characregistra = '" + guid + "'");
        delete declaration;
    }
    catch (sql::SQLException e)
    {
        std::cout << e.what();
    }
}

Solution

  • Finaly I did it like that :

    void renameCharac(std::string guid, std::string pseudo)
    {
            sql::Statement *declaration;
            declaration = connection->createStatement();
            declaration->executeUpdate("UPDATE characters SET name = '" + pseudoChoisi + "' WHERE characregistra = '" + guid + "'");
            delete declaration;
    }
    

    It works.