简体   繁体   中英

C++ MySQL-connector on Arch-Linux/arm

I have written a program using C++/C, the MySQL C++ connector and ncurses/CDK. It compiles just fine, and runs fine as well on an x86/64 architecture. It crashes, however, when run on a Raspberry Pi B+ (ArchLinux).

I realize this is a pretty hard question to answer, but maybe someone more experienced can help.

Here's the (hopefully) relevant Code:

//Open Connection to the Database
    nrpeout::MYSQL_CON localhost("127.0.0.1", 3306, "root", "toor");

    //localhost.write_attributes_to_console();
    con = localhost.open_database_connection();

    //Create a new object of type nrpeoutputquery
    nrpeout::Nrpeoutputquery current_query("SELECT * FROM nrpeout", con);

    //Execute query
    res = current_query.execute_query();

    //Close Database Connection
    localhost.close_database_connection(con);


    } catch (sql::SQLException &e) {
        //Handle SQL-Exceptions
        std::cout << "# ERR: SQLException in " << __FILE__;
        std::cout << "(" << __FUNCTION__ << ") on line " 
        << __LINE__ << std::endl;
        std::cout << "# ERR: " << e.what();
        std::cout << " (MySQL error code: " << e.getErrorCode();
        std::cout << ", SQLState: " << e.getSQLState() << " )" << std::endl;
    } catch(...) {
        //Handle Standard Exceptions
        std::cout << "Unknown Exception raised. Please contact your Administrator" << std::endl;
    }
nrpeout::NrpeResultSet* currentResults = new nrpeout::NrpeResultSet(res);

Using Valgrind and GDB, I have tried to narrow the error down to the line where I create the object "currentResults".

Here's the member function that saves the query results:

nrpeout::NrpeResultSet::NrpeResultSet(sql::ResultSet* res)
{
        for (unsigned int i = 0; i < res->rowsCount(); ++i) 
        { 
          res->next();
          std::string command = res->getString("command");

          //Shorten the String
          size_t posCommand = command.find("_");
          std::string shortened_command = command.substr(posCommand+1);

          int ret = res->getInt("ret");

          std::string text = res->getString("text");

          //Shorten the Text
          size_t posText = text.find("|");
          std::string shortened_text = text.substr(0, posText-1); 

          std::string last_updated = res->getString("last_updated");

          this->results.push_back(Row(shortened_command, ret, shortened_text, last_updated));
        }

Well, you are not catching an exception, which you may want to handle. InvalidInstanceException is thrown when using closed databse connections, statements or resultsets .

My suggestion is to run your code with a gdb and catch exceptions:

    gdb ./some-program
    $ catch throw
    $ r

This will break after each exception being thrown. (But also includes handled exceptions, so there may be quite a few breaks, depending on how long it takes you to get to the important part.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM